Skip to content

Commit f707e72

Browse files
committed
Fix spurious error when running build --stage 2 compiler/rustc
rust-lang#89759 introduced a panic: ``` Assembling stage3 compiler (x86_64-apple-darwin) thread 'main' panicked at 'fs::read(stamp) failed with No such file or directory (os error 2) ("/Users/user/rust2/build/x86_64-apple-darwin/stage2-rustc/x86_64-apple-darwin/release/.librustc.stamp")', src/bootstrap/lib.rs:1296:24 ``` This wasn't actually a bug in that PR - the problem was that `x build --stage 3` is broken, and has been for quite some time, even ignoring the stamp file error: ``` thread 'main' panicked at 'src.symlink_metadata() failed with No such file or directory (os error 2) ("failed to determine metadata of /home/jnelson/rust-lang/rust/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/rustc-main")', src/bootstrap/lib.rs:1414:24 ``` It needs to take into account whether the artifacts from stage1 are being reused, rather than blindly assuming rustc will be recompiled. Doing so is kind of annoying, because it requires knowing the target the compiler is being built for. Instead, just revert to the old behavior of `build --stage 2 compiler/rustc`, which avoids trying to create the sysroot in the first place.
1 parent 17355a3 commit f707e72

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/bootstrap/builder/tests.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,10 @@ mod dist {
501501
std!(A => C, stage = 2),
502502
]
503503
);
504-
assert_eq!(builder.cache.all::<compile::Assemble>().len(), 5);
504+
// Theoretically this should be 5, the same as `compile::Rustc`.
505+
// Unfortunately, the sysroot for the stage 3 compiler is broken; see #90244.
506+
// Instead we only generate the sysroot for non-stage2 build compilers.
507+
assert_eq!(builder.cache.all::<compile::Assemble>().len(), 3);
505508
assert_eq!(
506509
first(builder.cache.all::<compile::Rustc>()),
507510
&[

src/bootstrap/compile.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,30 @@ impl Step for Assemble {
11041104
}
11051105

11061106
fn make_run(run: RunConfig<'_>) {
1107-
run.builder.ensure(Assemble {
1108-
target_compiler: run.builder.compiler(run.builder.top_stage + 1, run.target),
1109-
});
1107+
// Trying to actually create the sysroot for stage 2 is tricky, because everywhere in
1108+
// bootstrap that touches self.rustc or self.cargo_out suddenly needs to know whether those
1109+
// artifacts actually exist or whether we're reusing the ones from stage 1. Instead, just
1110+
// build the artifacts, like we used to do before `compiler/rustc` implied assembling the
1111+
// compiler.
1112+
//
1113+
// When using full-bootstrap, we never reuse the artifacts from stage 1, so we don't have
1114+
// any issues.
1115+
//
1116+
// NOTE: Anywhere in bootstrap that calls `builder.compiler` has the side effect of running
1117+
// `Assemble`. In those cases, this workaround in `make_run` doesn't help, we'll still hit a
1118+
// panic (see #90224). In practice, that's probably ok: nothing currently uses the stage 2
1119+
// sysroot.
1120+
if run.builder.top_stage >= 2 && !run.builder.config.full_bootstrap {
1121+
let build_compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.build);
1122+
run.builder.ensure(Rustc {
1123+
compiler: build_compiler,
1124+
target: run.target,
1125+
crates: Default::default(),
1126+
});
1127+
return;
1128+
}
1129+
let target_compiler = Compiler { stage: run.builder.top_stage + 1, host: run.target };
1130+
run.builder.ensure(Assemble { target_compiler });
11101131
}
11111132

11121133
/// Prepare a new compiler from the artifacts in `stage`

0 commit comments

Comments
 (0)