@@ -112,7 +112,7 @@ pub struct ConfigInfo {
112
112
pub sysroot_panic_abort : bool ,
113
113
pub cg_backend_path : String ,
114
114
pub sysroot_path : String ,
115
- pub gcc_path : String ,
115
+ pub gcc_path : Option < String > ,
116
116
config_file : Option < String > ,
117
117
// This is used in particular in rust compiler bootstrap because it doesn't run at the root
118
118
// of the `cg_gcc` folder, making it complicated for us to get access to local files we need
@@ -173,6 +173,14 @@ impl ConfigInfo {
173
173
"--release-sysroot" => self . sysroot_release_channel = true ,
174
174
"--release" => self . channel = Channel :: Release ,
175
175
"--sysroot-panic-abort" => self . sysroot_panic_abort = true ,
176
+ "--gcc-path" => match args. next ( ) {
177
+ Some ( arg) if !arg. is_empty ( ) => {
178
+ self . gcc_path = Some ( arg. into ( ) ) ;
179
+ }
180
+ _ => {
181
+ return Err ( "Expected a value after `--gcc-path`, found nothing" . to_string ( ) ) ;
182
+ }
183
+ } ,
176
184
"--cg_gcc-path" => match args. next ( ) {
177
185
Some ( arg) if !arg. is_empty ( ) => {
178
186
self . cg_gcc_path = Some ( arg. into ( ) ) ;
@@ -260,8 +268,9 @@ impl ConfigInfo {
260
268
create_symlink ( & libgccjit_so, output_dir. join ( & format ! ( "{}.0" , libgccjit_so_name) ) ) ?;
261
269
}
262
270
263
- self . gcc_path = output_dir. display ( ) . to_string ( ) ;
264
- println ! ( "Using `{}` as path for libgccjit" , self . gcc_path) ;
271
+ let gcc_path = output_dir. display ( ) . to_string ( ) ;
272
+ println ! ( "Using `{}` as path for libgccjit" , gcc_path) ;
273
+ self . gcc_path = Some ( gcc_path) ;
265
274
Ok ( ( ) )
266
275
}
267
276
@@ -273,6 +282,9 @@ impl ConfigInfo {
273
282
}
274
283
275
284
pub fn setup_gcc_path ( & mut self ) -> Result < ( ) , String > {
285
+ if self . gcc_path . is_some ( ) {
286
+ return Ok ( ( ) ) ;
287
+ }
276
288
let config_file = match self . config_file . as_deref ( ) {
277
289
Some ( config_file) => config_file. into ( ) ,
278
290
None => self . compute_path ( "config.toml" ) ,
@@ -283,12 +295,10 @@ impl ConfigInfo {
283
295
self . download_gccjit_if_needed ( ) ?;
284
296
return Ok ( ( ) ) ;
285
297
}
286
- self . gcc_path = match gcc_path {
287
- Some ( path) => path,
288
- None => {
289
- return Err ( format ! ( "missing `gcc-path` value from `{}`" , config_file. display( ) , ) ) ;
290
- }
291
- } ;
298
+ if gcc_path. is_none ( ) {
299
+ return Err ( format ! ( "missing `gcc-path` value from `{}`" , config_file. display( ) ) ) ;
300
+ }
301
+ self . gcc_path = gcc_path;
292
302
Ok ( ( ) )
293
303
}
294
304
@@ -299,10 +309,11 @@ impl ConfigInfo {
299
309
) -> Result < ( ) , String > {
300
310
env. insert ( "CARGO_INCREMENTAL" . to_string ( ) , "0" . to_string ( ) ) ;
301
311
302
- if self . gcc_path . is_empty ( ) && !use_system_gcc {
312
+ if self . gcc_path . is_none ( ) && !use_system_gcc {
303
313
self . setup_gcc_path ( ) ?;
304
314
}
305
- env. insert ( "GCC_PATH" . to_string ( ) , self . gcc_path . clone ( ) ) ;
315
+ let gcc_path = self . gcc_path . clone ( ) . unwrap ( ) ;
316
+ env. insert ( "GCC_PATH" . to_string ( ) , gcc_path. clone ( ) ) ;
306
317
307
318
if self . cargo_target_dir . is_empty ( ) {
308
319
match env. get ( "CARGO_TARGET_DIR" ) . filter ( |dir| !dir. is_empty ( ) ) {
@@ -414,7 +425,7 @@ impl ConfigInfo {
414
425
"{target}:{sysroot}:{gcc_path}" ,
415
426
target = self . cargo_target_dir,
416
427
sysroot = sysroot. display( ) ,
417
- gcc_path = self . gcc_path,
428
+ gcc_path = gcc_path,
418
429
) ;
419
430
env. insert ( "LIBRARY_PATH" . to_string ( ) , ld_library_path. clone ( ) ) ;
420
431
env. insert ( "LD_LIBRARY_PATH" . to_string ( ) , ld_library_path. clone ( ) ) ;
@@ -459,6 +470,7 @@ impl ConfigInfo {
459
470
--release-sysroot : Build sysroot in release mode
460
471
--sysroot-panic-abort : Build the sysroot without unwinding support
461
472
--config-file : Location of the config file to be used
473
+ --gcc-path : Location of the GCC root folder
462
474
--cg_gcc-path : Location of the rustc_codegen_gcc root folder (used
463
475
when ran from another directory)
464
476
--no-default-features : Add `--no-default-features` flag to cargo commands
0 commit comments