@@ -141,17 +141,20 @@ pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap) -> LinkMet
141
141
return r;
142
142
}
143
143
144
- // The third parameter is for an env vars, used to set up the path for MSVC
145
- // to find its DLLs
144
+ // The third parameter is for env vars, used on windows to set up the
145
+ // path for MSVC to find its DLLs, and gcc to find its bundled
146
+ // toolchain
146
147
pub fn get_linker ( sess : & Session ) -> ( String , Command , Vec < ( OsString , OsString ) > ) {
148
+ let envs = vec ! [ ( "PATH" . into( ) , command_path( sess) ) ] ;
149
+
147
150
if let Some ( ref linker) = sess. opts . cg . linker {
148
- ( linker. clone ( ) , Command :: new ( linker) , vec ! [ ] )
151
+ ( linker. clone ( ) , Command :: new ( linker) , envs )
149
152
} else if sess. target . target . options . is_like_msvc {
150
153
let ( cmd, envs) = msvc_link_exe_cmd ( sess) ;
151
154
( "link.exe" . to_string ( ) , cmd, envs)
152
155
} else {
153
- ( sess. target . target . options . linker . clone ( ) ,
154
- Command :: new ( & sess . target . target . options . linker ) , vec ! [ ] )
156
+ let linker = & sess. target . target . options . linker ;
157
+ ( linker . clone ( ) , Command :: new ( & linker) , envs )
155
158
}
156
159
}
157
160
@@ -182,15 +185,14 @@ pub fn get_ar_prog(sess: &Session) -> String {
182
185
} )
183
186
}
184
187
185
- fn command_path ( sess : & Session , extra : Option < PathBuf > ) -> OsString {
188
+ fn command_path ( sess : & Session ) -> OsString {
186
189
// The compiler's sysroot often has some bundled tools, so add it to the
187
190
// PATH for the child.
188
191
let mut new_path = sess. host_filesearch ( PathKind :: All )
189
192
. get_tools_search_paths ( ) ;
190
193
if let Some ( path) = env:: var_os ( "PATH" ) {
191
194
new_path. extend ( env:: split_paths ( & path) ) ;
192
195
}
193
- new_path. extend ( extra) ;
194
196
env:: join_paths ( new_path) . unwrap ( )
195
197
}
196
198
@@ -451,7 +453,7 @@ fn archive_config<'a>(sess: &'a Session,
451
453
src : input. map ( |p| p. to_path_buf ( ) ) ,
452
454
lib_search_paths : archive_search_paths ( sess) ,
453
455
ar_prog : get_ar_prog ( sess) ,
454
- command_path : command_path ( sess, None ) ,
456
+ command_path : command_path ( sess) ,
455
457
}
456
458
}
457
459
@@ -727,7 +729,7 @@ fn link_natively(sess: &Session,
727
729
728
730
// The invocations of cc share some flags across platforms
729
731
let ( pname, mut cmd, envs) = get_linker ( sess) ;
730
- // This will set PATH on MSVC
732
+ // This will set PATH on windows
731
733
cmd. envs ( envs) ;
732
734
733
735
let root = sess. target_filesearch ( PathKind :: Native ) . get_lib_path ( ) ;
0 commit comments