Introduce crt_static target option in config.toml
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.
This commit is contained in:
parent
0c7a0e9851
commit
4b09dc6e39
5 changed files with 28 additions and 0 deletions
|
@ -292,6 +292,12 @@
|
|||
# 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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -503,6 +503,10 @@ impl<'a> Builder<'a> {
|
|||
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);
|
||||
|
|
|
@ -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 @@ impl 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);
|
||||
|
||||
|
|
|
@ -656,6 +656,12 @@ impl Build {
|
|||
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue