Skip to content

Commit 3541668

Browse files
committed
Address review
1 parent 572563d commit 3541668

File tree

3 files changed

+31
-32
lines changed

3 files changed

+31
-32
lines changed

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,9 +2857,7 @@ impl Step for Gcc {
28572857
fn run(self, builder: &Builder<'_>) -> Self::Output {
28582858
let tarball = Tarball::new(builder, "gcc", &self.target.triple);
28592859
let output = builder.ensure(super::gcc::Gcc { target: self.target });
2860-
if let Some(ref path) = output.libgccjit {
2861-
tarball.add_file(path, "lib", FileType::NativeLibrary);
2862-
}
2860+
tarball.add_file(&output.libgccjit, "lib", FileType::NativeLibrary);
28632861
tarball.generate()
28642862
}
28652863

src/bootstrap/src/core/build_steps/gcc.rs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ pub struct Gcc {
2727
#[derive(Clone)]
2828
pub struct GccOutput {
2929
/// Path to a built or downloaded libgccjit.
30-
/// Is None when setting libgccjit-libs-dir.
31-
/// FIXME: it seems wrong to make this an Option.
32-
/// Perhaps it should be a Vec so that we can install all libs from libgccjit-libs-dir?
33-
pub libgccjit: Option<PathBuf>,
30+
pub libgccjit: PathBuf,
3431
target: TargetSelection,
3532
}
3633

@@ -41,20 +38,20 @@ impl GccOutput {
4138
return;
4239
}
4340

44-
if let Some(ref path) = self.libgccjit {
45-
let target_filename = path.file_name().unwrap().to_str().unwrap().to_string();
41+
let target_filename = self.libgccjit.file_name().unwrap().to_str().unwrap().to_string();
4642

47-
// If we build libgccjit ourselves, then `self.libgccjit` can actually be a symlink.
48-
// In that case, we have to resolve it first, otherwise we'd create a symlink to a symlink,
49-
// which wouldn't work.
50-
let actual_libgccjit_path =
51-
t!(path.canonicalize(), format!("Cannot find libgccjit at {}", path.display()));
43+
// If we build libgccjit ourselves, then `self.libgccjit` can actually be a symlink.
44+
// In that case, we have to resolve it first, otherwise we'd create a symlink to a symlink,
45+
// which wouldn't work.
46+
let actual_libgccjit_path = t!(
47+
self.libgccjit.canonicalize(),
48+
format!("Cannot find libgccjit at {}", self.libgccjit.display())
49+
);
5250

53-
let dest_dir = directory.join("rustlib").join(self.target).join("lib");
54-
t!(fs::create_dir_all(&dest_dir));
55-
let dst = dest_dir.join(target_filename);
56-
builder.copy_link(&actual_libgccjit_path, &dst, FileType::NativeLibrary);
57-
}
51+
let dest_dir = directory.join("rustlib").join(self.target).join("lib");
52+
t!(fs::create_dir_all(&dest_dir));
53+
let dst = dest_dir.join(target_filename);
54+
builder.copy_link(&actual_libgccjit_path, &dst, FileType::NativeLibrary);
5855

5956
if let Some(ref path) = builder.config.libgccjit_libs_dir {
6057
let host_target = builder.config.host_target.triple;
@@ -109,8 +106,7 @@ impl Step for Gcc {
109106

110107
// If GCC has already been built, we avoid building it again.
111108
let metadata = match get_gcc_build_status(builder, target) {
112-
GccBuildStatus::AlreadyBuilt(path) => return GccOutput { libgccjit: Some(path), target },
113-
GccBuildStatus::InLibsDir => return GccOutput { libgccjit: None, target },
109+
GccBuildStatus::AlreadyBuilt(path) => return GccOutput { libgccjit: path, target },
114110
GccBuildStatus::ShouldBuild(m) => m,
115111
};
116112

@@ -120,14 +116,14 @@ impl Step for Gcc {
120116

121117
let libgccjit_path = libgccjit_built_path(&metadata.install_dir);
122118
if builder.config.dry_run() {
123-
return GccOutput { libgccjit: Some(libgccjit_path), target };
119+
return GccOutput { libgccjit: libgccjit_path, target };
124120
}
125121

126122
build_gcc(&metadata, builder, target);
127123

128124
t!(metadata.stamp.write());
129125

130-
GccOutput { libgccjit: Some(libgccjit_path), target }
126+
GccOutput { libgccjit: libgccjit_path, target }
131127
}
132128
}
133129

@@ -141,7 +137,6 @@ pub struct Meta {
141137
pub enum GccBuildStatus {
142138
/// libgccjit is already built at this path
143139
AlreadyBuilt(PathBuf),
144-
InLibsDir,
145140
ShouldBuild(Meta),
146141
}
147142

@@ -207,8 +202,18 @@ fn try_download_gcc(_builder: &Builder<'_>, _target: TargetSelection) -> Option<
207202
/// GCC, it's fine for us to not try to avoid doing so.
208203
pub fn get_gcc_build_status(builder: &Builder<'_>, target: TargetSelection) -> GccBuildStatus {
209204
if matches!(builder.config.gcc_ci_mode, crate::core::config::GccCiMode::CopyFromLibsDir) {
210-
// FIXME: check if this is OK.
211-
return GccBuildStatus::InLibsDir;
205+
let directory = builder
206+
.config
207+
.libgccjit_libs_dir
208+
.as_ref()
209+
.expect("libgccjit_libs_dir should be set when the mode is CopyFromLibsDir")
210+
.join(builder.build.host_target);
211+
let path = directory.join(target).join("libgccjit.so");
212+
if path.exists() {
213+
return GccBuildStatus::AlreadyBuilt(path);
214+
} else {
215+
builder.info(&format!("libgccjit.so not found at `{}`", path.display()));
216+
}
212217
}
213218

214219
if let Some(path) = try_download_gcc(builder, target) {
@@ -334,9 +339,7 @@ fn build_gcc(metadata: &Meta, builder: &Builder<'_>, target: TargetSelection) {
334339
/// Configures a Cargo invocation so that it can build the GCC codegen backend.
335340
pub fn add_cg_gcc_cargo_flags(cargo: &mut Cargo, gcc: &GccOutput) {
336341
// Add the path to libgccjit.so to the linker search paths.
337-
if let Some(ref path) = gcc.libgccjit {
338-
cargo.rustflag(&format!("-L{}", path.parent().unwrap().to_str().unwrap()));
339-
}
342+
cargo.rustflag(&format!("-L{}", gcc.libgccjit.parent().unwrap().to_str().unwrap()));
340343
}
341344

342345
/// The absolute path to the downloaded GCC artifacts.

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3965,9 +3965,7 @@ impl Step for CodegenGCC {
39653965
.arg("--mini-tests")
39663966
.arg("--std-tests");
39673967

3968-
if let Some(ref path) = gcc.libgccjit {
3969-
cargo.arg("--gcc-path").arg(path.parent().unwrap());
3970-
}
3968+
cargo.arg("--gcc-path").arg(gcc.libgccjit.parent().unwrap());
39713969
cargo.args(builder.config.test_args());
39723970

39733971
cargo.into_cmd().run(builder);

0 commit comments

Comments
 (0)