@@ -226,10 +226,10 @@ pub struct Build {
226226
227227 // Runtime state filled in later on
228228 // C/C++ compilers and archiver for all targets
229- cc : HashMap < TargetSelection , cc:: Tool > ,
230- cxx : HashMap < TargetSelection , cc:: Tool > ,
231- ar : HashMap < TargetSelection , PathBuf > ,
232- ranlib : HashMap < TargetSelection , PathBuf > ,
229+ cc : RefCell < HashMap < TargetSelection , cc:: Tool > > ,
230+ cxx : RefCell < HashMap < TargetSelection , cc:: Tool > > ,
231+ ar : RefCell < HashMap < TargetSelection , PathBuf > > ,
232+ ranlib : RefCell < HashMap < TargetSelection , PathBuf > > ,
233233 // Miscellaneous
234234 // allow bidirectional lookups: both name -> path and path -> name
235235 crates : HashMap < Interned < String > , Crate > ,
@@ -451,10 +451,10 @@ impl Build {
451451 miri_info,
452452 rustfmt_info,
453453 in_tree_llvm_info,
454- cc : HashMap :: new ( ) ,
455- cxx : HashMap :: new ( ) ,
456- ar : HashMap :: new ( ) ,
457- ranlib : HashMap :: new ( ) ,
454+ cc : RefCell :: new ( HashMap :: new ( ) ) ,
455+ cxx : RefCell :: new ( HashMap :: new ( ) ) ,
456+ ar : RefCell :: new ( HashMap :: new ( ) ) ,
457+ ranlib : RefCell :: new ( HashMap :: new ( ) ) ,
458458 crates : HashMap :: new ( ) ,
459459 crate_paths : HashMap :: new ( ) ,
460460 is_sudo,
@@ -482,7 +482,7 @@ impl Build {
482482 }
483483
484484 build. verbose ( "finding compilers" ) ;
485- cc_detect:: find ( & mut build) ;
485+ cc_detect:: find ( & build) ;
486486 // When running `setup`, the profile is about to change, so any requirements we have now may
487487 // be different on the next invocation. Don't check for them until the next time x.py is
488488 // run. This is ok because `setup` never runs any build commands, so it won't fail if commands are missing.
@@ -1103,16 +1103,16 @@ impl Build {
11031103 }
11041104
11051105 /// Returns the path to the C compiler for the target specified.
1106- fn cc ( & self , target : TargetSelection ) -> & Path {
1107- self . cc [ & target] . path ( )
1106+ fn cc ( & self , target : TargetSelection ) -> PathBuf {
1107+ self . cc . borrow ( ) [ & target] . path ( ) . into ( )
11081108 }
11091109
11101110 /// Returns a list of flags to pass to the C compiler for the target
11111111 /// specified.
11121112 fn cflags ( & self , target : TargetSelection , which : GitRepo , c : CLang ) -> Vec < String > {
11131113 let base = match c {
1114- CLang :: C => & self . cc [ & target] ,
1115- CLang :: Cxx => & self . cxx [ & target] ,
1114+ CLang :: C => self . cc . borrow ( ) [ & target] . clone ( ) ,
1115+ CLang :: Cxx => self . cxx . borrow ( ) [ & target] . clone ( ) ,
11161116 } ;
11171117
11181118 // Filter out -O and /O (the optimization flags) that we picked up from
@@ -1153,41 +1153,41 @@ impl Build {
11531153 }
11541154
11551155 /// Returns the path to the `ar` archive utility for the target specified.
1156- fn ar ( & self , target : TargetSelection ) -> Option < & Path > {
1157- self . ar . get ( & target) . map ( |p| & * * p )
1156+ fn ar ( & self , target : TargetSelection ) -> Option < PathBuf > {
1157+ self . ar . borrow ( ) . get ( & target) . cloned ( )
11581158 }
11591159
11601160 /// Returns the path to the `ranlib` utility for the target specified.
1161- fn ranlib ( & self , target : TargetSelection ) -> Option < & Path > {
1162- self . ranlib . get ( & target) . map ( |p| & * * p )
1161+ fn ranlib ( & self , target : TargetSelection ) -> Option < PathBuf > {
1162+ self . ranlib . borrow ( ) . get ( & target) . cloned ( )
11631163 }
11641164
11651165 /// Returns the path to the C++ compiler for the target specified.
1166- fn cxx ( & self , target : TargetSelection ) -> Result < & Path , String > {
1167- match self . cxx . get ( & target) {
1168- Some ( p) => Ok ( p. path ( ) ) ,
1166+ fn cxx ( & self , target : TargetSelection ) -> Result < PathBuf , String > {
1167+ match self . cxx . borrow ( ) . get ( & target) {
1168+ Some ( p) => Ok ( p. path ( ) . into ( ) ) ,
11691169 None => {
11701170 Err ( format ! ( "target `{}` is not configured as a host, only as a target" , target) )
11711171 }
11721172 }
11731173 }
11741174
11751175 /// Returns the path to the linker for the given target if it needs to be overridden.
1176- fn linker ( & self , target : TargetSelection ) -> Option < & Path > {
1177- if let Some ( linker) = self . config . target_config . get ( & target) . and_then ( |c| c. linker . as_ref ( ) )
1176+ fn linker ( & self , target : TargetSelection ) -> Option < PathBuf > {
1177+ if let Some ( linker) = self . config . target_config . get ( & target) . and_then ( |c| c. linker . clone ( ) )
11781178 {
11791179 Some ( linker)
11801180 } else if target. contains ( "vxworks" ) {
11811181 // need to use CXX compiler as linker to resolve the exception functions
11821182 // that are only existed in CXX libraries
1183- Some ( self . cxx [ & target] . path ( ) )
1183+ Some ( self . cxx . borrow ( ) [ & target] . path ( ) . into ( ) )
11841184 } else if target != self . config . build
11851185 && util:: use_host_linker ( target)
11861186 && !target. contains ( "msvc" )
11871187 {
11881188 Some ( self . cc ( target) )
11891189 } else if self . config . use_lld && !self . is_fuse_ld_lld ( target) && self . build == target {
1190- Some ( & self . initial_lld )
1190+ Some ( self . initial_lld . clone ( ) )
11911191 } else {
11921192 None
11931193 }
0 commit comments