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

redesign stage 0 std #119899

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

Conversation

onur-ozkan
Copy link
Member

@onur-ozkan onur-ozkan commented Jan 12, 2024

Summary

This PR changes how bootstrap builds the stage 1 compiler by switching to precompiled stage 0 standard library instead of building the in-tree one. The goal was to update bootstrap to use the beta standard library at stage 0 rather than compiling it from source (see the motivation at rust-lang/compiler-team#619).

Previously, to build a stage 1 compiler bootstrap followed this path:

download stage0 compiler -> build in-tree std -> compile stage1 compiler with in-tree std

With this PR, the new path is:

download stage0 compiler -> compile stage1 compiler with precompiled stage0 std

This also means that cfg(bootstrap)/cfg(not(bootstrap)) is no longer needed for library development.

Building "library"

Since stage0 std is no longer in-tree x build/test/check library --stage 0 is now no-op. The minimum supported stage to build std is now 1. For the same reason, default stage values in the library profile is no longer 0.

Because building the in-tree library now requires a stage1 compiler, I highly recommend library developers to enable download-rustc to speed up compilation time.


If you encounter a bug or unexpected results please open a topic in the #t-infra/bootstrap Zulip channel or create a bootstrap issue.

(Review thread: https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Review.20thread.3A.20stage.200.20redesign.20PR/with/508271433)

Blocked on #122709

@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 Jan 12, 2024
@onur-ozkan onur-ozkan added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 12, 2024
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Jan 13, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@onur-ozkan onur-ozkan force-pushed the redesign-stage0-std branch 2 times, most recently from ce81474 to b688ffa Compare January 13, 2024 15:51
@rust-log-analyzer

This comment has been minimized.

@onur-ozkan onur-ozkan force-pushed the redesign-stage0-std branch 6 times, most recently from 5f1747d to 00e59f0 Compare January 14, 2024 13:30
@onur-ozkan onur-ozkan marked this pull request as ready for review January 14, 2024 13:57
@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2024

This PR modifies src/bootstrap/src/core/config.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

@onur-ozkan onur-ozkan changed the title [WIP] redesign stage 0 std redesign stage 0 std Jan 14, 2024
@onur-ozkan
Copy link
Member Author

@rustbot ready

r? bootstrap
cc @rust-lang/libs

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 14, 2024
@onur-ozkan
Copy link
Member Author

@rustbot author (currently stage 2 std is copied from stage 1 and this behaviour should change with the beta std change)

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 14, 2024
Signed-off-by: onur-ozkan <[email protected]>
Signed-off-by: onur-ozkan <[email protected]>
Signed-off-by: onur-ozkan <[email protected]>
Signed-off-by: onur-ozkan <[email protected]>
Signed-off-by: onur-ozkan <[email protected]>
Signed-off-by: onur-ozkan <[email protected]>
Signed-off-by: onur-ozkan <[email protected]>
Signed-off-by: onur-ozkan <[email protected]>
Signed-off-by: onur-ozkan <[email protected]>
Signed-off-by: onur-ozkan <[email protected]>
@onur-ozkan onur-ozkan force-pushed the redesign-stage0-std branch from 8072fa1 to 664d864 Compare April 1, 2025 07:00
@onur-ozkan
Copy link
Member Author

Rebased.

Do you still plan to test this PR @jieyouxu? I've rebased it multiple times and it's exhausting a lot, so I would like to hold rebasing again until everyone has finished reviewing and testing.

@jieyouxu
Copy link
Member

jieyouxu commented Apr 1, 2025

Yes I'm still testing (but progress has been slow), rebasing is not necessary.

EDIT: trying to get the testing done by today.

@jieyouxu
Copy link
Member

jieyouxu commented Apr 2, 2025

Sorry for the wait, but local testing looks good to me (ignore the two problems previously, consider them resolved as they were also discussed in the review thread).

@jieyouxu
Copy link
Member

jieyouxu commented Apr 2, 2025

Local manual testing (Round 1)

Note

  • Datetime: 2025-04-02 Day
  • PR commit: 664d864
  • Rebased against 9daffa3.

Known and intentional omissions

  • Does not include "base cases" from Round 0.
  • Testing conducted on this PR does not exercise download-rustc = "if-unchanged" because this PR obviously by necessity has to modify the compiler/ tree, thereby disqualifying CI rustc "if-unchanged".
  • Still missing a lot of configurations.
  • Canadian cross scenarios (build != host != target) not tested.
  • Local LLVM build not tested.
  • macOS host/target not tested.
  • windows-{gnu,msvc} as host/target platform not tested.
  • ... and a lot more, not tractable to test locally.

Tests

Uniform platform (build == host == target)

Cherry-picked platform: aarch64-unknown-linux-gnu
(This is conducted on one of the AArch64 dev-desktops.)

Check flow

profile = "library" + ./x check library
Kind
Description Minimal library profile, download CI rustc unspecified, check library with no explicit stage
Invocation ./x check library
Outcome OK; a local stage 1 rustc was built because PR modifies compiler/ tree
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "library"
EOF

Invocation

$ ./x check library

Assessment

Watching output. Observe that stage1 rustc was fully built instead of downloading and using CI rustc.

Teardown

$ rm -rf build/
profile = "library" + download-rustc = false + ./x check library
Kind
Description Library profile, force disable CI rustc, check library with no explicit stage
Invocation ./x check library
Outcome OK; builds stage 1 compiler, checks stage 1 library incl. bench example
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "library"
[rust]
download-rustc = false
EOF

Invocation

$ ./x check library

Assessment

Stage 1 rustc built, stage 1 library artifacts checked

Teardown

$ rm -rf build/
profile = "library" + ./x check library --stage=0
Kind
Description Minimal library profile, check at stage 0
Invocation ./x check library --stage=0
Outcome OK; no-op as expected
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "library"
EOF

Invocation

$ ./x check library --stage=0

Assessment

Ok, no-op.

Teardown

$ rm -rf build/
profile = "library" + ./x check library --stage=1
Kind
Description Minimal library profile; check at explicit stage 1
Invocation ./x check library --stage=1
Outcome OK; builds stage 1 rustc, checks stage 1 library artifacts
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "library"
EOF

Invocation

$ ./x check library --stage=1

Assessment

Builds stage 1 rustc, checks stage 1 library artifacts

Teardown

$ rm -rf build/
profile = "library" + ./x check library --stage=2
Kind
Description Minimal library profile, check at explicit stage 2
Invocation ./x check library --stage=2
Outcome OK; builds stage 1/2 rustc, stage 1 library, checks stage 2 library
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "library"
EOF

Invocation

$ ./x check library --stage=2

Assessment

Builds stage 1 rustc, stage 1 library, stage 2 rustc.
Checks stage 2 library.

Teardown

$ rm -rf build/
profile = "library" + ./x check std
Kind
Description Minimal library profile, check with std path
Invocation ./x check std
Outcome Builds stage 1 rustc; Checks stage 1 std
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "library"
EOF

Invocation

$ ./x check std

Assessment

Builds stage 1 rustc, checks stage 1 std

Teardown

$ rm -rf build/
profile = "library" + ./x check core
Kind
Description Minimal library profile, check core path
Invocation ./x check core
Outcome OK; builds stage 1 rustc, checks stage 1 core
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "library"
EOF

Invocation

$ ./x check core

Assessment

Builds stage 1 rustc, checks stage 1 core

Teardown

$ rm -rf build/
profile = "library" + ./x check alloc
Kind
Description Library profile, check alloc path
Invocation ./x check alloc
Outcome OK; builds stage 1 rustc, checks stage 1 alloc
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "library"
EOF

Invocation

$ ./x check alloc

Assessment

Builds stage 1 rustc, checks stage 1 alloc

Teardown

$ rm -rf build/

Build flow

profile = "compiler" + ./x build library --stage=0
Kind
Description Compiler profile, explicit stage 0 library
Invocation ./x build library --stage=0
Outcome OK; no-op
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "compiler"
EOF

Invocation

$ ./x build library --stage=0

Assessment

  • No-op.
    -build/host/stage0/bin/rustc -vV is beta rustc.

Teardown

$ rm -rf build/
profile = "compiler" + ./x build library --stage=1
Kind
Description Compiler profile, explicit stage 1 library
Invocation ./x build library --stage=1
Outcome OK; builds stage 1 rustc/library, rustc binary OK
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "compiler"
EOF

Invocation

$ ./x build library --stage=1

Assessment

  • Builds stage 1 rustc, stage 1 library.
  • build/host/stage1/bin/rustc -vV OK.

Teardown

$ rm -rf build/
profile = "compiler" + ./x build library --stage=2
Kind
Description Minimal compiler profile, build explicit stage 2 library
Invocation ./x build library --stage=2
Outcome OK; builds stage 1 rustc/library, builds stage 2 rustc, uplifts stage 2 rustc, stage 2 rustc OK
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "compiler"
EOF

Invocation

$ ./x build library --stage=2

Assessment

  • Builds stage 1 rustc, stage 1 library, stage 2 rustc, uplift stage 2 library.
  • build/host/stage2/bin/rustc -vV OK

Teardown

$ rm -rf build/

Test flow

COMPILETEST_FORCE_STAGE0=1 ./x test run-make --stage=0
Kind
Description Compiler profile, forced stage 0 run-make
Invocation COMPILETEST_FORCE_STAGE0=1 ./x test run-make --stage=0
Outcome OK; expected amount of failures
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "compiler"
EOF

Invocation

$ COMPILETEST_FORCE_STAGE0=1 ./x test run-make --stage=0

Assessment

OK, amount of failure is expected.

Teardown

$ rm -rf build/
profile = "compiler" + ./x test --stage=2
Kind
Description Compiler profile, full explicit stage 2 tests
Invocation ./x test --stage=2
Outcome OK
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "compiler"
EOF

Invocation

$ ./x test --stage=2 --skip=tests/debuginfo

NOTE: debuginfo tests were failing because of Python stuff, unrelated to change.

Assessment

Seems okay.

Teardown

$ rm -rf build/

Build cache invalidation and spurious rebuilds

profile = "compiler" + ./x test mir-opt + ./x test mir-opt
Kind
Description Compiler profile, test library twice
Invocation ./x test mir-opt, ./x test mir-opt
Outcome OK; no library rebuilds
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "compiler"
EOF

Invocation

$ `./x test mir-opt`

Assessment

OK, no unnecessary library rebuilds

Teardown

$ rm -rf build/

--keep-stage-std

profile = "compiler" + ./x build library --stage=1 + ./x build library --keep-stage-std=1
Kind
Description Compiler profile, build stage 1 library, modify rustc, keep stage 1 std
Invocation ./x build library --stage=1, ./x build library --keep-stage-std=1
Outcome OK; stage 1 library not rebuilt
To reproduce

Setup

$ rm -rf build/
$ tee config.toml <<EOF
profile = "compiler"
EOF

Invocation

$ ./x build library --stage=1
$ echo "// meow" >> compiler/rustc_driver/src/lib.rs
$ ./x build library --keep-stage-std=1

Assessment

Stage 1 library not rebuilt

Teardown

$ rm -rf build/
$ git checkout -- .

Cross-compile (build == host)

Cherry-picked sample:

  • Build platform: x86_64-unknown-linux-gnu
  • Host platform: x86_64-unknown-linux-gnu
  • Target platform: wasm32-unknown-unknown
Kind
Description Compiler profile, cross build stage 1 to wasm32-u-u
Invocation ./x build library
Outcome OK; cross build successful
To reproduce

Setup

Download [wasi-sdk 25 wasi-sdk-25.0-arm64-linux.tar.gz] and extract to ../wasi-sdk-24.0-x86_64-linux/.

$ rm -rf build/
$ tee config.toml <<EOF
profile = "compiler"

[build]
target = [
  "wasm32-unknown-unknown",
]

[target."wasm32-unknown-unknown"]
wasi-root = "../wasi-sdk-24.0-x86_64-linux/"
EOF

Invocation

$ ./x build library

Assessment

OK; stage 1 library cross to wasm32-u-u.

Teardown

$ rm -rf build/

@onur-ozkan
Copy link
Member Author

I think the merge CI will run the most comprehensive and detailed tests on this.

@RalfJung
Copy link
Member

RalfJung commented Apr 2, 2025

Many things are not tested by CI, e.g. AFAIK we still do not test whether things like Miri work properly in stage 1 (might be stage 0 after this PR?). CI typically only tests stage 2, involving at least 2 compiler builds, which does not match local development builds.

@Kobzol
Copy link
Contributor

Kobzol commented Apr 2, 2025

(I will also run a bunch of try builds here to check that they work and how long they take).

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 2, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2025
redesign stage 0 std

### Summary

This PR changes how bootstrap builds the stage 1 compiler by switching to precompiled stage 0 standard library instead of building the in-tree one. The goal was to update bootstrap to use the beta standard library at stage 0 rather than compiling it from source (see the motivation at rust-lang/compiler-team#619).

Previously, to build a stage 1 compiler bootstrap followed this path:

```
download stage0 compiler -> build in-tree std -> compile stage1 compiler with in-tree std
```

With this PR, the new path is:

```
download stage0 compiler -> compile stage1 compiler with precompiled stage0 std
```

This also means that `cfg(bootstrap)`/`cfg(not(bootstrap))` is no longer needed for library development.

### Building "library"

Since stage0 `std` is no longer in-tree `x build/test/check library --stage 0` is now no-op. The minimum supported stage to build `std` is now 1. For the same reason, default stage values in the library profile is no longer 0.

Because building the in-tree library now requires a stage1 compiler, I highly recommend library developers to enable `download-rustc` to speed up compilation time.

<hr>

If you encounter a bug or unexpected results please open a topic in the [#t-infra/bootstrap](https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap) Zulip channel or create a [bootstrap issue](https://github.com/rust-lang/rust/issues/new?template=bootstrap.md).

(Review thread: https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Review.20thread.3A.20stage.200.20redesign.20PR/with/508271433)

~~Blocked on rust-lang#122709
@bors
Copy link
Collaborator

bors commented Apr 2, 2025

⌛ Trying commit 664d864 with merge 5f2f74fb8dda1fcd5e50db388713213585ff11c3...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustc-dev-guide Area: rustc-dev-guide A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-perf Status: Waiting on a perf run to be completed. 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) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.