diff --git a/src/lib.rs b/src/lib.rs index 7647acb..bb62368 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -746,13 +746,28 @@ fn symlink(original: &str, link: &Path) -> Result<(), Error> { } #[cfg(windows)] -fn symlink(original: &str, link: &Path) -> Result<(), Error> { - if std::fs::metadata(original)?.is_dir() { - std::os::windows::fs::symlink_dir(original, link) - } else { - std::os::windows::fs::symlink_file(original, link) +#[inline] +fn symlink(_original: &str, _link: &Path) -> Result<(), Error> { + Ok(()) +} + +#[inline] +fn symlink_on_windows_too(original: &str, link: &Path) -> Result<(), Error> { + #[cfg(unix)] + { + symlink(original, link) + } + + #[cfg(windows)] + { + let full_path = link.parent().unwrap().join(original); + if full_path.is_dir() { + std::os::windows::fs::symlink_dir(original, link) + .with_context(|| format!("unable to symlink from {link} to {original}")) + } else { + Ok(()) + } } - .with_context(|| format!("unable to symlink from {link} to {original}")) } #[cfg(test)] diff --git a/src/splat.rs b/src/splat.rs index 7ad3f7d..eeb8304 100644 --- a/src/splat.rs +++ b/src/splat.rs @@ -677,7 +677,7 @@ pub(crate) fn splat( // Multiple architectures both have a lib dir, // but we only need to create this symlink once. if !versioned_linkname.exists() { - symlink(".", &versioned_linkname)?; + crate::symlink_on_windows_too(".", &versioned_linkname)?; } // https://github.com/llvm/llvm-project/blob/release/14.x/clang/lib/Driver/ToolChains/MSVC.cpp#L1102 @@ -698,7 +698,7 @@ pub(crate) fn splat( // Desktop and Store variants both have an include dir, // but we only need to create this symlink once. if !versioned_linkname.exists() { - symlink(".", &versioned_linkname)?; + crate::symlink_on_windows_too(".", &versioned_linkname)?; } // https://github.com/llvm/llvm-project/blob/release/14.x/clang/lib/Driver/ToolChains/MSVC.cpp#L1340-L1346