@@ -12,7 +12,6 @@ use super::archive::{ArchiveBuilder, ArchiveConfig};
12
12
use super :: linker:: Linker ;
13
13
use super :: rpath:: RPathConfig ;
14
14
use super :: rpath;
15
- use super :: msvc;
16
15
use metadata:: METADATA_FILENAME ;
17
16
use rustc:: session:: config:: { self , NoDebugInfo , OutputFilenames , Input , OutputType } ;
18
17
use rustc:: session:: filesearch;
@@ -142,20 +141,41 @@ pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap) -> LinkMet
142
141
return r;
143
142
}
144
143
145
- // The third parameter is for an extra path to add to PATH for MSVC
146
- // cross linkers for host toolchain DLL dependencies
147
- pub fn get_linker ( sess : & Session ) -> ( String , Command , Option < PathBuf > ) {
144
+ // The third parameter is for an env vars, used to set up the path for MSVC
145
+ // to find its DLLs
146
+ pub fn get_linker ( sess : & Session ) -> ( String , Command , Vec < ( OsString , OsString ) > ) {
148
147
if let Some ( ref linker) = sess. opts . cg . linker {
149
- ( linker. clone ( ) , Command :: new ( linker) , None )
148
+ ( linker. clone ( ) , Command :: new ( linker) , vec ! [ ] )
150
149
} else if sess. target . target . options . is_like_msvc {
151
- let ( cmd, host ) = msvc :: link_exe_cmd ( sess) ;
152
- ( "link.exe" . to_string ( ) , cmd, host )
150
+ let ( cmd, envs ) = msvc_link_exe_cmd ( sess) ;
151
+ ( "link.exe" . to_string ( ) , cmd, envs )
153
152
} else {
154
153
( sess. target . target . options . linker . clone ( ) ,
155
- Command :: new ( & sess. target . target . options . linker ) , None )
154
+ Command :: new ( & sess. target . target . options . linker ) , vec ! [ ] )
156
155
}
157
156
}
158
157
158
+ #[ cfg( windows) ]
159
+ pub fn msvc_link_exe_cmd ( sess : & Session ) -> ( Command , Vec < ( OsString , OsString ) > ) {
160
+ use gcc:: windows_registry;
161
+
162
+ let target = & sess. opts . target_triple ;
163
+ let tool = windows_registry:: find_tool ( target, "link.exe" ) ;
164
+
165
+ if let Some ( tool) = tool {
166
+ let envs = tool. env ( ) . to_vec ( ) ;
167
+ ( tool. to_command ( ) , envs)
168
+ } else {
169
+ debug ! ( "Failed to locate linker." ) ;
170
+ ( Command :: new ( "link.exe" ) , vec ! [ ] )
171
+ }
172
+ }
173
+
174
+ #[ cfg( not( windows) ) ]
175
+ pub fn msvc_link_exe_cmd ( _sess : & Session ) -> ( Command , Vec < ( OsString , OsString ) > ) {
176
+ ( Command :: new ( "link.exe" ) , vec ! [ ] )
177
+ }
178
+
159
179
pub fn get_ar_prog ( sess : & Session ) -> String {
160
180
sess. opts . cg . ar . clone ( ) . unwrap_or_else ( || {
161
181
sess. target . target . options . ar . clone ( )
@@ -706,8 +726,9 @@ fn link_natively(sess: &Session,
706
726
let flavor = sess. linker_flavor ( ) ;
707
727
708
728
// The invocations of cc share some flags across platforms
709
- let ( pname, mut cmd, extra) = get_linker ( sess) ;
710
- cmd. env ( "PATH" , command_path ( sess, extra) ) ;
729
+ let ( pname, mut cmd, envs) = get_linker ( sess) ;
730
+ // This will set PATH on MSVC
731
+ cmd. envs ( envs) ;
711
732
712
733
let root = sess. target_filesearch ( PathKind :: Native ) . get_lib_path ( ) ;
713
734
if let Some ( args) = sess. target . target . options . pre_link_args . get ( & flavor) {
0 commit comments