From 4acc7d53182cf83f2c776c4005fc12756ecdfe8f Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 28 Sep 2023 18:14:28 -0700 Subject: [PATCH 1/2] bootstrap: allow disabling target self-contained --- config.example.toml | 5 +++++ src/bootstrap/compile.rs | 4 ++++ src/bootstrap/config.rs | 8 ++++++++ src/bootstrap/lib.rs | 5 +++++ 4 files changed, 22 insertions(+) diff --git a/config.example.toml b/config.example.toml index f3c2366d674e..c6c5e24fb592 100644 --- a/config.example.toml +++ b/config.example.toml @@ -798,6 +798,11 @@ changelog-seen = 2 # target triples containing `-none`, `nvptx`, `switch`, or `-uefi`. #no-std = (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/compile.rs b/src/bootstrap/compile.rs index 292ccc5780fa..d4d79ce982af 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -251,6 +251,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_libdir(*compiler, target).join("self-contained"); t!(fs::create_dir_all(&libdir_self_contained)); let mut target_deps = vec![]; diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 836328f94ef8..4ae3d853ed88 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -527,6 +527,7 @@ pub struct Target { pub wasi_root: Option, pub qemu_rootfs: Option, pub no_std: bool, + pub self_contained: bool, } impl Target { @@ -535,6 +536,9 @@ pub fn from_triple(triple: &str) -> Self { if triple.contains("-none") || triple.contains("nvptx") || triple.contains("switch") { target.no_std = true; } + if triple.contains("-musl") || triple.contains("-wasi") || triple.contains("-windows-gnu") { + target.self_contained = true; + } target } } @@ -1033,6 +1037,7 @@ struct TomlTarget { wasi_root: Option = "wasi-root", qemu_rootfs: Option = "qemu-rootfs", no_std: Option = "no-std", + self_contained: Option = "self-contained", } } @@ -1587,6 +1592,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).or_else(|| { target.ndk.as_ref().map(|ndk| ndk_compiler(Language::C, &triple, ndk)) }); diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 8b8d4b237953..c3e7a1ccc00f 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -1320,6 +1320,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.41.0