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

Running ./x.py test miri --stage 0 twice rebuilds miri, cargo-miri, and rustdoc #123177

Closed
RalfJung opened this issue Mar 28, 2024 · 13 comments · Fixed by #123192 or #126934
Closed

Running ./x.py test miri --stage 0 twice rebuilds miri, cargo-miri, and rustdoc #123177

RalfJung opened this issue Mar 28, 2024 · 13 comments · Fixed by #123192 or #126934
Labels
T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@RalfJung
Copy link
Member

This is fairly easy to reproduce:

./x.py test miri --stage 0 --test-args hello
./x.py test miri --stage 0 --test-args hello

(The --test-args just serves to make this take less long.)

The second command shouldn't have to build anything, just run the tests. But somehow it actually rebuilds miri, cargo-miri, and rustdoc.

This is a recent regression introduced by #123028. Somehow building rustdoc seems to destroy the build cache for miri and cargo-miri, and vice versa.
Cc @onur-ozkan

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 28, 2024
@onur-ozkan onur-ozkan added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 29, 2024
@onur-ozkan
Copy link
Member

Building rustdoc using the stage 1 compiler causes this, which is weird. I suspect that previously invoked miri related steps may have broken the cache somehow. Or we may need to improve/enhance Builder::ensure.

@RalfJung
Copy link
Member Author

I've just found this in the rustdoc sources:

// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
// we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
// compilers, which isn't what we want. Rustdoc should be linked in the same way as the
// rustc compiler it's paired with, so it must be built with the previous stage compiler.
let build_compiler = builder.compiler(target_compiler.stage - 1, builder.config.build);

Maybe Miri should do something similar. Then ./x.py test miri should also Do The Right Thing without adding --stage 0 (since actually stage 1 would be the right stage to use). And maybe then the rebuilding issue also vanishes. Or maybe that's unrelated, not sure.

@onur-ozkan
Copy link
Member

That would work actually, it seems to be the right path.

@RalfJung
Copy link
Member Author

Unfortunately it doesn't help. We probably still should do it.

But somehow building rustdoc seems to delete the build cache for Miri and cargo-miri, and vice versa.

@RalfJung
Copy link
Member Author

Cargo has this to say about why things are rebuilt:

       Dirty libc v0.2.153: the rustflags changed

And indeed, rustdoc sets

cargo.rustflag("--cfg=parallel_compiler");

That's a bit annoying to have this set in the tool, it means each tool needs to repeat the same logic.

@onur-ozkan
Copy link
Member

onur-ozkan commented Mar 30, 2024

iirc rustdoc sets that to not dirt the compiler builds, we should probably handle that more globally.

@RalfJung
Copy link
Member Author

iirc rustdoc sets that to not dirt the compiler builds, we should probably handle that more globally.

Yup, that's what the last commit in #123192 does now.

bors added a commit to rust-lang-ci/rust that referenced this issue Mar 31, 2024
…-ozkan

Refactor the way bootstrap invokes `cargo miri`

Instead of basically doing `cargo run --manifest-path=<cargo-miri's manifest> -- miri`, let's invoke the `cargo-miri` binary directly. That means less indirections, and also makes it easier to e.g. run the libcore test suite in Miri. (But there are still other issues with that.)

Also also adjusted Miri's stage numbering so that it is consistent with rustc/rustdoc.

This also makes `./x.py test miri` honor `--no-doc`.

And this fixes rust-lang#123177 by moving where we handle parallel_compiler.
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 31, 2024
…-ozkan

Refactor the way bootstrap invokes `cargo miri`

Instead of basically doing `cargo run --manifest-path=<cargo-miri's manifest> -- miri`, let's invoke the `cargo-miri` binary directly. That means less indirections, and also makes it easier to e.g. run the libcore test suite in Miri. (But there are still other issues with that.)

Also also adjusted Miri's stage numbering so that it is consistent with rustc/rustdoc.

This also makes `./x.py test miri` honor `--no-doc`.

And this fixes rust-lang#123177 by moving where we handle parallel_compiler.
@bors bors closed this as completed in 871df0d Apr 1, 2024
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Apr 3, 2024
Refactor the way bootstrap invokes `cargo miri`

Instead of basically doing `cargo run --manifest-path=<cargo-miri's manifest> -- miri`, let's invoke the `cargo-miri` binary directly. That means less indirections, and also makes it easier to e.g. run the libcore test suite in Miri. (But there are still other issues with that.)

Also also adjusted Miri's stage numbering so that it is consistent with rustc/rustdoc.

This also makes `./x.py test miri` honor `--no-doc`.

And this fixes rust-lang/rust#123177 by moving where we handle parallel_compiler.
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
Refactor the way bootstrap invokes `cargo miri`

Instead of basically doing `cargo run --manifest-path=<cargo-miri's manifest> -- miri`, let's invoke the `cargo-miri` binary directly. That means less indirections, and also makes it easier to e.g. run the libcore test suite in Miri. (But there are still other issues with that.)

Also also adjusted Miri's stage numbering so that it is consistent with rustc/rustdoc.

This also makes `./x.py test miri` honor `--no-doc`.

And this fixes rust-lang/rust#123177 by moving where we handle parallel_compiler.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
Refactor the way bootstrap invokes `cargo miri`

