File 0001-bootstrap-allow-disabling-target-self-contained.patch of Package rust

From df0d6f1d8b46db82d7599ca8eff6e8f844cf52f2 Mon Sep 17 00:00:00 2001
From: Josh Stone <jistone@redhat.com>
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/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/config.example.toml b/config.example.toml
index e5df28a49af6..2fcd8b8cb057 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -807,6 +807,11 @@ change-id = 116881
 # target triples containing `-none`, `nvptx`, `switch`, or `-uefi`.
 #no-std = <platform-specific> (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 = <platform-specific> (bool)
+
 # =============================================================================
 # Distribution options
 #
diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs
index 7021a9543582..11555c65ca87 100644
--- a/src/bootstrap/src/core/build_steps/compile.rs
+++ b/src/bootstrap/src/core/build_steps/compile.rs
@@ -302,6 +302,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/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs
index 0a9175aa3ea5..a2e028b25036 100644
--- a/src/bootstrap/src/core/config/config.rs
+++ b/src/bootstrap/src/core/config/config.rs
@@ -533,6 +533,7 @@ pub struct Target {
     pub wasi_root: Option<PathBuf>,
     pub qemu_rootfs: Option<PathBuf>,
     pub no_std: bool,
+    pub self_contained: bool,
 }
 
 impl Target {
@@ -541,6 +542,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
     }
 }
@@ -1051,6 +1055,7 @@ struct TomlTarget {
         wasi_root: Option<String> = "wasi-root",
         qemu_rootfs: Option<String> = "qemu-rootfs",
         no_std: Option<bool> = "no-std",
+        self_contained: Option<bool> = "self-contained",
     }
 }
 
@@ -1600,6 +1605,9 @@ fn get_table(option: &str) -> Result<TomlConfig, toml::de::Error> {
                 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 33b8f1a7ce72..f36e53187576 100644
--- a/src/bootstrap/src/lib.rs
+++ b/src/bootstrap/src/lib.rs
@@ -1335,6 +1335,11 @@ fn no_std(&self, target: TargetSelection) -> Option<bool> {
         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<bool> {
+        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

openSUSE Build Service is sponsored by