@@ -313,8 +313,8 @@ impl Config {
313
313
}
314
314
315
315
pub fn target_supported ( & self ) -> bool {
316
- let target = env:: var ( "TARGET" ) . unwrap_or_default ( ) ;
317
- let host = env:: var ( "HOST" ) . unwrap_or_default ( ) ;
316
+ let target = env:: var_os ( "TARGET" ) . unwrap_or_default ( ) ;
317
+ let host = env:: var_os ( "HOST" ) . unwrap_or_default ( ) ;
318
318
319
319
// Only use pkg-config in host == target situations by default (allowing an
320
320
// override).
@@ -326,13 +326,13 @@ impl Config {
326
326
// a wrapper script that sets up platform-specific prefixes.
327
327
match self . targetted_env_var ( "PKG_CONFIG_ALLOW_CROSS" ) {
328
328
// don't use pkg-config if explicitly disabled
329
- Ok ( ref val) if val == "0" => false ,
330
- Ok ( _) => true ,
331
- Err ( _ ) => {
329
+ Some ( ref val) if val == "0" => false ,
330
+ Some ( _) => true ,
331
+ None => {
332
332
// if not disabled, and pkg-config is customized,
333
333
// then assume it's prepared for cross-compilation
334
- self . targetted_env_var ( "PKG_CONFIG" ) . is_ok ( )
335
- || self . targetted_env_var ( "PKG_CONFIG_SYSROOT_DIR" ) . is_ok ( )
334
+ self . targetted_env_var ( "PKG_CONFIG" ) . is_some ( )
335
+ || self . targetted_env_var ( "PKG_CONFIG_SYSROOT_DIR" ) . is_some ( )
336
336
}
337
337
}
338
338
}
@@ -343,26 +343,27 @@ impl Config {
343
343
get_variable ( package, variable) . map_err ( |e| e. to_string ( ) )
344
344
}
345
345
346
- fn targetted_env_var ( & self , var_base : & str ) -> Result < String , env:: VarError > {
347
- if let Ok ( target) = env:: var ( "TARGET" ) {
348
- let host = env:: var ( "HOST" ) ?;
349
- let kind = if host == target { "HOST" } else { "TARGET" } ;
350
- let target_u = target. replace ( "-" , "_" ) ;
351
-
352
- self . env_var ( & format ! ( "{}_{}" , var_base, target) )
353
- . or_else ( |_| self . env_var ( & format ! ( "{}_{}" , var_base, target_u) ) )
354
- . or_else ( |_| self . env_var ( & format ! ( "{}_{}" , kind, var_base) ) )
355
- . or_else ( |_| self . env_var ( var_base) )
356
- } else {
357
- self . env_var ( var_base)
358
- }
359
- }
346
+ fn targetted_env_var ( & self , var_base : & str ) -> Option < OsString > {
347
+ match ( env:: var ( "TARGET" ) , env:: var ( "HOST" ) ) {
348
+ ( Ok ( target) , Ok ( host) ) => {
349
+ let kind = if host == target { "HOST" } else { "TARGET" } ;
350
+ let target_u = target. replace ( "-" , "_" ) ;
360
351
361
- fn env_var ( & self , name : & str ) -> Result < String , env:: VarError > {
362
- if self . env_metadata {
363
- println ! ( "cargo:rerun-if-env-changed={}" , name) ;
352
+ self . env_var_os ( & format ! ( "{}_{}" , var_base, target) )
353
+ . or_else ( || self . env_var_os ( & format ! ( "{}_{}" , var_base, target_u) ) )
354
+ . or_else ( || self . env_var_os ( & format ! ( "{}_{}" , kind, var_base) ) )
355
+ . or_else ( || self . env_var_os ( var_base) )
356
+ }
357
+ ( Err ( env:: VarError :: NotPresent ) , _) | ( _, Err ( env:: VarError :: NotPresent ) ) => {
358
+ self . env_var_os ( var_base)
359
+ }
360
+ ( Err ( env:: VarError :: NotUnicode ( s) ) , _) | ( _, Err ( env:: VarError :: NotUnicode ( s) ) ) => {
361
+ panic ! (
362
+ "HOST or TARGET environment variable is not valid unicode: {:?}" ,
363
+ s
364
+ )
365
+ }
364
366
}
365
- env:: var ( name)
366
367
}
367
368
368
369
fn env_var_os ( & self , name : & str ) -> Option < OsString > {
@@ -378,21 +379,21 @@ impl Config {
378
379
379
380
fn command ( & self , name : & str , args : & [ & str ] ) -> Command {
380
381
let exe = self
381
- . env_var ( "PKG_CONFIG" )
382
- . unwrap_or_else ( |_| String :: from ( "pkg-config" ) ) ;
382
+ . env_var_os ( "PKG_CONFIG" )
383
+ . unwrap_or_else ( || OsString :: from ( "pkg-config" ) ) ;
383
384
let mut cmd = Command :: new ( exe) ;
384
385
if self . is_static ( name) {
385
386
cmd. arg ( "--static" ) ;
386
387
}
387
388
cmd. args ( args) . args ( & self . extra_args ) ;
388
389
389
- if let Ok ( value) = self . targetted_env_var ( "PKG_CONFIG_PATH" ) {
390
+ if let Some ( value) = self . targetted_env_var ( "PKG_CONFIG_PATH" ) {
390
391
cmd. env ( "PKG_CONFIG_PATH" , value) ;
391
392
}
392
- if let Ok ( value) = self . targetted_env_var ( "PKG_CONFIG_LIBDIR" ) {
393
+ if let Some ( value) = self . targetted_env_var ( "PKG_CONFIG_LIBDIR" ) {
393
394
cmd. env ( "PKG_CONFIG_LIBDIR" , value) ;
394
395
}
395
- if let Ok ( value) = self . targetted_env_var ( "PKG_CONFIG_SYSROOT_DIR" ) {
396
+ if let Some ( value) = self . targetted_env_var ( "PKG_CONFIG_SYSROOT_DIR" ) {
396
397
cmd. env ( "PKG_CONFIG_SYSROOT_DIR" , value) ;
397
398
}
398
399
if self . print_system_libs {
0 commit comments