diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 487132683e920..aa5328e87d040 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -105,32 +105,37 @@ pub fn source_root() -> PathBuf { env_var("SOURCE_ROOT").into() } -/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix. -#[cfg(target_family = "windows")] +/// Creates a new symlink to a path on the filesystem (only available for Unix because symlink +/// creation is a priviledged operation on Windows; see +/// ). pub fn create_symlink, Q: AsRef>(original: P, link: Q) { - if link.as_ref().exists() { - std::fs::remove_dir(link.as_ref()).unwrap(); + #[cfg(target_family = "windows")] + { + panic!( + "symlink is an priviledged operation on Windows that is not normally enabled on user machines" + ); } - use std::os::windows::fs; - fs::symlink_file(original.as_ref(), link.as_ref()).expect(&format!( - "failed to create symlink {:?} for {:?}", - link.as_ref().display(), - original.as_ref().display(), - )); -} -/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix. -#[cfg(target_family = "unix")] -pub fn create_symlink, Q: AsRef>(original: P, link: Q) { - if link.as_ref().exists() { - std::fs::remove_dir(link.as_ref()).unwrap(); + #[cfg(target_family = "unix")] + { + let link = link.as_ref(); + if link.exists() { + std::fs::remove_dir(link) + .expect(&format!("failed to remove existing symlink: {}", link.display())); + } + + use std::os::unix::fs; + fs::symlink(original.as_ref(), link).expect(&format!( + "failed to create symlink {} for {}", + link.display(), + original.as_ref().display(), + )); + } + + #[cfg(not(any(target_family = "unix", target_family = "windows")))] + { + unimplemented!(); } - use std::os::unix::fs; - fs::symlink(original.as_ref(), link.as_ref()).expect(&format!( - "failed to create symlink {:?} for {:?}", - link.as_ref().display(), - original.as_ref().display(), - )); } /// Construct the static library name based on the platform. diff --git a/tests/run-make/symlinked-extern/rmake.rs b/tests/run-make/symlinked-extern/rmake.rs index 98f69aefbe622..e8c3748d462aa 100644 --- a/tests/run-make/symlinked-extern/rmake.rs +++ b/tests/run-make/symlinked-extern/rmake.rs @@ -9,6 +9,7 @@ // can result in successful compilation. //@ ignore-cross-compile +//@ ignore-windows (symlink creation is priviledged on Windows) use run_make_support::{create_symlink, cwd, fs_wrapper, rustc}; diff --git a/tests/run-make/symlinked-libraries/rmake.rs b/tests/run-make/symlinked-libraries/rmake.rs index 3f02f19ccd5b0..deb83bfddc4f3 100644 --- a/tests/run-make/symlinked-libraries/rmake.rs +++ b/tests/run-make/symlinked-libraries/rmake.rs @@ -6,6 +6,7 @@ // See https://github.com/rust-lang/rust/issues/12459 //@ ignore-cross-compile +//@ ignore-windows (symlink creation is priviledged on Windows) use run_make_support::{create_symlink, dynamic_lib_name, fs_wrapper, rustc}; diff --git a/tests/run-make/symlinked-rlib/rmake.rs b/tests/run-make/symlinked-rlib/rmake.rs index 3759ca25928a1..59a916bf1aef3 100644 --- a/tests/run-make/symlinked-rlib/rmake.rs +++ b/tests/run-make/symlinked-rlib/rmake.rs @@ -6,6 +6,7 @@ // See https://github.com/rust-lang/rust/pull/32828 //@ ignore-cross-compile +//@ ignore-windows (symlink creation is priviledged on Windows) use run_make_support::{create_symlink, cwd, rustc};