Skip to content

Commit aeafb51

Browse files
committed
Do not build or download libgccjit if using libgccjit-libs-dir
1 parent 4d5755f commit aeafb51

File tree

5 files changed

+49
-25
lines changed

5 files changed

+49
-25
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2857,7 +2857,9 @@ 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-
tarball.add_file(&output.libgccjit, "lib", FileType::NativeLibrary);
2860+
if let Some(ref path) = output.libgccjit {
2861+
tarball.add_file(path, "lib", FileType::NativeLibrary);
2862+
}
28612863
tarball.generate()
28622864
}
28632865

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

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ pub struct Gcc {
2626

2727
#[derive(Clone)]
2828
pub struct GccOutput {
29-
pub libgccjit: PathBuf,
29+
/// 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>,
3034
target: TargetSelection,
3135
}
3236

@@ -37,20 +41,22 @@ impl GccOutput {
3741
return;
3842
}
3943

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

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

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

5561
if let Some(ref path) = builder.config.libgccjit_libs_dir {
5662
let host_target = builder.config.host_target.triple;
@@ -62,13 +68,14 @@ impl GccOutput {
6268
.map(|target| target.triple)
6369
.chain(std::iter::once(host_target));
6470

71+
let target_filename = "libgccjit.so.0";
6572
for target in targets {
66-
let source = source.join(target).join(&target_filename);
73+
let source = source.join(target).join(target_filename);
6774
// To support symlinks in libgccjit-libs-dir, we have to resolve it first,
6875
// otherwise we'd create a symlink to a symlink, which wouldn't work.
6976
let actual_libgccjit_path = t!(
7077
source.canonicalize(),
71-
format!("Cannot find libgccjit at {}", self.libgccjit.display())
78+
format!("Cannot find libgccjit at {}", source.display())
7279
);
7380
let target_dir = dst.join(target);
7481
t!(
@@ -102,7 +109,8 @@ impl Step for Gcc {
102109

103110
// If GCC has already been built, we avoid building it again.
104111
let metadata = match get_gcc_build_status(builder, target) {
105-
GccBuildStatus::AlreadyBuilt(path) => return GccOutput { libgccjit: path, target },
112+
GccBuildStatus::AlreadyBuilt(path) => return GccOutput { libgccjit: Some(path), target },
113+
GccBuildStatus::InLibsDir => return GccOutput { libgccjit: None },
106114
GccBuildStatus::ShouldBuild(m) => m,
107115
};
108116

@@ -112,14 +120,14 @@ impl Step for Gcc {
112120

113121
let libgccjit_path = libgccjit_built_path(&metadata.install_dir);
114122
if builder.config.dry_run() {
115-
return GccOutput { libgccjit: libgccjit_path, target };
123+
return GccOutput { libgccjit: Some(libgccjit_path), target };
116124
}
117125

118126
build_gcc(&metadata, builder, target);
119127

120128
t!(metadata.stamp.write());
121129

122-
GccOutput { libgccjit: libgccjit_path, target }
130+
GccOutput { libgccjit: Some(libgccjit_path), target }
123131
}
124132
}
125133

@@ -133,6 +141,7 @@ pub struct Meta {
133141
pub enum GccBuildStatus {
134142
/// libgccjit is already built at this path
135143
AlreadyBuilt(PathBuf),
144+
InLibsDir,
136145
ShouldBuild(Meta),
137146
}
138147

@@ -197,6 +206,11 @@ fn try_download_gcc(_builder: &Builder<'_>, _target: TargetSelection) -> Option<
197206
/// It's used to avoid busting caches during x.py check -- if we've already built
198207
/// GCC, it's fine for us to not try to avoid doing so.
199208
pub fn get_gcc_build_status(builder: &Builder<'_>, target: TargetSelection) -> GccBuildStatus {
209+
if matches!(builder.config.gcc_ci_mode, crate::core::config::GccCiMode::CopyFromLibsDir) {
210+
// TODO: check if this is OK.
211+
return GccBuildStatus::InLibsDir;
212+
}
213+
200214
if let Some(path) = try_download_gcc(builder, target) {
201215
return GccBuildStatus::AlreadyBuilt(path);
202216
}
@@ -320,7 +334,9 @@ fn build_gcc(metadata: &Meta, builder: &Builder<'_>, target: TargetSelection) {
320334
/// Configures a Cargo invocation so that it can build the GCC codegen backend.
321335
pub fn add_cg_gcc_cargo_flags(cargo: &mut Cargo, gcc: &GccOutput) {
322336
// Add the path to libgccjit.so to the linker search paths.
323-
cargo.rustflag(&format!("-L{}", gcc.libgccjit.parent().unwrap().to_str().unwrap()));
337+
if let Some(ref path) = gcc.libgccjit {
338+
cargo.rustflag(&format!("-L{}", path.parent().unwrap().to_str().unwrap()));
339+
}
324340
}
325341

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

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3959,13 +3959,17 @@ impl Step for CodegenGCC {
39593959
.arg("test")
39603960
.arg("--use-backend")
39613961
.arg("gcc")
3962-
.arg("--gcc-path")
3963-
.arg(gcc.libgccjit.parent().unwrap())
39643962
.arg("--out-dir")
39653963
.arg(builder.stage_out(compilers.build_compiler(), Mode::Codegen).join("cg_gcc"))
39663964
.arg("--release")
39673965
.arg("--mini-tests")
39683966
.arg("--std-tests");
3967+
3968+
if let Some(ref path) = gcc.libgccjit {
3969+
cargo
3970+
.arg("--gcc-path")
3971+
.arg(path.parent().unwrap());
3972+
}
39693973
cargo.args(builder.config.test_args());
39703974

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

src/bootstrap/src/core/config/config.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,12 +1219,13 @@ impl Config {
12191219
Warnings::Default => rust_deny_warnings.unwrap_or(true),
12201220
};
12211221

1222-
let gcc_ci_mode = match gcc_download_ci_gcc {
1223-
Some(value) => match value {
1222+
let gcc_ci_mode = match (&libgccjit_libs_dir, gcc_download_ci_gcc) {
1223+
(Some(_), _) => GccCiMode::CopyFromLibsDir,
1224+
(None, Some(value)) => match value {
12241225
true => GccCiMode::DownloadFromCi,
12251226
false => GccCiMode::BuildLocally,
12261227
},
1227-
None => GccCiMode::default(),
1228+
(None, None) => GccCiMode::default(),
12281229
};
12291230

12301231
let targets = flags_target

src/bootstrap/src/core/config/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ pub enum GccCiMode {
433433
/// If it is not available on CI, it will be built locally instead.
434434
#[default]
435435
DownloadFromCi,
436+
CopyFromLibsDir,
436437
}
437438

438439
pub fn threads_from_config(v: u32) -> u32 {

0 commit comments

Comments
 (0)