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
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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Feb 15, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 15, 2026

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: bootstrap
  • bootstrap expanded to 6 candidates
  • Random selection from Mark-Simulacrum, clubby789, jieyouxu

@ehuss
Copy link
Contributor Author

ehuss commented Feb 15, 2026

cc @davidtwco

I think this should either be backported to beta, or #150151 reverted on beta. Otherwise 1.94 will not be buildable. I might recommend reverting, so that all of the destabilization changes are in 1.95.

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Happy for #150151 to be reverted on beta.

View changes since this review

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

  • On the bootstrap part, tiny nit re. backlinking to a cleanup issue #152709.
  • Compiler wise, I would lean towards reverting #150151 on beta so the destabilization changes can land together (IIUC).

You can r= david and me after the nit.

View changes since this review

JSON target specs were destabilized in
rust-lang#150151 and
rust-lang#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`](https://github.com/rust-lang/cargo/blob/592058c7ce08a2ba2628b01e7dc4ce1e72b6bdff/src/cargo/core/compiler/compile_kind.rs#L144-L154).

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
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 rust-lang#151729
@ehuss ehuss force-pushed the bootstrap-json-target-spec branch from 24918a5 to b4e645f Compare February 16, 2026 16:31
@ehuss
Copy link
Contributor Author

ehuss commented Feb 16, 2026

@jieyouxu I realized I made a mistake. This was missing RUSTC_BOOTSTRAP. This would otherwise fail when the channel is set to stable. Do the new changes look correct to you?

ehuss added a commit to ehuss/rust that referenced this pull request Feb 16, 2026
This reverts rust-lang#150151 in order to
deal with rust-lang#151729 where the
destabilization caused a problem with building rustc itself with JSON
target specs. There's a fix at
rust-lang#152677, but we would prefer to
not backport that, and instead give ourselves more time to work out the
kinks. Also, the destabilization was incomplete, and the rest of the
changes are in 1.95 (rust-lang#151534 and
rust-lang/cargo#16557), so it would be nice to
keep all the changes together in one release.

This reverts commit a89683d, reversing
changes made to 2f1bd3f.
@ehuss
Copy link
Contributor Author

ehuss commented Feb 16, 2026

Posted a beta revert at #152721.

@jieyouxu
Copy link
Member

@jieyouxu I realized I made a mistake. This was missing RUSTC_BOOTSTRAP. This would otherwise fail when the channel is set to stable. Do the new changes look correct to you?

This seems okay.

Thanks
@bors r+ rollup=never p=1

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 17, 2026

📌 Commit b4e645f has been approved by jieyouxu

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 17, 2026
@jieyouxu
Copy link
Member

@bors r=davidtwco,jieyouxu

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 17, 2026

📌 Commit b4e645f has been approved by davidtwco,jieyouxu

It is now in the queue for this repository.

@rust-bors

This comment has been minimized.

@rust-bors rust-bors bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 17, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 17, 2026

☀️ Test successful - CI
Approved by: davidtwco,jieyouxu
Duration: 4h 1m 44s
Pushing 8387095 to main...

@rust-bors rust-bors bot merged commit 8387095 into rust-lang:main Feb 17, 2026
12 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 17, 2026
rust-bors bot pushed a commit that referenced this pull request Feb 17, 2026
[beta] Revert destabilise target-spec-json

This reverts #150151 in order to deal with #151729 where the destabilization caused a problem with building rustc itself with JSON target specs. There's a fix at #152677, but we would prefer to not backport that, and instead give ourselves more time to work out the kinks. Also, the destabilization was incomplete, and the rest of the changes are in 1.95 (#151534 and rust-lang/cargo#16557), so it would be nice to keep all the changes together in one release.

This reverts commit a89683d, reversing changes made to 2f1bd3f.
@github-actions
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing dfbfbf7 (parent) -> 8387095 (this PR)

Test differences

Show 2 test diffs

2 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 8387095803f21a256a9a772ac1f9b41ed4d5aa0a --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-apple-various: 2h 11m -> 1h 47m (-18.1%)
  2. i686-gnu-1: 2h 21m -> 1h 58m (-16.1%)
  3. pr-check-1: 33m 33s -> 28m 14s (-15.9%)
  4. x86_64-gnu-llvm-20: 1h 18m -> 1h 6m (-15.5%)
  5. x86_64-gnu-distcheck: 2h 21m -> 2h (-15.2%)
  6. test-various: 2h 12m -> 1h 52m (-15.0%)
  7. tidy: 2m 54s -> 2m 31s (-12.9%)
  8. x86_64-gnu-gcc: 1h 10m -> 1h 1m (-11.8%)
  9. x86_64-gnu: 2h 22m -> 2h 6m (-11.3%)
  10. x86_64-gnu-tools: 1h 2m -> 55m 40s (-11.3%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8387095): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary -2.5%, secondary 5.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
5.9% [5.9%, 5.9%] 1
Improvements ✅
(primary)
-2.5% [-2.5%, -2.5%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.5% [-2.5%, -2.5%] 1

Cycles

Results (primary 2.2%, secondary -2.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.2% [2.2%, 2.2%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.9% [-2.9%, -2.9%] 1
All ❌✅ (primary) 2.2% [2.2%, 2.2%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 482.346s -> 480.396s (-0.40%)
Artifact size: 397.84 MiB -> 397.88 MiB (0.01%)

rust-bors bot pushed a commit that referenced this pull request Feb 18, 2026
[beta] Revert destabilise target-spec-json

This reverts #150151 in order to deal with #151729 where the destabilization caused a problem with building rustc itself with JSON target specs. There's a fix at #152677, but we would prefer to not backport that, and instead give ourselves more time to work out the kinks. Also, the destabilization was incomplete, and the rest of the changes are in 1.95 (#151534 and rust-lang/cargo#16557), so it would be nice to keep all the changes together in one release.

This reverts commit a89683d, reversing changes made to 2f1bd3f.
rust-bors bot pushed a commit that referenced this pull request Feb 18, 2026
[beta] Revert destabilise target-spec-json

This reverts #150151 in order to deal with #151729 where the destabilization caused a problem with building rustc itself with JSON target specs. There's a fix at #152677, but we would prefer to not backport that, and instead give ourselves more time to work out the kinks. Also, the destabilization was incomplete, and the rest of the changes are in 1.95 (#151534 and rust-lang/cargo#16557), so it would be nice to keep all the changes together in one release.

This reverts commit a89683d, reversing changes made to 2f1bd3f.
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

Comments