@@ -136,14 +136,17 @@ pub fn build_link_meta<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
136
136
return r;
137
137
}
138
138
139
- pub fn get_linker ( sess : & Session ) -> ( String , Command ) {
139
+ // The third parameter is for an extra path to add to PATH for MSVC
140
+ // cross linkers for host toolchain DLL dependencies
141
+ pub fn get_linker ( sess : & Session ) -> ( String , Command , Option < PathBuf > ) {
140
142
if let Some ( ref linker) = sess. opts . cg . linker {
141
- ( linker. clone ( ) , Command :: new ( linker) )
143
+ ( linker. clone ( ) , Command :: new ( linker) , None )
142
144
} else if sess. target . target . options . is_like_msvc {
143
- ( "link.exe" . to_string ( ) , msvc:: link_exe_cmd ( sess) )
145
+ let ( cmd, host) = msvc:: link_exe_cmd ( sess) ;
146
+ ( "link.exe" . to_string ( ) , cmd, host)
144
147
} else {
145
148
( sess. target . target . options . linker . clone ( ) ,
146
- Command :: new ( & sess. target . target . options . linker ) )
149
+ Command :: new ( & sess. target . target . options . linker ) , None )
147
150
}
148
151
}
149
152
@@ -153,17 +156,15 @@ pub fn get_ar_prog(sess: &Session) -> String {
153
156
} )
154
157
}
155
158
156
- fn command_path ( sess : & Session ) -> OsString {
159
+ fn command_path ( sess : & Session , extra : Option < PathBuf > ) -> OsString {
157
160
// The compiler's sysroot often has some bundled tools, so add it to the
158
161
// PATH for the child.
159
162
let mut new_path = sess. host_filesearch ( PathKind :: All )
160
163
. get_tools_search_paths ( ) ;
161
164
if let Some ( path) = env:: var_os ( "PATH" ) {
162
165
new_path. extend ( env:: split_paths ( & path) ) ;
163
166
}
164
- if sess. target . target . options . is_like_msvc {
165
- new_path. extend ( msvc:: host_dll_path ( ) ) ;
166
- }
167
+ new_path. extend ( extra) ;
167
168
env:: join_paths ( new_path) . unwrap ( )
168
169
}
169
170
@@ -379,7 +380,7 @@ fn archive_config<'a>(sess: &'a Session,
379
380
src : input. map ( |p| p. to_path_buf ( ) ) ,
380
381
lib_search_paths : archive_search_paths ( sess) ,
381
382
ar_prog : get_ar_prog ( sess) ,
382
- command_path : command_path ( sess) ,
383
+ command_path : command_path ( sess, None ) ,
383
384
}
384
385
}
385
386
@@ -616,8 +617,8 @@ fn link_natively(sess: &Session,
616
617
info ! ( "preparing {:?} from {:?} to {:?}" , crate_type, objects, out_filename) ;
617
618
618
619
// The invocations of cc share some flags across platforms
619
- let ( pname, mut cmd) = get_linker ( sess) ;
620
- cmd. env ( "PATH" , command_path ( sess) ) ;
620
+ let ( pname, mut cmd, extra ) = get_linker ( sess) ;
621
+ cmd. env ( "PATH" , command_path ( sess, extra ) ) ;
621
622
622
623
let root = sess. target_filesearch ( PathKind :: Native ) . get_lib_path ( ) ;
623
624
cmd. args ( & sess. target . target . options . pre_link_args ) ;
@@ -682,10 +683,15 @@ fn link_natively(sess: &Session,
682
683
info ! ( "linker stdout:\n {}" , escape_string( & prog. stdout[ ..] ) ) ;
683
684
} ,
684
685
Err ( e) => {
685
- // Trying to diagnose https://github.com/rust-lang/rust/issues/33844
686
686
sess. struct_err ( & format ! ( "could not exec the linker `{}`: {}" , pname, e) )
687
687
. note ( & format ! ( "{:?}" , & cmd) )
688
688
. emit ( ) ;
689
+ if sess. target . target . options . is_like_msvc && e. kind ( ) == io:: ErrorKind :: NotFound {
690
+ sess. note_without_error ( "the msvc targets depend on the msvc linker \
691
+ but `link.exe` was not found") ;
692
+ sess. note_without_error ( "please ensure that VS 2013 or VS 2015 was installed \
693
+ with the Visual C++ option") ;
694
+ }
689
695
sess. abort_if_errors ( ) ;
690
696
}
691
697
}
0 commit comments