Instead of basically doing `cargo run --manifest-path=<cargo-miri's manifest> -- miri`, let's invoke the `cargo-miri` binary directly. That means less indirections, and also makes it easier to e.g. run the libcore test suite in Miri. (But there are still other issues with that.)

Also also adjusted Miri's stage numbering so that it is consistent with rustc/rustdoc.

This also makes `./x.py test miri` honor `--no-doc`.

And this fixes rust-lang/rust#123177 by moving where we handle parallel_compiler.
@RalfJung
Copy link
Member Author

This issue is back now, I am again seeing rebuilds of Miri and rustdoc all the time. Did something change in bootstrap?

@RalfJung RalfJung reopened this Jun 25, 2024
@onur-ozkan
Copy link
Member

Couldn't reproduce it on my side with default config (without the config.toml file).

$ ./x build rustdoc
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.03s
WARNING: you have not made a `config.toml`
HELP: consider running `./x.py setup` or copying `config.example.toml` by running `cp config.example.toml config.toml`
Building stage0 library artifacts (x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized] target(s) in 0.10s
Building compiler artifacts (stage0 -> stage1, x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized] target(s) in 0.17s
Creating a sysroot for stage1 compiler (use `rustup toolchain link 'name' build/host/stage1`)
Building stage0 tool lld-wrapper (x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized] target(s) in 0.09s
Building tool rustdoc (stage0 -> stage1, x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized] target(s) in 0.11s
WARNING: you have not made a `config.toml`
HELP: consider running `./x.py setup` or copying `config.example.toml` by running `cp config.example.toml config.toml`
NOTE: this message was printed twice to make it more likely to be seen
Build completed successfully in 0:00:02

$ git log -1
commit 164e1297e1bce47a241e4d93a9f044452b288715 (HEAD -> master, origin/master, origin/HEAD)
Merge: fc555cd832e 45da03541c0
Author: bors <bors@rust-lang.org>
Date:   Tue Jun 25 05:09:30 2024 +0000

    Auto merge of #125610 - oli-obk:define_opaque_types14, r=compiler-errors

    Allow constraining opaque types during various unsizing casts

    allows unsizing of tuples, arrays and Adts to constraint opaque types in their generic parameters to concrete types on either side of the unsizing cast.

    Also allows constraining opaque types during trait object casts that only differ in auto traits or lifetimes.

    cc #116652

There might be a specific option that triggers this. Can you share your config?

@onur-ozkan
Copy link
Member

Couldn't reproduce it on my side with default config (without the config.toml file).

$ ./x build rustdoc
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.03s
WARNING: you have not made a `config.toml`
HELP: consider running `./x.py setup` or copying `config.example.toml` by running `cp config.example.toml config.toml`
Building stage0 library artifacts (x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized] target(s) in 0.10s
Building compiler artifacts (stage0 -> stage1, x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized] target(s) in 0.17s
Creating a sysroot for stage1 compiler (use `rustup toolchain link 'name' build/host/stage1`)
Building stage0 tool lld-wrapper (x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized] target(s) in 0.09s
Building tool rustdoc (stage0 -> stage1, x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized] target(s) in 0.11s
WARNING: you have not made a `config.toml`
HELP: consider running `./x.py setup` or copying `config.example.toml` by running `cp config.example.toml config.toml`
NOTE: this message was printed twice to make it more likely to be seen
Build completed successfully in 0:00:02

$ git log -1
commit 164e1297e1bce47a241e4d93a9f044452b288715 (HEAD -> master, origin/master, origin/HEAD)
Merge: fc555cd832e 45da03541c0
Author: bors <bors@rust-lang.org>
Date:   Tue Jun 25 05:09:30 2024 +0000

    Auto merge of #125610 - oli-obk:define_opaque_types14, r=compiler-errors

    Allow constraining opaque types during various unsizing casts

    allows unsizing of tuples, arrays and Adts to constraint opaque types in their generic parameters to concrete types on either side of the unsizing cast.

    Also allows constraining opaque types during trait object casts that only differ in auto traits or lifetimes.

    cc #116652

There might be a specific option that triggers this. Can you share your config?

Seems like it only happens with x test caused by different rustflags.

@RalfJung
Copy link
Member Author

The command I was running is ./x.py miri library/core --test-args notest. Running that command multiple times in a row rebuilds miri and rustdoc each time. Adding --no-doc avoids that.

@onur-ozkan
Copy link
Member

onur-ozkan commented Jun 25, 2024

Found the problem and opened the fix PR. I will try to add a bootstrap test (around this weekend) for ensuring this never happens again.

@RalfJung
Copy link
Member Author

Thanks for the quick debugging :)

compiler-errors added a commit to compiler-errors/rust that referenced this issue Jun 25, 2024
…obzol

fix broken build cache caused by rustdoc builds

Currently rustdoc breaks the build cache (due to having different rustflags) when building rustdoc before building another tool (e.g., `x test miri && x test rustdoc && x test miri`).

This change fixes that by moving `on-broken-pipe` into `prepare_cargo_tool` so it is set for all tools.

cc `@RalfJung`

Fixes rust-lang#123177
@bors bors closed this as completed in bae813a Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
3 participants