11
11
use std:: ffi:: OsString ;
12
12
use std:: path:: { Path , PathBuf } ;
13
13
use std:: process:: Command ;
14
+ use std:: fs;
14
15
15
16
use rustc_back:: archive;
16
17
use session:: Session ;
@@ -25,6 +26,7 @@ use session::config;
25
26
/// MSVC linker (e.g. `link.exe`) is being used.
26
27
pub trait Linker {
27
28
fn link_dylib ( & mut self , lib : & str ) ;
29
+ fn link_rust_dylib ( & mut self , lib : & str , path : & Path ) ;
28
30
fn link_framework ( & mut self , framework : & str ) ;
29
31
fn link_staticlib ( & mut self , lib : & str ) ;
30
32
fn link_rlib ( & mut self , lib : & Path ) ;
@@ -67,6 +69,10 @@ impl<'a> Linker for GnuLinker<'a> {
67
69
fn position_independent_executable ( & mut self ) { self . cmd . arg ( "-pie" ) ; }
68
70
fn args ( & mut self , args : & [ String ] ) { self . cmd . args ( args) ; }
69
71
72
+ fn link_rust_dylib ( & mut self , lib : & str , _path : & Path ) {
73
+ self . cmd . arg ( "-l" ) . arg ( lib) ;
74
+ }
75
+
70
76
fn link_framework ( & mut self , framework : & str ) {
71
77
self . cmd . arg ( "-framework" ) . arg ( framework) ;
72
78
}
@@ -189,6 +195,18 @@ impl<'a> Linker for MsvcLinker<'a> {
189
195
fn link_dylib ( & mut self , lib : & str ) {
190
196
self . cmd . arg ( & format ! ( "{}.lib" , lib) ) ;
191
197
}
198
+
199
+ fn link_rust_dylib ( & mut self , lib : & str , path : & Path ) {
200
+ // When producing a dll, the MSVC linker may not actually emit a
201
+ // `foo.lib` file if the dll doesn't actually export any symbols, so we
202
+ // check to see if the file is there and just omit linking to it if it's
203
+ // not present.
204
+ let name = format ! ( "{}.lib" , lib) ;
205
+ if fs:: metadata ( & path. join ( & name) ) . is_ok ( ) {
206
+ self . cmd . arg ( name) ;
207
+ }
208
+ }
209
+
192
210
fn link_staticlib ( & mut self , lib : & str ) {
193
211
self . cmd . arg ( & format ! ( "{}.lib" , lib) ) ;
194
212
}
0 commit comments