From e8833a9032b9f5773ef891b3f12b93322d6b4950 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/config.rs | 8 ++++++++ src/bootstrap/src/lib.rs | 5 +++++ 4 files changed, 22 insertions(+) diff --git a/bootstrap.example.toml b/bootstrap.example.toml index 2a98821f225..580d6b2a8a2 100644 --- a/bootstrap.example.toml +++ b/bootstrap.example.toml @@ -948,6 +948,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 18b5d4426b1..3de9667123b 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 bbb0fbfbb93..8642a86cbf8 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -666,6 +666,7 @@ pub struct Target { pub codegen_backends: Option>, pub optimized_compiler_builtins: Option, pub jemalloc: Option, + pub self_contained: bool, } impl Target { @@ -677,6 +678,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 } } @@ -1292,6 +1296,7 @@ struct TomlTarget { runner: Option = "runner", optimized_compiler_builtins: Option = "optimized-compiler-builtins", jemalloc: Option = "jemalloc", + self_contained: Option = "self-contained", } } @@ -2245,6 +2250,9 @@ fn get_table(option: &str) -> Result { 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/lib.rs b/src/bootstrap/src/lib.rs index 843d474f92d..3a4398ee1f8 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -1434,6 +1434,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.48.1