Skip to content

Commit 84a1158

Browse files
Kobzolantoyo
authored andcommitted
Do not use GccCiMode for the libs directory
This will allow users to provide pre-built cross-compiled dylibs, while still downloading common (e.g. x64) dylibs from the CI.
1 parent 87b71ce commit 84a1158

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

bootstrap.example.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,30 @@
190190
# modifications to the `src/gcc` submodule.
191191
# Currently, this is only supported for the `x86_64-unknown-linux-gnu` target.
192192
#gcc.download-ci-gcc = false
193+
194+
# Provide a directory of prebuilt libgccjit.so dylibs for given (host, target) compilation pairs.
195+
# This is useful when you want to cross-compile `rustc` to another target since GCC is not a
196+
# multi-target compiler.
197+
# You have to use a directory structure that looks like this:
198+
# `<libgccjit-libs-dir>/<host>/<target>/libgccjit.so`.
199+
# For example:
200+
#
201+
# ```
202+
# <libgccjit-libs-dir>
203+
# ├── m68k-unknown-linux-gnu
204+
# │ └── m68k-unknown-linux-gnu
205+
# │ └── libgccjit.so
206+
# └── x86_64-unknown-linux-gnu
207+
# ├── m68k-unknown-linux-gnu
208+
# │ └── libgccjit.so
209+
# └── x86_64-unknown-linux-gnu
210+
# └── libgccjit.so
211+
# ```
212+
# The directory above would allow you to cross-compile rustc from x64 to m68k
213+
#
214+
# Note that this option has priority over `gcc.download-ci-gcc`.
215+
# If you set both, bootstrap will first try to load libgccjit.so from this directory.
216+
# Only if it isn't found, it will try to download it from CI or build it locally.
193217
#gcc.libgccjit-libs-dir = "/path/to/libgccjit-libs-dir"
194218

195219
# =============================================================================

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,25 +201,28 @@ fn try_download_gcc(_builder: &Builder<'_>, _target: TargetSelection) -> Option<
201201
/// It's used to avoid busting caches during x.py check -- if we've already built
202202
/// GCC, it's fine for us to not try to avoid doing so.
203203
pub fn get_gcc_build_status(builder: &Builder<'_>, target: TargetSelection) -> GccBuildStatus {
204-
if matches!(builder.config.gcc_ci_mode, crate::core::config::GccCiMode::CopyFromLibsDir) {
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");
204+
// Prefer taking externally provided prebuilt libgccjit dylib
205+
if let Some(dir) = &builder.config.libgccjit_libs_dir {
206+
// The dir structure should be <root>/<host>/<target>/libgccjit.so
207+
let host_dir = dir.join(builder.build.host_target);
208+
let path = host_dir.join(target).join("libgccjit.so");
212209
if path.exists() {
213210
return GccBuildStatus::AlreadyBuilt(path);
214211
} else {
215-
builder.info(&format!("libgccjit.so not found at `{}`", path.display()));
212+
builder.info(&format!(
213+
"libgccjit.so for host `{}` and target `{target}` was not found at `{}`",
214+
builder.build.host_target,
215+
path.display()
216+
));
216217
}
217218
}
218219

220+
// If not available, try to download from CI
219221
if let Some(path) = try_download_gcc(builder, target) {
220222
return GccBuildStatus::AlreadyBuilt(path);
221223
}
222224

225+
// If not available, try to build (or use already built libgccjit from disk)
223226
static STAMP_HASH_MEMO: OnceLock<String> = OnceLock::new();
224227
let smart_stamp_hash = STAMP_HASH_MEMO.get_or_init(|| {
225228
generate_smart_stamp_hash(

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,10 @@ impl Config {
621621
vendor: dist_vendor,
622622
} = toml.dist.unwrap_or_default();
623623

624-
let Gcc { download_ci_gcc: gcc_download_ci_gcc, libgccjit_libs_dir } =
625-
toml.gcc.unwrap_or_default();
624+
let Gcc {
625+
download_ci_gcc: gcc_download_ci_gcc,
626+
libgccjit_libs_dir: gcc_libgccjit_libs_dir,
627+
} = toml.gcc.unwrap_or_default();
626628

627629
if rust_bootstrap_override_lld.is_some() && rust_bootstrap_override_lld_legacy.is_some() {
628630
panic!(
@@ -1220,13 +1222,12 @@ impl Config {
12201222
Warnings::Default => rust_deny_warnings.unwrap_or(true),
12211223
};
12221224

1223-
let gcc_ci_mode = match (&libgccjit_libs_dir, gcc_download_ci_gcc) {
1224-
(Some(_), _) => GccCiMode::CopyFromLibsDir,
1225-
(None, Some(value)) => match value {
1225+
let gcc_ci_mode = match gcc_download_ci_gcc {
1226+
Some(value) => match value {
12261227
true => GccCiMode::DownloadFromCi,
12271228
false => GccCiMode::BuildLocally,
12281229
},
1229-
(None, None) => GccCiMode::default(),
1230+
None => GccCiMode::default(),
12301231
};
12311232

12321233
let targets = flags_target
@@ -1349,7 +1350,7 @@ impl Config {
13491350
keep_stage: flags_keep_stage,
13501351
keep_stage_std: flags_keep_stage_std,
13511352
libdir: install_libdir.map(PathBuf::from),
1352-
libgccjit_libs_dir,
1353+
libgccjit_libs_dir: gcc_libgccjit_libs_dir,
13531354
library_docs_private_items: build_library_docs_private_items.unwrap_or(false),
13541355
lld_enabled,
13551356
lldb: build_lldb.map(PathBuf::from),

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

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

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

0 commit comments

Comments
 (0)