@@ -126,7 +126,7 @@ pub struct Build {
126
126
warnings_into_errors : bool ,
127
127
warnings : Option < bool > ,
128
128
extra_warnings : Option < bool > ,
129
- env_cache : Arc < Mutex < HashMap < String , Option < String > > > > ,
129
+ env_cache : Arc < Mutex < HashMap < String , Option < Arc < str > > > > > ,
130
130
apple_sdk_root_cache : Arc < Mutex < HashMap < String , OsString > > > ,
131
131
emit_rerun_if_env_changed : bool ,
132
132
}
@@ -1605,9 +1605,8 @@ impl Build {
1605
1605
Some ( true ) => "-MT" ,
1606
1606
Some ( false ) => "-MD" ,
1607
1607
None => {
1608
- let features = self
1609
- . getenv ( "CARGO_CFG_TARGET_FEATURE" )
1610
- . unwrap_or ( String :: new ( ) ) ;
1608
+ let features = self . getenv ( "CARGO_CFG_TARGET_FEATURE" ) ;
1609
+ let features = features. as_deref ( ) . unwrap_or_default ( ) ;
1611
1610
if features. contains ( "crt-static" ) {
1612
1611
"-MT"
1613
1612
} else {
@@ -1827,9 +1826,8 @@ impl Build {
1827
1826
}
1828
1827
1829
1828
if self . static_flag . is_none ( ) {
1830
- let features = self
1831
- . getenv ( "CARGO_CFG_TARGET_FEATURE" )
1832
- . unwrap_or ( String :: new ( ) ) ;
1829
+ let features = self . getenv ( "CARGO_CFG_TARGET_FEATURE" ) ;
1830
+ let features = features. as_deref ( ) . unwrap_or_default ( ) ;
1833
1831
if features. contains ( "crt-static" ) {
1834
1832
cmd. args . push ( "-static" . into ( ) ) ;
1835
1833
}
@@ -2381,6 +2379,7 @@ impl Build {
2381
2379
}
2382
2380
let host = self . get_host ( ) ?;
2383
2381
let target = self . get_target ( ) ?;
2382
+ let target = & * target;
2384
2383
let ( env, msvc, gnu, traditional, clang) = if self . cpp {
2385
2384
( "CXX" , "cl.exe" , "g++" , "c++" , "clang++" )
2386
2385
} else {
@@ -2412,7 +2411,7 @@ impl Build {
2412
2411
// semi-buggy build scripts which are shared in
2413
2412
// makefiles/configure scripts (where spaces are far more
2414
2413
// lenient)
2415
- let mut t = Tool :: with_clang_driver ( PathBuf :: from ( tool. trim ( ) ) , driver_mode) ;
2414
+ let mut t = Tool :: with_clang_driver ( tool, driver_mode) ;
2416
2415
if let Some ( cc_wrapper) = wrapper {
2417
2416
t. cc_wrapper_path = Some ( PathBuf :: from ( cc_wrapper) ) ;
2418
2417
}
@@ -2472,7 +2471,7 @@ impl Build {
2472
2471
format ! ( "arm-kmc-eabi-{}" , gnu)
2473
2472
} else if target. starts_with ( "aarch64-kmc-solid_" ) {
2474
2473
format ! ( "aarch64-kmc-elf-{}" , gnu)
2475
- } else if self . get_host ( ) ? != target {
2474
+ } else if & * self . get_host ( ) ? != target {
2476
2475
let prefix = self . prefix_for_target ( & target) ;
2477
2476
match prefix {
2478
2477
Some ( prefix) => {
@@ -2499,10 +2498,10 @@ impl Build {
2499
2498
"CUDA compilation currently assumes empty pre-existing args"
2500
2499
) ;
2501
2500
let nvcc = match self . getenv_with_target_prefixes ( "NVCC" ) {
2502
- Err ( _) => "nvcc" . into ( ) ,
2503
- Ok ( nvcc) => nvcc,
2501
+ Err ( _) => PathBuf :: from ( "nvcc" ) ,
2502
+ Ok ( nvcc) => PathBuf :: from ( & * nvcc) ,
2504
2503
} ;
2505
- let mut nvcc_tool = Tool :: with_features ( PathBuf :: from ( nvcc) , None , self . cuda ) ;
2504
+ let mut nvcc_tool = Tool :: with_features ( nvcc, None , self . cuda ) ;
2506
2505
nvcc_tool
2507
2506
. args
2508
2507
. push ( format ! ( "-ccbin={}" , tool. path. display( ) ) . into ( ) ) ;
@@ -2589,7 +2588,7 @@ impl Build {
2589
2588
}
2590
2589
2591
2590
/// Returns compiler path, optional modifier name from whitelist, and arguments vec
2592
- fn env_tool ( & self , name : & str ) -> Option < ( String , Option < String > , Vec < String > ) > {
2591
+ fn env_tool ( & self , name : & str ) -> Option < ( PathBuf , Option < String > , Vec < String > ) > {
2593
2592
let tool = match self . getenv_with_target_prefixes ( name) {
2594
2593
Ok ( tool) => tool,
2595
2594
Err ( _) => return None ,
@@ -2598,8 +2597,8 @@ impl Build {
2598
2597
// If this is an exact path on the filesystem we don't want to do any
2599
2598
// interpretation at all, just pass it on through. This'll hopefully get
2600
2599
// us to support spaces-in-paths.
2601
- if Path :: new ( & tool) . exists ( ) {
2602
- return Some ( ( tool, None , Vec :: new ( ) ) ) ;
2600
+ if Path :: new ( & * tool) . exists ( ) {
2601
+ return Some ( ( PathBuf :: from ( & * tool) , None , Vec :: new ( ) ) ) ;
2603
2602
}
2604
2603
2605
2604
// Ok now we want to handle a couple of scenarios. We'll assume from
@@ -2638,15 +2637,15 @@ impl Build {
2638
2637
if known_wrappers. contains ( & file_stem) {
2639
2638
if let Some ( compiler) = parts. next ( ) {
2640
2639
return Some ( (
2641
- compiler. to_string ( ) ,
2640
+ compiler. into ( ) ,
2642
2641
Some ( maybe_wrapper. to_string ( ) ) ,
2643
2642
parts. map ( |s| s. to_string ( ) ) . collect ( ) ,
2644
2643
) ) ;
2645
2644
}
2646
2645
}
2647
2646
2648
2647
Some ( (
2649
- maybe_wrapper. to_string ( ) ,
2648
+ maybe_wrapper. into ( ) ,
2650
2649
Self :: rustc_wrapper_fallback ( ) ,
2651
2650
parts. map ( |s| s. to_string ( ) ) . collect ( ) ,
2652
2651
) )
@@ -2665,7 +2664,7 @@ impl Build {
2665
2664
if stdlib. is_empty ( ) {
2666
2665
Ok ( None )
2667
2666
} else {
2668
- Ok ( Some ( stdlib) )
2667
+ Ok ( Some ( stdlib. to_string ( ) ) )
2669
2668
}
2670
2669
} else {
2671
2670
let target = self . get_target ( ) ?;
@@ -3070,30 +3069,30 @@ impl Build {
3070
3069
prefixes. first ( ) . map ( |prefix| * prefix) )
3071
3070
}
3072
3071
3073
- fn get_target ( & self ) -> Result < Cow < str > , Error > {
3072
+ fn get_target ( & self ) -> Result < Arc < str > , Error > {
3074
3073
match & self . target {
3075
- Some ( t) => Ok ( Cow :: Borrowed ( & t ) ) ,
3076
- None => Ok ( Cow :: Owned ( self . getenv_unwrap ( "TARGET" ) ? ) ) ,
3074
+ Some ( t) => Ok ( t . clone ( ) ) ,
3075
+ None => self . getenv_unwrap ( "TARGET" ) ,
3077
3076
}
3078
3077
}
3079
3078
3080
- fn get_host ( & self ) -> Result < Cow < str > , Error > {
3079
+ fn get_host ( & self ) -> Result < Arc < str > , Error > {
3081
3080
match & self . host {
3082
- Some ( h) => Ok ( Cow :: Borrowed ( & h ) ) ,
3083
- None => Ok ( Cow :: Owned ( self . getenv_unwrap ( "HOST" ) ? ) ) ,
3081
+ Some ( h) => Ok ( h . clone ( ) ) ,
3082
+ None => self . getenv_unwrap ( "HOST" ) ,
3084
3083
}
3085
3084
}
3086
3085
3087
- fn get_opt_level ( & self ) -> Result < Cow < str > , Error > {
3086
+ fn get_opt_level ( & self ) -> Result < Arc < str > , Error > {
3088
3087
match & self . opt_level {
3089
- Some ( ol) => Ok ( Cow :: Borrowed ( & ol ) ) ,
3090
- None => Ok ( Cow :: Owned ( self . getenv_unwrap ( "OPT_LEVEL" ) ? ) ) ,
3088
+ Some ( ol) => Ok ( ol . clone ( ) ) ,
3089
+ None => self . getenv_unwrap ( "OPT_LEVEL" ) ,
3091
3090
}
3092
3091
}
3093
3092
3094
3093
fn get_debug ( & self ) -> bool {
3095
3094
self . debug . unwrap_or_else ( || match self . getenv ( "DEBUG" ) {
3096
- Some ( s) => s != "false" ,
3095
+ Some ( s) => & * s != "false" ,
3097
3096
None => false ,
3098
3097
} )
3099
3098
}
@@ -3136,7 +3135,7 @@ impl Build {
3136
3135
}
3137
3136
}
3138
3137
3139
- fn getenv ( & self , v : & str ) -> Option < String > {
3138
+ fn getenv ( & self , v : & str ) -> Option < Arc < str > > {
3140
3139
// Returns true for environment variables cargo sets for build scripts:
3141
3140
// https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
3142
3141
//
@@ -3158,13 +3157,13 @@ impl Build {
3158
3157
if self . emit_rerun_if_env_changed && !provided_by_cargo ( v) {
3159
3158
self . print ( & format_args ! ( "cargo:rerun-if-env-changed={}" , v) ) ;
3160
3159
}
3161
- let r = env:: var ( v) . ok ( ) ;
3160
+ let r = env:: var ( v) . ok ( ) . map ( Arc :: from ) ;
3162
3161
self . print ( & format_args ! ( "{} = {:?}" , v, r) ) ;
3163
3162
cache. insert ( v. to_string ( ) , r. clone ( ) ) ;
3164
3163
r
3165
3164
}
3166
3165
3167
- fn getenv_unwrap ( & self , v : & str ) -> Result < String , Error > {
3166
+ fn getenv_unwrap ( & self , v : & str ) -> Result < Arc < str > , Error > {
3168
3167
match self . getenv ( v) {
3169
3168
Some ( s) => Ok ( s) ,
3170
3169
None => Err ( Error :: new (
@@ -3174,7 +3173,7 @@ impl Build {
3174
3173
}
3175
3174
}
3176
3175
3177
- fn getenv_with_target_prefixes ( & self , var_base : & str ) -> Result < String , Error > {
3176
+ fn getenv_with_target_prefixes ( & self , var_base : & str ) -> Result < Arc < str > , Error > {
3178
3177
let target = self . get_target ( ) ?;
3179
3178
let host = self . get_host ( ) ?;
3180
3179
let kind = if host == target { "HOST" } else { "TARGET" } ;
0 commit comments