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 22
33use crate :: { proc_macro:: bridge, rustc_server:: TokenStream } ;
44use std:: fs:: File ;
5- use std:: path:: Path ;
5+ use std:: path:: { Path , PathBuf } ;
66
77use goblin:: { mach:: Mach , Object } ;
88use 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+ }
You can’t perform that action at this time.
0 commit comments