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

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
@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 Mar 22, 2025
@onur-ozkan onur-ozkan force-pushed the redesign-stage0-std branch from bcedb49 to 5071fac Compare March 22, 2025 11:56
@Kobzol
Copy link
Contributor

Kobzol commented Mar 22, 2025

I tried download-rustc = true again. When I do x build (from scratch, without pre-existing build directory), it now builds a stage1 libstd, but it still builds a stage2 sysroot, which is a bit confusing to me, I would expect that it uses the downloaded rustc as stage1, builds stage1 libstd and assembles a stage1 sysroot. But I think that this behavior is pre-existing.

However, when I actually tried to use the stage2 sysroot, it fails with this:

   Compiling hello-world v0.1.0 (/projects/personal/rust/rust/crates/hello-world)
error[E0464]: multiple candidates for `dylib` dependency `std` found
  |
  = note: candidate #1: /projects/personal/rust/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-11d409dc53867953.so
  = note: candidate #2: /projects/personal/rust/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-168b2af3cdbd9a8b.so

error[E0464]: multiple candidates for `dylib` dependency `std` found
 --> src/main.rs:3:5
  |
3 | use std::path::PathBuf;
  |     ^^^
  |
  = note: candidate #1: /projects/personal/rust/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-11d409dc53867953.so
  = note: candidate #2: /projects/personal/rust/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-168b2af3cdbd9a8b.so

It seems like multiple standard libraries are being copied to the stage2 sysroot.

@onur-ozkan onur-ozkan force-pushed the redesign-stage0-std branch from 5071fac to ba875be Compare March 22, 2025 12:57
@onur-ozkan
Copy link
Member Author

I tried download-rustc = true again. When I do x build (from scratch, without pre-existing build directory), it now builds a stage1 libstd, but it still builds a stage2 sysroot, which is a bit confusing to me, I would expect that it uses the downloaded rustc as stage1, builds stage1 libstd and assembles a stage1 sysroot. But I think that this behavior is pre-existing.

However, when I actually tried to use the stage2 sysroot, it fails with this:

   Compiling hello-world v0.1.0 (/projects/personal/rust/rust/crates/hello-world)
error[E0464]: multiple candidates for `dylib` dependency `std` found
  |
  = note: candidate #1: /projects/personal/rust/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-11d409dc53867953.so
  = note: candidate #2: /projects/personal/rust/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-168b2af3cdbd9a8b.so

error[E0464]: multiple candidates for `dylib` dependency `std` found
 --> src/main.rs:3:5
  |
3 | use std::path::PathBuf;
  |     ^^^
  |
  = note: candidate #1: /projects/personal/rust/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-11d409dc53867953.so
  = note: candidate #2: /projects/personal/rust/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-168b2af3cdbd9a8b.so

It seems like multiple standard libraries are being copied to the stage2 sysroot.

Thanks for testing it! Can you try again? It should be working now.

@Kobzol
Copy link
Contributor

Kobzol commented Mar 22, 2025

Thanks! It indeed seems to work now, and changes in stdlib are reflected in the stage2 toolchain. Given the amount of if builder.download_rustc() checks in bootstrap, I expect that there will be some other rough edges, but the basic use-case of "download rustc when you only want to modify the library" seems to work now 👍

One thing I have noticed is that if I modify stdlib and then try to rebuild a crate using the stage2 toolchain, cargo doesn't notice that the stdlib has been invalidated, and I have to remove the target directory in order to force recompilation and see the new stdlib code in effect. I'm not sure if this happened before - perhaps not, because "naive" modifications of the stdlib also rebuilt the compiler before? Anyway, it's not a blocking concern, just something that we might want to write down somewhere, as it can be a bit surprising behavior.

@onur-ozkan
Copy link
Member Author

One thing I have noticed is that if I modify stdlib and then try to rebuild a crate using the stage2 toolchain, cargo doesn't notice that the stdlib has been invalidated, and I have to remove the target directory in order to force recompilation and see the new stdlib code in effect. I'm not sure if this happened before - perhaps not, because "naive" modifications of the stdlib also rebuilt the compiler before? Anyway, it's not a blocking concern, just something that we might want to write down somewhere, as it can be a bit surprising behavior.

That happens on master even without CI-rustc enabled.

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 for working on this! The changes themselves look good to me. I have further (manual) testing I would like to do on Monday to exercise some more flows, especially related to dist flows, build cache invalidations and test flows.

(Purely illustrative .oO)

test-flows

@bors
Copy link
Contributor

bors commented Mar 22, 2025

☔ The latest upstream changes (presumably #136974) made this pull request unmergeable. Please resolve the merge conflicts.

On stage 0, rather than compiling std utilize the one from the stage0 sysroot
as stage 0 should represent the snapshot version not the compiled one.

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]>
Signed-off-by: onur-ozkan <[email protected]>
@onur-ozkan onur-ozkan force-pushed the redesign-stage0-std branch from ba875be to 8072fa1 Compare March 22, 2025 16:50
@onur-ozkan
Copy link
Member Author

Rebased.

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