@@ -112,7 +112,7 @@ pub struct ConfigInfo {
112112 pub sysroot_panic_abort : bool ,
113113 pub cg_backend_path : String ,
114114 pub sysroot_path : String ,
115- pub gcc_path : String ,
115+ pub gcc_path : Option < String > ,
116116 config_file : Option < String > ,
117117 // This is used in particular in rust compiler bootstrap because it doesn't run at the root
118118 // of the `cg_gcc` folder, making it complicated for us to get access to local files we need
@@ -173,6 +173,14 @@ impl ConfigInfo {
173173 "--release-sysroot" => self . sysroot_release_channel = true ,
174174 "--release" => self . channel = Channel :: Release ,
175175 "--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+ } ,
176184 "--cg_gcc-path" => match args. next ( ) {
177185 Some ( arg) if !arg. is_empty ( ) => {
178186 self . cg_gcc_path = Some ( arg. into ( ) ) ;
@@ -260,8 +268,9 @@ impl ConfigInfo {
260268 create_symlink ( & libgccjit_so, output_dir. join ( & format ! ( "{}.0" , libgccjit_so_name) ) ) ?;
261269 }
262270
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) ;
265274 Ok ( ( ) )
266275 }
267276
@@ -273,6 +282,15 @@ impl ConfigInfo {
273282 }
274283
275284 pub fn setup_gcc_path ( & mut self ) -> Result < ( ) , String > {
285+ // If the user used the `--gcc-path` option, no need to look at `config.toml` content
286+ // since we already have everything we need.
287+ if let Some ( gcc_path) = & self . gcc_path {
288+ println ! (
289+ "`--gcc-path` was provided, ignoring config file. Using `{}` as path for libgccjit" ,
290+ gcc_path
291+ ) ;
292+ return Ok ( ( ) ) ;
293+ }
276294 let config_file = match self . config_file . as_deref ( ) {
277295 Some ( config_file) => config_file. into ( ) ,
278296 None => self . compute_path ( "config.toml" ) ,
@@ -283,12 +301,15 @@ impl ConfigInfo {
283301 self . download_gccjit_if_needed ( ) ?;
284302 return Ok ( ( ) ) ;
285303 }
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- }
304+ let Some ( gcc_path) = gcc_path else {
305+ return Err ( format ! ( "missing `gcc-path` value from `{}`" , config_file. display( ) ) ) ;
291306 } ;
307+ println ! (
308+ "GCC path retrieved from `{}`. Using `{}` as path for libgccjit" ,
309+ config_file. display( ) ,
310+ gcc_path
311+ ) ;
312+ self . gcc_path = Some ( gcc_path) ;
292313 Ok ( ( ) )
293314 }
294315
@@ -299,10 +320,13 @@ impl ConfigInfo {
299320 ) -> Result < ( ) , String > {
300321 env. insert ( "CARGO_INCREMENTAL" . to_string ( ) , "0" . to_string ( ) ) ;
301322
302- if self . gcc_path . is_empty ( ) && !use_system_gcc {
323+ if self . gcc_path . is_none ( ) && !use_system_gcc {
303324 self . setup_gcc_path ( ) ?;
304325 }
305- env. insert ( "GCC_PATH" . to_string ( ) , self . gcc_path . clone ( ) ) ;
326+ let gcc_path = self . gcc_path . clone ( ) . expect (
327+ "The config module should have emitted an error if the GCC path wasn't provided" ,
328+ ) ;
329+ env. insert ( "GCC_PATH" . to_string ( ) , gcc_path. clone ( ) ) ;
306330
307331 if self . cargo_target_dir . is_empty ( ) {
308332 match env. get ( "CARGO_TARGET_DIR" ) . filter ( |dir| !dir. is_empty ( ) ) {
@@ -416,7 +440,7 @@ impl ConfigInfo {
416440 "{target}:{sysroot}:{gcc_path}" ,
417441 target = self . cargo_target_dir,
418442 sysroot = sysroot. display( ) ,
419- gcc_path = self . gcc_path,
443+ gcc_path = gcc_path,
420444 ) ;
421445 env. insert ( "LIBRARY_PATH" . to_string ( ) , ld_library_path. clone ( ) ) ;
422446 env. insert ( "LD_LIBRARY_PATH" . to_string ( ) , ld_library_path. clone ( ) ) ;
@@ -461,6 +485,7 @@ impl ConfigInfo {
461485 --release-sysroot : Build sysroot in release mode
462486 --sysroot-panic-abort : Build the sysroot without unwinding support
463487 --config-file : Location of the config file to be used
488+ --gcc-path : Location of the GCC root folder
464489 --cg_gcc-path : Location of the rustc_codegen_gcc root folder (used
465490 when ran from another directory)
466491 --no-default-features : Add `--no-default-features` flag to cargo commands
0 commit comments