diff options
Diffstat (limited to 'crates/ra_proc_macro_srv')
-rw-r--r-- | crates/ra_proc_macro_srv/src/dylib.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/crates/ra_proc_macro_srv/src/dylib.rs b/crates/ra_proc_macro_srv/src/dylib.rs index 476bc5c01..018cc7bb8 100644 --- a/crates/ra_proc_macro_srv/src/dylib.rs +++ b/crates/ra_proc_macro_srv/src/dylib.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use crate::{proc_macro::bridge, rustc_server::TokenStream}; | 3 | use crate::{proc_macro::bridge, rustc_server::TokenStream}; |
4 | use std::fs::File; | 4 | use std::fs::File; |
5 | use std::path::Path; | 5 | use std::path::{Path, PathBuf}; |
6 | 6 | ||
7 | use goblin::{mach::Mach, Object}; | 7 | use goblin::{mach::Mach, Object}; |
8 | use libloading::Library; | 8 | use libloading::Library; |
@@ -123,6 +123,9 @@ impl Expander { | |||
123 | .canonicalize() | 123 | .canonicalize() |
124 | .unwrap_or_else(|err| panic!("Cannot canonicalize {}: {:?}", lib.display(), err)); | 124 | .unwrap_or_else(|err| panic!("Cannot canonicalize {}: {:?}", lib.display(), err)); |
125 | 125 | ||
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 | |||
126 | let library = ProcMacroLibraryImpl::open(&lib).map_err(|e| e.to_string())?; | 129 | let library = ProcMacroLibraryImpl::open(&lib).map_err(|e| e.to_string())?; |
127 | 130 | ||
128 | Ok(Expander { inner: library }) | 131 | Ok(Expander { inner: library }) |
@@ -195,3 +198,17 @@ impl Expander { | |||
195 | .collect() | 198 | .collect() |
196 | } | 199 | } |
197 | } | 200 | } |
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 | } | ||