Skip to content

Commit

Permalink
Only symlink certain directories on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Nov 9, 2023
1 parent 5b0c8fc commit c4d97f1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
27 changes: 21 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions src/splat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c4d97f1

Please sign in to comment.