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

Expose host and target sysroot to build scripts. #13473

Open
c272 opened this issue Feb 21, 2024 · 2 comments
Open

Expose host and target sysroot to build scripts. #13473

c272 opened this issue Feb 21, 2024 · 2 comments
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.

Comments

@c272
Copy link

c272 commented Feb 21, 2024

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

@c272 c272 added 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. labels Feb 21, 2024
@Eh2406
Copy link
Contributor

Eh2406 commented Feb 21, 2024

I worry that the proposed solution leads to a proliferation of environment variables that every build script needs to know to look for and pass along. Can we just have one environment variable for "the arguments we want to pass to rustc", actually don't we already have that environment variable?

@c272
Copy link
Author

c272 commented Feb 26, 2024

If you're referring to CARGO_ENCODED_RUSTFLAGS, that doesn't really seem to contain everything that is passed to rustc by Cargo, but simply any RUSTFLAGS added manually (you can test this in any project by adding the print-cargo-encoded-rustflags crate, or just adding a snippet to build.rs).

However, the solution you mentioned I do agree with, it's what was mentioned in #7501, and in the last paragraph there. Exposing specifically the sysroot separately in addition to that could be useful for some use cases, but I am entirely unopposed to going that route instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

2 participants