@@ -158,61 +158,6 @@ impl<'a> Toolchain<'a> {
158
158
== Some ( true )
159
159
}
160
160
161
- // Custom and Distributable. Installed only.
162
- pub fn set_ldpath ( & self , cmd : & mut Command ) {
163
- let mut new_path = vec ! [ self . path. join( "lib" ) ] ;
164
-
165
- #[ cfg( not( target_os = "macos" ) ) ]
166
- mod sysenv {
167
- pub const LOADER_PATH : & str = "LD_LIBRARY_PATH" ;
168
- }
169
- #[ cfg( target_os = "macos" ) ]
170
- mod sysenv {
171
- // When loading and linking a dynamic library or bundle, dlopen
172
- // searches in LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, PWD, and
173
- // DYLD_FALLBACK_LIBRARY_PATH.
174
- // In the Mach-O format, a dynamic library has an "install path."
175
- // Clients linking against the library record this path, and the
176
- // dynamic linker, dyld, uses it to locate the library.
177
- // dyld searches DYLD_LIBRARY_PATH *before* the install path.
178
- // dyld searches DYLD_FALLBACK_LIBRARY_PATH only if it cannot
179
- // find the library in the install path.
180
- // Setting DYLD_LIBRARY_PATH can easily have unintended
181
- // consequences.
182
- pub const LOADER_PATH : & str = "DYLD_FALLBACK_LIBRARY_PATH" ;
183
- }
184
- if cfg ! ( target_os = "macos" )
185
- && env:: var_os ( sysenv:: LOADER_PATH )
186
- . filter ( |x| x. len ( ) > 0 )
187
- . is_none ( )
188
- {
189
- // These are the defaults when DYLD_FALLBACK_LIBRARY_PATH isn't
190
- // set or set to an empty string. Since we are explicitly setting
191
- // the value, make sure the defaults still work.
192
- if let Some ( home) = env:: var_os ( "HOME" ) {
193
- new_path. push ( PathBuf :: from ( home) . join ( "lib" ) ) ;
194
- }
195
- new_path. push ( PathBuf :: from ( "/usr/local/lib" ) ) ;
196
- new_path. push ( PathBuf :: from ( "/usr/lib" ) ) ;
197
- }
198
-
199
- env_var:: prepend_path ( sysenv:: LOADER_PATH , new_path, cmd) ;
200
-
201
- // Prepend CARGO_HOME/bin to the PATH variable so that we're sure to run
202
- // cargo/rustc via the proxy bins. There is no fallback case for if the
203
- // proxy bins don't exist. We'll just be running whatever happens to
204
- // be on the PATH.
205
- let mut path_entries = vec ! [ ] ;
206
- if let Ok ( cargo_home) = utils:: cargo_home ( ) {
207
- path_entries. push ( cargo_home. join ( "bin" ) ) ;
208
- }
209
-
210
- if cfg ! ( target_os = "windows" ) {
211
- path_entries. push ( self . path . join ( "bin" ) ) ;
212
- }
213
-
214
- env_var:: prepend_path ( "PATH" , path_entries, cmd) ;
215
- }
216
161
// Custom and Distributable. Installed only.
217
162
pub fn doc_path ( & self , relative : & str ) -> Result < PathBuf > {
218
163
self . verify ( ) ?;
@@ -252,15 +197,15 @@ impl<'a> Toolchain<'a> {
252
197
}
253
198
// Distributable and Custom. Installed only.
254
199
pub fn rustc_version ( & self ) -> String {
255
- if self . exists ( ) {
200
+ if let Ok ( installed ) = self . as_installed_common ( ) {
256
201
let rustc_path = self . binary_file ( "rustc" ) ;
257
202
if utils:: is_file ( & rustc_path) {
258
203
let mut cmd = Command :: new ( & rustc_path) ;
259
204
cmd. arg ( "--version" ) ;
260
205
cmd. stdin ( Stdio :: null ( ) ) ;
261
206
cmd. stdout ( Stdio :: piped ( ) ) ;
262
207
cmd. stderr ( Stdio :: piped ( ) ) ;
263
- self . set_ldpath ( & mut cmd) ;
208
+ installed . set_ldpath ( & mut cmd) ;
264
209
265
210
// some toolchains are faulty with some combinations of platforms and
266
211
// may fail to launch but also to timely terminate.
@@ -345,7 +290,7 @@ impl<'a> InstalledCommonToolchain<'a> {
345
290
}
346
291
347
292
fn set_env ( & self , cmd : & mut Command ) {
348
- self . 0 . set_ldpath ( cmd) ;
293
+ self . set_ldpath ( cmd) ;
349
294
350
295
// Because rustup and cargo use slightly different
351
296
// definitions of cargo home (rustup doesn't read HOME on
@@ -360,6 +305,61 @@ impl<'a> InstalledCommonToolchain<'a> {
360
305
cmd. env ( "RUSTUP_TOOLCHAIN" , & self . 0 . name ) ;
361
306
cmd. env ( "RUSTUP_HOME" , & self . 0 . cfg . rustup_dir ) ;
362
307
}
308
+
309
+ fn set_ldpath ( & self , cmd : & mut Command ) {
310
+ let mut new_path = vec ! [ self . 0 . path. join( "lib" ) ] ;
311
+
312
+ #[ cfg( not( target_os = "macos" ) ) ]
313
+ mod sysenv {
314
+ pub const LOADER_PATH : & str = "LD_LIBRARY_PATH" ;
315
+ }
316
+ #[ cfg( target_os = "macos" ) ]
317
+ mod sysenv {
318
+ // When loading and linking a dynamic library or bundle, dlopen
319
+ // searches in LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, PWD, and
320
+ // DYLD_FALLBACK_LIBRARY_PATH.
321
+ // In the Mach-O format, a dynamic library has an "install path."
322
+ // Clients linking against the library record this path, and the
323
+ // dynamic linker, dyld, uses it to locate the library.
324
+ // dyld searches DYLD_LIBRARY_PATH *before* the install path.
325
+ // dyld searches DYLD_FALLBACK_LIBRARY_PATH only if it cannot
326
+ // find the library in the install path.
327
+ // Setting DYLD_LIBRARY_PATH can easily have unintended
328
+ // consequences.
329
+ pub const LOADER_PATH : & str = "DYLD_FALLBACK_LIBRARY_PATH" ;
330
+ }
331
+ if cfg ! ( target_os = "macos" )
332
+ && env:: var_os ( sysenv:: LOADER_PATH )
333
+ . filter ( |x| x. len ( ) > 0 )
334
+ . is_none ( )
335
+ {
336
+ // These are the defaults when DYLD_FALLBACK_LIBRARY_PATH isn't
337
+ // set or set to an empty string. Since we are explicitly setting
338
+ // the value, make sure the defaults still work.
339
+ if let Some ( home) = env:: var_os ( "HOME" ) {
340
+ new_path. push ( PathBuf :: from ( home) . join ( "lib" ) ) ;
341
+ }
342
+ new_path. push ( PathBuf :: from ( "/usr/local/lib" ) ) ;
343
+ new_path. push ( PathBuf :: from ( "/usr/lib" ) ) ;
344
+ }
345
+
346
+ env_var:: prepend_path ( sysenv:: LOADER_PATH , new_path, cmd) ;
347
+
348
+ // Prepend CARGO_HOME/bin to the PATH variable so that we're sure to run
349
+ // cargo/rustc via the proxy bins. There is no fallback case for if the
350
+ // proxy bins don't exist. We'll just be running whatever happens to
351
+ // be on the PATH.
352
+ let mut path_entries = vec ! [ ] ;
353
+ if let Ok ( cargo_home) = utils:: cargo_home ( ) {
354
+ path_entries. push ( cargo_home. join ( "bin" ) ) ;
355
+ }
356
+
357
+ if cfg ! ( target_os = "windows" ) {
358
+ path_entries. push ( self . 0 . path . join ( "bin" ) ) ;
359
+ }
360
+
361
+ env_var:: prepend_path ( "PATH" , path_entries, cmd) ;
362
+ }
363
363
}
364
364
365
365
/// Newtype to facilitate splitting out custom-toolchain specific code.
0 commit comments