Skip to content

Commit b9fdc6b

Browse files
authored
Rollup merge of #144252 - Kobzol:rmeta-sysroot, r=jieyouxu
Do not copy .rmeta files into the sysroot of the build compiler during check of rustc/std Before, when bootstrap did a check build of rustc stage N (with a build compiler that was stage N-1), it automatically copied the resulting `.rmeta` artifacts into the sysroot of the stage N-1 build compiler, so that stage N `rustc_private` tools such as `miri` could be compiled using the stage N-1 build compiler. This has a number of issues: - It was done unconditionally, even if no `rustc_private` tools were actually built. - If we did a check and a build of the same stage compiler in the same bootstrap invocation, the generated rmeta and rlib files could clash. This is also why you can see that `check::Std` actually doesn't copy the artifacts anymore (which forced us to build std instead of just checking it in a bunch of `Check` steps). - It was polluting the sysroot of the build compiler. This is especially annoying for the stage 0 compiler, because we are forced to create an artificial sysroot for it, so that we can copy new stuff into it. - It was very implicit in bootstrap. Based on suggestions by ```@cuviper``` and ```@bjorn3,``` I tried to change how this behaves. Instead of copying the rmeta artifacts into the sysroot of the build compiler (from where they would be loaded implicitly), they are now stored in a separate transient bootstrap build directory, and they are then explicitly passed *only* when checking `rustc_private` tools using the `-L` flag. The flags are passed out-of-band through our rustc wrapper, to avoid invalidating the build cache. This is the first commit. The second commit does the same for std. For a few months, we used to build std instead of just checking it when doing a cross-compile check of something that required std, this now fixes it. There is still the previous ordering requirement though, that `check::Std` has to be executed as the last check step, or rather nothing that requires checked std should be executed *after* it, because it will run into rmeta/rlib duplications (https://github.com/rust-lang/rust/blob/4fa90ef7996f891f7f1e126411e5d75afe64accf/src/bootstrap/src/core/builder/mod.rs#L1066). I tried to fix in this PR, but it quickly runs into the fact that building things currently copies *rlib* artifacts into the build compiler sysroot. I want to fix that as one of the next steps. After we get rid of all the copies (or rather, we only do the copies for dist/stage2+ and do not copy anything into the stage0 compiler's sysroot), we could hopefully finally get rid of `stage0-sysroot`. Based on my local tests, this seems to be working fine. If it works on CI, and we don't run into other issues after merging it, I'd like to do the same also for rlib artifacts generated during `x build`. r? ```@jieyouxu```
2 parents 0671b2f + 533ecdb commit b9fdc6b

File tree

5 files changed

+335
-88
lines changed

5 files changed

+335
-88
lines changed

src/bootstrap/src/bin/rustc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@ fn main() {
179179
}
180180
}
181181

182+
// Here we pass additional paths that essentially act as a sysroot.
183+
// These are used to load rustc crates (e.g. `extern crate rustc_ast;`)
184+
// for rustc_private tools, so that we do not have to copy them into the
185+
// actual sysroot of the compiler that builds the tool.
186+
if let Ok(dirs) = env::var("RUSTC_ADDITIONAL_SYSROOT_PATHS") {
187+
for dir in dirs.split(",") {
188+
cmd.arg(format!("-L{dir}"));
189+
}
190+
}
191+
182192
// Force all crates compiled by this compiler to (a) be unstable and (b)
183193
// allow the `rustc_private` feature to link to other unstable crates
184194
// also in the sysroot. We also do this for host crates, since those

0 commit comments

Comments
 (0)