]> git.lizzy.rs Git - rust.git/commitdiff
Introduce crt_static target option in config.toml
authorSamuel Holland <samuel@sholland.org>
Tue, 22 Aug 2017 21:24:29 +0000 (16:24 -0500)
committerSamuel Holland <samuel@sholland.org>
Tue, 22 Aug 2017 21:24:29 +0000 (16:24 -0500)
This controls the value of the crt-static feature used when building the
standard library for a target, as well as the compiler itself when that
target is the host.

config.toml.example
src/bootstrap/bin/rustc.rs
src/bootstrap/builder.rs
src/bootstrap/config.rs
src/bootstrap/lib.rs

index 962be2e608501659cfafe2e0a7d559e1a0c1263a..fd1f03b9d0e24bb17d73e2bec658316c5c786e1f 100644 (file)
 # build native code.
 #android-ndk = "/path/to/ndk"
 
+# Force static or dynamic linkage of the standard library for this target. If
+# this target is a host for rustc, this will also affect the linkage of the
+# compiler itself. This is useful for building rustc on targets that normally
+# only use static libraries. If unset, the target's default linkage is used.
+#crt-static = false
+
 # The root location of the MUSL installation directory. The library directory
 # will also need to contain libunwind.a for an unwinding implementation. Note
 # that this option only makes sense for MUSL targets that produce statically
index f6ed4ee91b3c5b66b2ead3cbbdfa5e406f705179..d098806a8a002de9dd39f9a0921a0fa466eca382 100644 (file)
@@ -242,6 +242,15 @@ fn main() {
             cmd.arg("-C").arg("target-feature=+crt-static");
         }
 
+        if let Ok(s) = env::var("RUSTC_CRT_STATIC") {
+            if s == "true" {
+                cmd.arg("-C").arg("target-feature=+crt-static");
+            }
+            if s == "false" {
+                cmd.arg("-C").arg("target-feature=-crt-static");
+            }
+        }
+
         // Force all crates compiled by this compiler to (a) be unstable and (b)
         // allow the `rustc_private` feature to link to other unstable crates
         // also in the sysroot.
index e325fc65f051d3f1e22e768ea035ab0281f4340a..298f6a004a20aefd1c6da6c892bf62b6c9450bd1 100644 (file)
@@ -503,6 +503,10 @@ pub fn cargo(&self,
             cargo.env("RUSTC_METADATA_SUFFIX", "rustc");
         }
 
+        if let Some(x) = self.crt_static(target) {
+            cargo.env("RUSTC_CRT_STATIC", x.to_string());
+        }
+
         // Enable usage of unstable features
         cargo.env("RUSTC_BOOTSTRAP", "1");
         self.add_rust_test_threads(&mut cargo);
index aa688fc66e267831e71a7a3824720cdc8aa6ea8f..f43035fbfe8a1a75b342fee167b2ef449e42441f 100644 (file)
@@ -143,6 +143,7 @@ pub struct Target {
     pub cc: Option<PathBuf>,
     pub cxx: Option<PathBuf>,
     pub ndk: Option<PathBuf>,
+    pub crt_static: Option<bool>,
     pub musl_root: Option<PathBuf>,
     pub qemu_rootfs: Option<PathBuf>,
 }
@@ -275,6 +276,7 @@ struct TomlTarget {
     cc: Option<String>,
     cxx: Option<String>,
     android_ndk: Option<String>,
+    crt_static: Option<bool>,
     musl_root: Option<String>,
     qemu_rootfs: Option<String>,
 }
@@ -446,6 +448,7 @@ pub fn parse(args: &[String]) -> Config {
                 }
                 target.cxx = cfg.cxx.clone().map(PathBuf::from);
                 target.cc = cfg.cc.clone().map(PathBuf::from);
+                target.crt_static = cfg.crt_static.clone();
                 target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
                 target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);
 
index b6e009815763362db829da3b306803dd2cea3a96..d6afc562f3dc894a27b66547f1da06e6c8b5545d 100644 (file)
@@ -656,6 +656,12 @@ fn rustc_flags(&self, target: Interned<String>) -> Vec<String> {
         base
     }
 
+    /// Returns if this target should statically link the C runtime, if specified
+    fn crt_static(&self, target: Interned<String>) -> Option<bool> {
+        self.config.target_config.get(&target)
+            .and_then(|t| t.crt_static)
+    }
+
     /// Returns the "musl root" for this `target`, if defined
     fn musl_root(&self, target: Interned<String>) -> Option<&Path> {
         self.config.target_config.get(&target)