Expose host and target sysroot to build scripts. #13473
Labels
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
S-triage
Status: This issue is waiting on initial triage.
Problem
Currently, when using
-Zbuild-std
, Cargo passes a--sysroot
argument down to the relevantrustc
invocations. However, the value of this argument is not exposed to build scripts, so any build scripts which rely on any further invocation ofrustc
that matches the current build configuration (such as autocfg) must somehow discover the sysroot themselves.Build scripts may also wish to build tools which depend on knowledge of the contents of the host or target sysroot, such as for building an external dependency which links into existing std artifacts.
Proposed Solution
Expose the relevant host and target sysroot passed to
rustc
by Cargo to build scripts, in the form of theRUSTC_HOST_SYSROOT
andRUSTC_TARGET_SYSROOT
environment variables. These variables would contain the absolute path of the sysroot on disk.This would support all the above-mentioned use cases, but will not create a mechanism to determine whether
-Zbuild-std
is enabled from a build script perspective. The script may not be able to determine whether--sysroot
was passed originally, however unconditionally passing a--sysroot
argument should not cause adverse behaviour.One possible solution to that issue as mentioned in #7501 is to simply expose all flags passed from Cargo to
rustc
in someCARGO_RUSTFLAGS
variable. However, access to a fine-grained sysroot variable is useful for use cases other than simply replicating arustc
setup, so that could possibly be an additional solution to this request.Notes
Related to #7501
Related to rust-lang/wg-cargo-std-aware#50
Related to #13443
The text was updated successfully, but these errors were encountered: