Skip to content

redesign stage 0 std #119899

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

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

try-job: dist-x86_64-linux

@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
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 10, 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

try-job: dist-x86_64-linux
@bors
Copy link
Collaborator

bors commented Apr 10, 2025

☀️ Try build successful - checks-actions
Build commit: 424ee44 (424ee4431faa6f45caca8312cb7e92b94a294898)

@onur-ozkan
Copy link
Member Author

It worked, nice :)

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Apr 10, 2025
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Apr 11, 2025
std: make `cmath` functions safe

The floating point intrinsics are more difficult, I'll probably wait until rust-lang#119899 has merged before making them safe as well.
ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Apr 12, 2025
std: make `cmath` functions safe

The floating point intrinsics are more difficult, I'll probably wait until rust-lang#119899 has merged before making them safe as well.
ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Apr 12, 2025
std: make `cmath` functions safe

The floating point intrinsics are more difficult, I'll probably wait until rust-lang#119899 has merged before making them safe as well.
ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Apr 13, 2025
std: make `cmath` functions safe

The floating point intrinsics are more difficult, I'll probably wait until rust-lang#119899 has merged before making them safe as well.
ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Apr 13, 2025
std: make `cmath` functions safe

The floating point intrinsics are more difficult, I'll probably wait until rust-lang#119899 has merged before making them safe as well.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 13, 2025
Rollup merge of rust-lang#139107 - joboet:safe_cmath, r=ibraheemdev

std: make `cmath` functions safe

The floating point intrinsics are more difficult, I'll probably wait until rust-lang#119899 has merged before making them safe as well.
Copy link
Member

@RalfJung RalfJung Apr 15, 2025

Choose a reason for hiding this comment

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

I just learned about compiletest-use-stage0-libtest. Does this PR make true the default value for that? It seems like there's no good reason to even still support false for that option, or is there?

Copy link
Member

@jieyouxu jieyouxu Apr 15, 2025

Choose a reason for hiding this comment

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

It seems like there's no good reason to even still support false for that option, or is there?

true might make sense as a default (since libtest programmatic API changes relatively unfrequently), but if someone is working on a libtest (programmatic API) change that can require changing compiletest, in which case the contributor would probably want to use false so that they can test their changes for compiletest too.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just learned about compiletest-use-stage0-libtest. Does this PR make true the default value for that? It seems like there's no good reason to even still support false for that option, or is there?

The default value for that option is already true and false is useful to detect breaking changes from libtest to compiletest. Currently we run x check compiletest with compiletest-use-stage0-libtest=false on couple of CI runners to prevent that.

Copy link
Member

@RalfJung RalfJung Apr 22, 2025

Choose a reason for hiding this comment

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

The default value for that option is already true

The reason I thought it was "false" is that the change notification says
"Added a new option build.compiletest-use-stage0-libtest to force compiletest to use the stage 0 libtest."
That sure sounds like if I want compiletest to use stage 0 libtest I need to "force" that to happen by manually changing the configuration.

@RalfJung
Copy link
Member

RalfJung commented Apr 15, 2025 via email

github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Apr 19, 2025
std: make `cmath` functions safe

The floating point intrinsics are more difficult, I'll probably wait until rust-lang#119899 has merged before making them safe as well.
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Apr 28, 2025
…, r=jieyouxu,kobzol

make it possible to use stage0 libtest on compiletest

With rust-lang/rust#119899, building the library tree will require a stage 1 compiler. This is because `compiletest` is defined as a `ToolStd` (since rust-lang/rust#68019) in order to use the in-tree library. As a result, rust-lang/rust#119899 makes certain development workflows more difficult as changes on the compiler tree will now require recompiling `compiletest` each time.

This PR allows switching `ToolStd` to `ToolBootstrap` with a simple boolean option in `bootstrap.toml` to allow `compiletest` to use the stage 0 `libtest` instead.

The changes under `src/ci` are clearly intended to make sure that `compiletest` doesn't break during future bootstrap beta bumps.
@onur-ozkan
Copy link
Member Author

Any idea what we are waiting for?

@jieyouxu
Copy link
Member

A few small things:

FYI @rust-lang/bootstrap since this is a major bootstrap change, in case you have any last minute review feedback.

@onur-ozkan
Copy link
Member Author

A few small things:

FYI @rust-lang/bootstrap since this is a major bootstrap change, in case you have any last minute review feedback.

Okay.

@rustbot blocked

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 29, 2025
tgross35 added a commit to tgross35/rust that referenced this pull request Apr 29, 2025
compiletest: Remove the libtest-based executor and its dependency

Now that rust-lang#140288 has landed and the new compiletest executor is used by default, we can now move forward with removing the libtest dependency from compiletest.

My hope is that after landing this, we can configure bootstrap to build compiletest with the pre-built stage0 library by default, instead of the in-tree stage0 library. That would give the stage0 redesign one less thing to worry about.

---

This PR has deliberately been kept small and simple, to make it easier to revert if necessary. Further cleanup can take palce after we're confident that it won't need to be reverted.

r? jieyouxu

Blocker for rust-lang#119899
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 29, 2025
Rollup merge of rust-lang#140392 - Zalathar:goodbye-libtest, r=jieyouxu

compiletest: Remove the libtest-based executor and its dependency

Now that rust-lang#140288 has landed and the new compiletest executor is used by default, we can now move forward with removing the libtest dependency from compiletest.

My hope is that after landing this, we can configure bootstrap to build compiletest with the pre-built stage0 library by default, instead of the in-tree stage0 library. That would give the stage0 redesign one less thing to worry about.

---

This PR has deliberately been kept small and simple, to make it easier to revert if necessary. Further cleanup can take palce after we're confident that it won't need to be reverted.

r? jieyouxu

Blocker for rust-lang#119899
@krasimirgg
Copy link
Contributor

onur-ozkan, first, I think this work is really cool!

We've got a custom rust bootstrapping setup that doesn't invoke x directly. I've applied the complier and library changes from this PR and adapted it to use beta-rustc and beta-stdlibs to build the first new rustc. I ran into a curious build failure about an interaction between compiler/rustc_expand/src/proc_macro_server.rs and library/proc_macro/src/bridge/server.rs:

error[E0046]: not all trait items implemented, missing: `SourceFile`
   --> compiler/rustc_expand/src/proc_macro_server.rs:457:1
    |
457 | impl server::Types for Rustc<'_, '_> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `SourceFile` in implementation
    |
    = help: implement the missing item: `type SourceFile = /* Type */;`

error[E0046]: not all trait items implemented, missing: `source_file`
   --> compiler/rustc_expand/src/proc_macro_server.rs:665:1
    |
665 | impl server::Span for Rustc<'_, '_> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `source_file` in implementation
    |
    = help: implement the missing item: `fn source_file(&mut self, _: <Self as Types>::Span) -> <Self as Types>::SourceFile { todo!() }`

error[E0277]: the trait bound `Rustc<'_, '_>: server::SourceFile` is not satisfied
   --> compiler/rustc_expand/src/proc_macro_server.rs:833:25
    |
833 | impl server::Server for Rustc<'_, '_> {
    |                         ^^^^^^^^^^^^^ the trait `server::SourceFile` is not implemented for `Rustc<'_, '_>`
    |
note: required by a bound in `Server`
   --> /rustc/45165c82a4c5315ff52c391ad138f41ff40b52d8/library/proc_macro/src/bridge/server.rs:121:1
    = note: `Server` is a "sealed trait", because to implement it you also need to implement `pm::bridge::server::SourceFile`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it
    = help: the following type implements the trait:
              pm::bridge::server::MarkedTypes<S>
    = note: this error originates in the macro `declare_server_traits` which comes from the expansion of the macro `with_api` (in Nightly builds, run with -Z macro-backtrace for more info)

Naively, this looks related to this commit 3962069#diff-002b2429c67f4267af1485b8b9e2f95cbfe586971ed97f832da4d4d45d0e1e41, where the source file was removed from both the library and compiler sides in lockstep. How does the redesigned bootstrap workflow handle cases like this?

@Kobzol
Copy link
Contributor

Kobzol commented Apr 30, 2025

Do we still need stage0-sysroot after this PR? (

host_dir.join("stage0-sysroot")
). I guess not, but also it can probably stay and we can remove it later once this is merged?

@bjorn3
Copy link
Member

bjorn3 commented Apr 30, 2025

I think rustc_expand will need to be changed to depend on the in-tree libproc_macro directly rather than fetching it from the sysroot. It needs to link against a libproc_macro built from the same sources as the one that will end up in it's own sysroot. It doesn't care about the libproc_macro copy that is in the sysroot with which rustc itself was built. It just happens to be the case that before this PR, both copies are built from the same source and thus are ABI compatible (libproc_macro uses the C ABI internally, so only the source needs to match for ABI compat, not the rustc it was built with).

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-blocked Status: Blocked on something else such as an RFC or other implementation work. 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.