@@ -226,10 +226,10 @@ pub struct Build {
226
226
227
227
// Runtime state filled in later on
228
228
// 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 > > ,
233
233
// Miscellaneous
234
234
// allow bidirectional lookups: both name -> path and path -> name
235
235
crates : HashMap < Interned < String > , Crate > ,
@@ -451,10 +451,10 @@ impl Build {
451
451
miri_info,
452
452
rustfmt_info,
453
453
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 ( ) ) ,
458
458
crates : HashMap :: new ( ) ,
459
459
crate_paths : HashMap :: new ( ) ,
460
460
is_sudo,
@@ -482,7 +482,7 @@ impl Build {
482
482
}
483
483
484
484
build. verbose ( "finding compilers" ) ;
485
- cc_detect:: find ( & mut build) ;
485
+ cc_detect:: find ( & build) ;
486
486
// When running `setup`, the profile is about to change, so any requirements we have now may
487
487
// be different on the next invocation. Don't check for them until the next time x.py is
488
488
// 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 {
1103
1103
}
1104
1104
1105
1105
/// 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 ( )
1108
1108
}
1109
1109
1110
1110
/// Returns a list of flags to pass to the C compiler for the target
1111
1111
/// specified.
1112
1112
fn cflags ( & self , target : TargetSelection , which : GitRepo , c : CLang ) -> Vec < String > {
1113
1113
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 ( ) ,
1116
1116
} ;
1117
1117
1118
1118
// Filter out -O and /O (the optimization flags) that we picked up from
@@ -1153,41 +1153,41 @@ impl Build {
1153
1153
}
1154
1154
1155
1155
/// 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 ( )
1158
1158
}
1159
1159
1160
1160
/// 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 ( )
1163
1163
}
1164
1164
1165
1165
/// 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 ( ) ) ,
1169
1169
None => {
1170
1170
Err ( format ! ( "target `{}` is not configured as a host, only as a target" , target) )
1171
1171
}
1172
1172
}
1173
1173
}
1174
1174
1175
1175
/// 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 ( ) )
1178
1178
{
1179
1179
Some ( linker)
1180
1180
} else if target. contains ( "vxworks" ) {
1181
1181
// need to use CXX compiler as linker to resolve the exception functions
1182
1182
// that are only existed in CXX libraries
1183
- Some ( self . cxx [ & target] . path ( ) )
1183
+ Some ( self . cxx . borrow ( ) [ & target] . path ( ) . into ( ) )
1184
1184
} else if target != self . config . build
1185
1185
&& util:: use_host_linker ( target)
1186
1186
&& !target. contains ( "msvc" )
1187
1187
{
1188
1188
Some ( self . cc ( target) )
1189
1189
} 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 ( ) )
1191
1191
} else {
1192
1192
None
1193
1193
}
0 commit comments