Skip to content

Commit 7676171

Browse files
committed
wipe rustlib/rust before linking
When using `symlink_dir`, it first removes the existing link with `remove_dir`. However, if the path isn't a link and contains files, `remove_dir` fails with "DirectoryNotEmpty", which causes the symbolic linking to fail as well. We have this problem on "rustlib/rust" linking. This change fixes it by clearing the path before using `symlink_dir`. Signed-off-by: onur-ozkan <[email protected]>
1 parent e794b0f commit 7676171

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::collections::HashSet;
1111
use std::env;
1212
use std::ffi::OsStr;
1313
use std::fs;
14+
use std::fs::remove_dir_all;
1415
use std::io::prelude::*;
1516
use std::io::BufReader;
1617
use std::path::{Path, PathBuf};
@@ -1625,6 +1626,9 @@ impl Step for Sysroot {
16251626
let sysroot_lib_rustlib_src = sysroot.join("lib/rustlib/src");
16261627
t!(fs::create_dir_all(&sysroot_lib_rustlib_src));
16271628
let sysroot_lib_rustlib_src_rust = sysroot_lib_rustlib_src.join("rust");
1629+
// This path may already contain files, which can cause symbolic linking to fail.
1630+
// Make sure the path doesn't exist before linking it.
1631+
let _ = remove_dir_all(&sysroot_lib_rustlib_src_rust);
16281632
if let Err(e) = symlink_dir(&builder.config, &builder.src, &sysroot_lib_rustlib_src_rust) {
16291633
eprintln!(
16301634
"WARNING: creating symbolic link `{}` to `{}` failed with {}",
@@ -1643,6 +1647,9 @@ impl Step for Sysroot {
16431647
let sysroot_lib_rustlib_rustcsrc = sysroot.join("lib/rustlib/rustc-src");
16441648
t!(fs::create_dir_all(&sysroot_lib_rustlib_rustcsrc));
16451649
let sysroot_lib_rustlib_rustcsrc_rust = sysroot_lib_rustlib_rustcsrc.join("rust");
1650+
// This path may already contain files, which can cause symbolic linking to fail.
1651+
// Make sure the path doesn't exist before linking it.
1652+
let _ = remove_dir_all(&sysroot_lib_rustlib_rustcsrc_rust);
16461653
if let Err(e) =
16471654
symlink_dir(&builder.config, &builder.src, &sysroot_lib_rustlib_rustcsrc_rust)
16481655
{

0 commit comments

Comments
 (0)