File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
crates/ra_proc_macro_srv/src Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
use crate :: { proc_macro:: bridge, rustc_server:: TokenStream } ;
4
4
use std:: fs:: File ;
5
- use std:: path:: Path ;
5
+ use std:: path:: { Path , PathBuf } ;
6
6
7
7
use goblin:: { mach:: Mach , Object } ;
8
8
use libloading:: Library ;
@@ -123,6 +123,9 @@ impl Expander {
123
123
. canonicalize ( )
124
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
129
let library = ProcMacroLibraryImpl :: open ( & lib) . map_err ( |e| e. to_string ( ) ) ?;
127
130
128
131
Ok ( Expander { inner : library } )
@@ -195,3 +198,17 @@ impl Expander {
195
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
+ }
You can’t perform that action at this time.
0 commit comments