From 3a89cbb0ff0352fc6ab4bf329124f961fddb1e2a Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 18 Aug 2025 17:11:07 -0700 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/config.rs | 3 +++ src/bootstrap/src/core/config/toml/target.rs | 5 +++++ src/bootstrap/src/lib.rs | 5 +++++ 5 files changed, 22 insertions(+) diff --git a/bootstrap.example.toml b/bootstrap.example.toml index eac939577979..db72e0fd29c5 100644 --- a/bootstrap.example.toml +++ b/bootstrap.example.toml @@ -1060,3 +1060,8 @@ # Link the compiler and LLVM against `jemalloc` instead of the default libc allocator. # 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) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 1458b0beefa8..08757f3283cf 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -370,6 +370,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/config.rs b/src/bootstrap/src/core/config/config.rs index 678a9b639522..9e45efc72d1a 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -819,6 +819,9 @@ pub(crate) fn parse_inner( if let Some(s) = cfg.no_std { target.no_std = s; } + if let Some(s) = cfg.self_contained { + target.self_contained = s; + } target.cc = cfg.cc.map(PathBuf::from); target.cxx = cfg.cxx.map(PathBuf::from); target.ar = cfg.ar.map(PathBuf::from); diff --git a/src/bootstrap/src/core/config/toml/target.rs b/src/bootstrap/src/core/config/toml/target.rs index 020602e6a199..a944e1d194dd 100644 --- a/src/bootstrap/src/core/config/toml/target.rs +++ b/src/bootstrap/src/core/config/toml/target.rs @@ -43,6 +43,7 @@ struct TomlTarget { runner: Option = "runner", optimized_compiler_builtins: Option = "optimized-compiler-builtins", jemalloc: Option = "jemalloc", + self_contained: Option = "self-contained", } } @@ -75,6 +76,7 @@ pub struct Target { pub codegen_backends: Option>, pub optimized_compiler_builtins: Option, pub jemalloc: Option, + pub self_contained: bool, } impl Target { @@ -86,6 +88,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 } } diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index a2aeed20948e..e530e1ceb99e 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -1453,6 +1453,11 @@ fn no_std(&self, target: TargetSelection) -> 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.51.0