Skip to content

fix sysroot issue which appears for ci downloaded rustc #104076

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

Merged
merged 1 commit into from
Nov 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,13 +1122,18 @@ impl Step for Sysroot {
fn run(self, builder: &Builder<'_>) -> Interned<PathBuf> {
let compiler = self.compiler;
let host_dir = builder.out.join(&compiler.host.triple);
let sysroot = if compiler.stage == 0 {
host_dir.join("stage0-sysroot")
} else if builder.download_rustc() {
host_dir.join("ci-rustc-sysroot")
} else {
host_dir.join(format!("stage{}", compiler.stage))

let sysroot_dir = |stage| {
if stage == 0 {
host_dir.join("stage0-sysroot")
} else if builder.download_rustc() && compiler.stage != builder.top_stage {
host_dir.join("ci-rustc-sysroot")
} else {
host_dir.join(format!("stage{}", stage))
}
};
let sysroot = sysroot_dir(compiler.stage);

let _ = fs::remove_dir_all(&sysroot);
t!(fs::create_dir_all(&sysroot));

Expand All @@ -1139,9 +1144,15 @@ impl Step for Sysroot {
"Cross-compiling is not yet supported with `download-rustc`",
);

// #102002, cleanup stage1 and stage0-sysroot folders when using download-rustc so people don't use old versions of the toolchain by accident.
let _ = fs::remove_dir_all(host_dir.join("stage1"));
let _ = fs::remove_dir_all(host_dir.join("stage0-sysroot"));
// #102002, cleanup old toolchain folders when using download-rustc so people don't use them by accident.
for stage in 0..=2 {
if stage != compiler.stage {
let dir = sysroot_dir(stage);
if !dir.ends_with("ci-rustc-sysroot") {
let _ = fs::remove_dir_all(dir);
}
}
}

// Copy the compiler into the correct sysroot.
let ci_rustc_dir =
Expand Down