Support JSON target specs in bootstrap#152677
Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom Feb 17, 2026
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
JSON target specs were destabilized in #150151 and #151534. However, this broke trying to build rustc itself with a JSON target spec. This is because in a few places bootstrap is manually calling
rustcwithout the ability for the user to provide additional flags (primarily,-Zunstable-optionsto enable JSON targets).There's a few different ways to fix this. One would be to change these calls to
rustcto include flags provided by the user (such asRUSTFLAGS_NOT_BOOTSTRAP). Just to keep things simple, this PR proposes to just unconditionally pass-Zunstable-options.Another consideration here is how maintainable this is. A possible improvement here would be to have a function somewhere (BootstrapCommand, TargetSelection, free function) that would handle appropriately adding the
--targetflag. For example, that's what cargo does inCompileKind::add_target_arg.I have only tested building the compiler and a few tools like rustdoc. I have not tested doing things like building other tools, running tests, etc.
This would be much easier if there was a Docker image for testing the use case of building rustc with a custom target spec (and even better if that ran in CI).
After the next beta branch, using target JSON specs will become more cumbersome because target specs with the
.jsonextension will now require passing-Zjson-target-spec(fromrust-lang/cargo#16557). This does not affect target specs without the
.jsonextension (such as those from RUST_TARGET_PATH). From my testing, it should be sufficient to passCARGOFLAGS_NOT_BOOTSTRAP="-Zjson-target-spec". I think that should be fine, since this is not a particularly common use case AFAIK. We could extend bootstrap to auto-detect if the target is a file path, and pass-Zjson-target-specappropriately. I tried something similar in ehuss@f0bdd35, which could be adapted if desired.It would be nice if all of this is documented somewhere. https://rustc-dev-guide.rust-lang.org/building/new-target.html does not really say how to build the compiler with a custom json target.
Fixes #151729