Description
Problem
The value of target_feature = "crt-static"
can be controlled in rustc
with -Ctarget-feature=+crt-static
or -Ctarget-feature=-crt-static
. Some targets have this enabled by default, but that doesn't seem to be propagated to CARGO_CFG_TARGET_FEATURE
.
Steps
Create a build script with the following contents:
fn main() {
println!("cargo::warning={:?}", std::env::var("CARGO_CFG_TARGET_FEATURE"));
}
Since running rustc --target=aarch64-unknown-linux-musl --print=cfg
outputs target_feature="crt-static"
, one would expect it to also be output with cargo check --target=aarch64-unknown-linux-musl
of the above program, but it does not, setting RUSTFLAGS="-Ctarget-features=+crt-static"
is required.
Possible Solution(s)
Maybe this method in rustc
needs to be tweaked?
Or maybe Cargo needs to avoid passing --crate-type proc-macro
to rustc
when determining target info? (somewhere around here)
Notes
This is somewhat affecting cc
, as it is not guaranteed to pass the correct value for the ``/-static
flag to compilers (though it shouldn't matter much since `cc` doesn't link anyhow).
Version
cargo 1.84.0-nightly (cf53cc5 2024-10-18)
release: 1.84.0-nightly
commit-hash: cf53cc5
commit-date: 2024-10-18
host: aarch64-apple-darwin
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.7.1 (sys:0.4.74+curl-8.9.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Mac OS 14.7.0 [64-bit]