diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index f44fe4548a1db..34c25808a27db 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -408,7 +408,7 @@ impl Build { .strip_prefix(&config.initial_sysroot) .unwrap_or_else(|_| { panic!( - "Couldn’t resolve the initial relative libdir from {}", + "Couldn't resolve the initial relative libdir from {}", initial_target_dir.display() ) }) @@ -542,10 +542,16 @@ impl Build { if host.is_symlink() { // Left over from a previous build; overwrite it. // This matters if `build.build` has changed between invocations. - #[cfg(windows)] - t!(fs::remove_dir(&host)); - #[cfg(not(windows))] - t!(fs::remove_file(&host)); + // Try remove_dir first (for directory symlinks), then remove_file (for file symlinks). + // On Windows, there are two types of symlinks: directory and file symlinks. + // remove_dir only works on directory symlinks, remove_file only works on file symlinks. + if let Err(e) = fs::remove_dir(&host) { + if e.kind() == io::ErrorKind::NotADirectory { + t!(fs::remove_file(&host)); + } else { + panic!("failed to remove symlink: {e}"); + } + } } t!( symlink_dir(&build.config, &build_triple, &host),