allow build-std
to be configured per-target in .cargo/config.toml
#15670
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR try to resolve?
-Zbuild-std
has some issues with per-pkg-target and bindeps, as seen with #10444 and #9451.At the same time, since these features essentially enable builds where crates with different targets can co-exist, some people may want to use build-std for one target (in my own project:
amdgcn-amd-amdhsa
, for OS dev people:x86_64-unknown-none
) but not for another target where std is already shipped: #8733This PR overhauls the way build-std interacts with targets and we're able to fix the issues described above by introducing an additional per-target config in
.cargo/config.toml
forbuild-std
. Note that these configs co-exist with the global-Zbuild-std
flag, and has different behavior whether or not the two are used together: if the global flag is enabled, then all targets will attempt to build their std crates, with per-target config as an override. If the global flag is not used, then only targets that are configured via per-target config will try to build std crates.This supercedes my two previous attempts at resolving the same issue: #10330 and #11969
How to test and review this PR?
Use
.cargo/config.toml
:I've already included some essential tests in
tests/testsuite/standard_lib.rs
such as intersection with per-pkg-target and bindeps. Feel free to suggest additional test cases.I haven't run the cross compile test locally as I don't know how to get an environment for it on NixOS, will (ab)use the CI for this I guess.
Some unresolved questions:
[target.TARGET.unstable]
instead?-Zbuild-std
way of usage?target.TARGET.build-std = 'xxx'
whenTARGET
isn't being built? (thus not parsed in the current state)