@@ -12,7 +12,6 @@ use super::archive::{ArchiveBuilder, ArchiveConfig};
1212use super :: linker:: Linker ;
1313use super :: rpath:: RPathConfig ;
1414use super :: rpath;
15- use super :: msvc;
1615use metadata:: METADATA_FILENAME ;
1716use rustc:: session:: config:: { self , NoDebugInfo , OutputFilenames , Input , OutputType } ;
1817use rustc:: session:: filesearch;
@@ -142,20 +141,41 @@ pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap) -> LinkMet
142141 return r;
143142}
144143
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 ) > ) {
148147 if let Some ( ref linker) = sess. opts . cg . linker {
149- ( linker. clone ( ) , Command :: new ( linker) , None )
148+ ( linker. clone ( ) , Command :: new ( linker) , vec ! [ ] )
150149 } 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 )
153152 } else {
154153 ( sess. target . target . options . linker . clone ( ) ,
155- Command :: new ( & sess. target . target . options . linker ) , None )
154+ Command :: new ( & sess. target . target . options . linker ) , vec ! [ ] )
156155 }
157156}
158157
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+
159179pub fn get_ar_prog ( sess : & Session ) -> String {
160180 sess. opts . cg . ar . clone ( ) . unwrap_or_else ( || {
161181 sess. target . target . options . ar . clone ( )
@@ -706,8 +726,9 @@ fn link_natively(sess: &Session,
706726 let flavor = sess. linker_flavor ( ) ;
707727
708728 // 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) ;
711732
712733 let root = sess. target_filesearch ( PathKind :: Native ) . get_lib_path ( ) ;
713734 if let Some ( args) = sess. target . target . options . pre_link_args . get ( & flavor) {
0 commit comments