Skip to content

Expose host and target sysroot to build scripts. #13473

Closed as not planned
Closed as not planned
@c272

Description

@c272

Problem

Currently, when using -Zbuild-std, Cargo passes a --sysroot argument down to the relevant rustc invocations. However, the value of this argument is not exposed to build scripts, so any build scripts which rely on any further invocation of rustc 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 the RUSTC_HOST_SYSROOT and RUSTC_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 some CARGO_RUSTFLAGS variable. However, access to a fine-grained sysroot variable is useful for use cases other than simply replicating a rustc 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions