Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CARGO_CFG_TARGET_FEATURE does not include default value of crt-static #14778

Open
madsmtm opened this issue Nov 4, 2024 · 1 comment
Open
Labels
A-build-scripts Area: build.rs scripts C-bug Category: bug S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@madsmtm
Copy link
Contributor

madsmtm commented Nov 4, 2024

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]

@madsmtm madsmtm added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Nov 4, 2024
@ehuss
Copy link
Contributor

ehuss commented Nov 4, 2024

Hm. We really need a better way to query rustc for information1. In this particular case, I would lean towards finding a new way to get information from rustc about the supported crate types and the output file prefix/suffix without using --crate-type.

Footnotes

  1. I would like to be able to run a single rustc invocation that will spit out a single JSON blob with all the information we need, instead of the text-based parsing system we have now.

@ehuss ehuss added S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. A-build-scripts Area: build.rs scripts and removed S-triage Status: This issue is waiting on initial triage. labels Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-scripts Area: build.rs scripts C-bug Category: bug S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

2 participants