From 6af71d8ff0932bc14102cd9cbfbca16354c5cd2a Mon Sep 17 00:00:00 2001 From: Jesus Checa Hidalgo Date: Mon, 7 Apr 2025 16:59:10 +0200 Subject: [PATCH 1/2] bootstrap: allow disabling target self-contained --- bootstrap.example.toml | 5 +++++ src/bootstrap/src/core/build_steps/compile.rs | 4 ++++ src/bootstrap/src/core/config/toml/target.rs | 8 ++++++++ src/bootstrap/src/lib.rs | 5 +++++ 4 files changed, 22 insertions(+) diff --git a/bootstrap.example.toml b/bootstrap.example.toml index 19cf360b0fb..916bae8dc7d 100644 --- a/bootstrap.example.toml +++ b/bootstrap.example.toml @@ -974,6 +974,11 @@ # This overrides the global `rust.jemalloc` option. See that option for more info. #jemalloc = rust.jemalloc (bool) +# Copy libc and CRT objects into the target lib/self-contained/ directory. +# Enabled by default on `musl`, `wasi`, and `windows-gnu` targets. Other +# targets may ignore this setting if they have nothing to be contained. +#self-contained = (bool) + # ============================================================================= # Distribution options # diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index f6efb23e8d8..4d0ae54e1ef 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -374,6 +374,10 @@ fn copy_self_contained_objects( compiler: &Compiler, target: TargetSelection, ) -> Vec<(PathBuf, DependencyType)> { + if builder.self_contained(target) != Some(true) { + return vec![]; + } + let libdir_self_contained = builder.sysroot_target_libdir(*compiler, target).join("self-contained"); t!(fs::create_dir_all(&libdir_self_contained)); diff --git a/src/bootstrap/src/core/config/toml/target.rs b/src/bootstrap/src/core/config/toml/target.rs index b9f6780ca3f..41a4a815d31 100644 --- a/src/bootstrap/src/core/config/toml/target.rs +++ b/src/bootstrap/src/core/config/toml/target.rs @@ -47,6 +47,7 @@ struct TomlTarget { runner: Option = "runner", optimized_compiler_builtins: Option = "optimized-compiler-builtins", jemalloc: Option = "jemalloc", + self_contained: Option = "self-contained", } } @@ -79,6 +80,7 @@ pub struct Target { pub codegen_backends: Option>, pub optimized_compiler_builtins: Option, pub jemalloc: Option, + pub self_contained: bool, } impl Target { @@ -90,6 +92,9 @@ pub fn from_triple(triple: &str) -> Self { if triple.contains("emscripten") { target.runner = Some("node".into()); } + if triple.contains("-musl") || triple.contains("-wasi") || triple.contains("-windows-gnu") { + target.self_contained = true; + } target } } @@ -126,6 +131,9 @@ pub fn apply_target_config(&mut self, toml_target: Option Option { self.config.target_config.get(&target).map(|t| t.no_std) } + /// Returns `true` if this is a self-contained `target`, if defined + fn self_contained(&self, target: TargetSelection) -> Option { + self.config.target_config.get(&target).map(|t| t.self_contained) + } + /// Returns `true` if the target will be tested using the `remote-test-client` /// and `remote-test-server` binaries. fn remote_tested(&self, target: TargetSelection) -> bool { -- 2.49.0