Skip to content

Commit 5a5bba5

Browse files
committed
Copy dylib to temp directory
1 parent 3e24444 commit 5a5bba5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

crates/ra_proc_macro_srv/src/dylib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::{proc_macro::bridge, rustc_server::TokenStream};
44
use std::fs::File;
5-
use std::path::Path;
5+
use std::path::{Path, PathBuf};
66

77
use goblin::{mach::Mach, Object};
88
use libloading::Library;
@@ -123,6 +123,9 @@ impl Expander {
123123
.canonicalize()
124124
.unwrap_or_else(|err| panic!("Cannot canonicalize {}: {:?}", lib.display(), err));
125125

126+
// Copy the dylib to temp directory to prevent locking in Windows
127+
let lib = copy_to_temp_dir(&lib).map_err(|e| e.to_string())?;
128+
126129
let library = ProcMacroLibraryImpl::open(&lib).map_err(|e| e.to_string())?;
127130

128131
Ok(Expander { inner: library })
@@ -195,3 +198,17 @@ impl Expander {
195198
.collect()
196199
}
197200
}
201+
202+
fn copy_to_temp_dir(path: &Path) -> io::Result<PathBuf> {
203+
let mut to = std::env::temp_dir();
204+
let file_name = path.file_name().ok_or_else(|| {
205+
io::Error::new(
206+
io::ErrorKind::InvalidInput,
207+
format!("File path is invalid: {}", path.display()),
208+
)
209+
})?;
210+
211+
to.push(file_name);
212+
std::fs::copy(path, &to)?;
213+
Ok(to)
214+
}

0 commit comments

Comments
 (0)