Skip to content

Support JSON target specs in bootstrap#152677

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
ehuss:bootstrap-json-target-spec
Feb 17, 2026
Merged

Support JSON target specs in bootstrap#152677
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
ehuss:bootstrap-json-target-spec

Conversation

@ehuss
Copy link
Copy Markdown
Contributor

@ehuss ehuss commented Feb 15, 2026

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 rustc without the ability for the user to provide additional flags (primarily, -Zunstable-options to enable JSON targets).

There's a few different ways to fix this. One would be to change these calls to rustc to include flags provided by the user (such as RUSTFLAGS_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 --target flag. For example, that's what cargo does in CompileKind::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 .json extension will now require passing -Zjson-target-spec (from
rust-lang/cargo#16557). This does not affect target specs without the .json extension (such as those from RUST_TARGET_PATH). From my testing, it should be sufficient to pass CARGOFLAGS_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-spec appropriately. 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

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustc is not building for custom targets

5 participants