-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Refactor the way bootstrap invokes cargo miri
#123192
Conversation
r? @clubby789 rustbot has assigned @clubby789. Use |
The Miri subtree was changed cc @rust-lang/miri |
@@ -150,7 +150,7 @@ fn main() { | |||
{ | |||
cmd.arg("-Ztls-model=initial-exec"); | |||
} | |||
} else if std::env::var("MIRI").is_err() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not needed anymore, that probably mean that Miri is respecting the RUSTFLAGS
set by bootstrap (or always passing a target). It's probably not worth checking if there are any --cfg bootstrap
or --check-cfg
args being passed, since we will quickly see if CI fails.
Good to see this hack disappear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Miri always passes a target, but that has always been the case. Nothing recently changed wrt RUSTFLAGS either.
But maybe somehow this interacts with the other changes in this PR.
@@ -121,7 +121,6 @@ impl Step for ReplaceVersionPlaceholder { | |||
|
|||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | |||
pub struct Miri { | |||
stage: u32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized this field is unnecessary. At least it seems unnecessary, I don't fully understand how this make_run
vs run
stuff is meant to be used.
161b0e0
to
cd2dbe9
Compare
// `cfg` option for rustc, `features` option for cargo, for conditional compilation | ||
cargo.rustflag("--cfg=parallel_compiler"); | ||
cargo.rustdocflag("--cfg=parallel_compiler"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have traced back every caller of this function and verified that they all call prepare_tool_cargo
with one of the modes that triggers the flag.
25f030b
to
2c7ec0e
Compare
2c7ec0e
to
24ba73c
Compare
@@ -135,29 +133,35 @@ impl Step for Miri { | |||
} | |||
|
|||
fn make_run(run: RunConfig<'_>) { | |||
run.builder.ensure(Miri { | |||
stage: run.builder.top_stage, | |||
host: run.build_triple(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run.build_triple()
returns builder.cmd.build
; I assume that's always the same as builder.build.build
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run.build_triple() returns builder.cmd.build
run.build_triple()
returns builder.build.build
already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, you are right... and builder.cmd.build
does not exist.
But some places use builder.config.build
. That is hopefully the same as builder.build.build
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they are identical.
24ba73c
to
1dd0f30
Compare
"run", | ||
"src/tools/miri/cargo-miri", | ||
target_compiler, | ||
Mode::ToolStd, // it's unclear what to use here, we're not building anything just doing a smoke test! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToolBootstrap
is the right choice if you don't build anything.
ref:
rust/src/bootstrap/src/core/build_steps/tool.rs
Lines 79 to 87 in 40116ad
match self.mode { | |
Mode::ToolRustc => { | |
builder.ensure(compile::Std::new(compiler, compiler.host)); | |
builder.ensure(compile::Rustc::new(compiler, target)); | |
} | |
Mode::ToolStd => builder.ensure(compile::Std::new(compiler, target)), | |
Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs | |
_ => panic!("unexpected Mode for tool build"), | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't work for stages > 0 though, because of this assertion:
rust/src/bootstrap/src/core/builder.rs
Lines 1461 to 1462 in e990cde
let use_snapshot = mode == Mode::ToolBootstrap; | |
assert!(!use_snapshot || stage == 0 || self.local_rebuild); |
// 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 host_compiler = builder.compiler(stage - 1, host); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized this is still not quite consistent with rustdoc. In rustdoc the stage adjustment is done in the tool
step, not the test
step. But the tool
steps are macro-generated for a bunch of tools and I don't want to do a change that could break clippy or so.^^
And arguably rustdoc is the weird one here; ./x.py build compiler/rustc --stage 0
and ./x.py build miri --stage 0
should be consistent (and they are with this PR); ./x.py build rustdoc --stage 0
is a NOP that does nothing.
e990cde
to
f4ff9c6
Compare
…he cargo-miri smoke test and Miri sysroot build
f4ff9c6
to
5b7b4b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes looks good to me, if you don't plan to do further changes you can r=me.
@bors rollup=iffy |
I think this is good to go. |
This comment has been minimized.
This comment has been minimized.
Miri isn't really different from regular rustc here though, so it would be rather strange if it needed special treatment... How does bootstrap usually provide the right libraries? I'm not sure if I'll be able to debug this by just throwing spaghetti at the CI runners until it sticks. This may need someone with a Windows machine to play around with the code. We now have two invocations of cargo-miri shortly after each other: first to build the sysroot, then to run
Is |
Hm, I also found something interesting in the clippy code. Sadly with no comments explaining it. Instead of calling I thought it would obviously be better to call |
The basic difference I can see between
The dependencies for
However, the dependencies for
|
@danielframpton thanks! So sounds to me like the staging mismatch I mentioned here and here is actually a problem on Windows. In rustc we are doing a stage increment in the Linux also has a bit of stage weirdness here in that we are indeed adding the stage2 compiler's lib paths when running the stage 1 Miri. I don't know why there's an off-by-1 here. But we did this with The latest patch adds |
This comment has been minimized.
This comment has been minimized.
FWIW it's also strange that on Windows the Miri binary is in |
877d577
to
294fa81
Compare
The I noticed that |
Oh, interesting. On Linux it's run from the tools-bin directory. So if we were running it from the stage1-tools-bin folder things would actually work? Very strange.
Hm... but the build steps for Miri and Clippy are generated by the same macro. Does clippy also have the off-by-1, where the clippy-driver.exe in stage1 needs the libs from stage2? |
@onur-ozkan I think we have something that works on Windows, though I don't yet fully understand what exactly causes the stage mismatch. Are you fine with landing b08b06e ? That's the only major difference compared to before (the other difference is just a bit more logging). (Don't approve right now, we still have the Windows builder in PR CI to double-check that this does indeed all work now.) |
This may be a staging difference, not a platform difference. I do most of my testing with rust/src/bootstrap/src/core/build_steps/tool.rs Lines 822 to 840 in 288daeb
So for stages other than 0 we do some adjustment of the path returned for where to find the tool. That adjustment is strangely also tied to whether @onur-ozkan you wrote that code in 6d99d6a. Is it possible that this copies clippy/miri to the wrong sysroot, i.e. not the one that has the libraries they need? Specifically, EDIT: I can confirm that indeed when I use |
294fa81
to
85d460e
Compare
Okay Windows CI is still happy. :) PR is ready to land again. |
Thanks a lot @danielframpton for the help! |
Those binaries copied from @bors r+ |
I'm pretty sure that's wrong. We usually copy e.g. from stage0-rustc to stage1/bin, so tools should also have such a stage increment I think. |
☀️ Test successful - checks-actions |
Finished benchmarking commit (871df0d): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 667.101s -> 667.778s (0.10%) |
Instead of basically doing
cargo run --manifest-path=<cargo-miri's manifest> -- miri
, let's invoke thecargo-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 #123177 by moving where we handle parallel_compiler.