Repository navigation
Build scripts are not informed of rustflags or rustc wrapper #9600
Description
Activity
- addedC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
on Jun 18, 2021 - added a commit that references this issue
on Jun 18, 2021 Describe the solution you'd like
The rust compiler is given to the build script in the form of the
RUSTCenvironment variable, but that alone is not sufficient for a build script that wants to inspect (or use) the target Rust compilation context. The rustc configuration (the wrapper and RUSTFLAGS) should be passed to the build script as well, likely through two new environment variables:CARGO_RUSTC_WRAPPERCARGO_RUSTFLAGS
So those would be the target-specific flags, right? (i.e. matching the
TARGETthat cargo also sets for the build script.)This would be a real boon to
autocfg! (cc cuviper/autocfg#15 cuviper/autocfg#34)Yes, my thinking was that they'd be set based on how Cargo decides to build the build script itself. See also the implementation of this in #9601, which is really quite simple.
Yes, my thinking was that they'd be set based on how Cargo decides to build the build script itself.
I don't think that's quite the same thing, since the build script runs on the host. But AFAICT the call you added does use the current
bcx.target_data, the same thatTARGETis set from, so it should be what I want.Reacted by Jon Gjengset- added a commit that references this issue
on Jun 18, 2021 - added a commit that references this issue
on Jul 20, 2021
Describe the problem you are trying to solve
I recently came across a bug in anyhow whose root cause is that it does "test compile" to see whether it can make use of some nightly features, but that test compile does not take into account Cargo configuration like
[build] rustflags =. Looking through the environment variables Cargo sets for build scripts it doesn't appear that things like the rustc wrapper or the final rustflags is actually passed to the build script. Specifically, this can be seen by runningThen, observe that "wrap", which appears in both
build.rustflagsandbuild.rustc-wrapper, does not appear in the build output:$ grep wrap build-output.log $Describe the solution you'd like
The rust compiler is given to the build script in the form of the
RUSTCenvironment variable, but that alone is not sufficient for a build script that wants to inspect (or use) the target Rust compilation context. The rustc configuration (the wrapper and RUSTFLAGS) should be passed to the build script as well, likely through two new environment variables:CARGO_RUSTC_WRAPPERCARGO_RUSTFLAGSNote that these do not include
_BUILDto avoid overlap with the environment variables Cargo reads.