@@ -128,6 +128,7 @@ pub struct ConfigInfo {
128128 // just to set the `gcc_path` field to display it.
129129 pub no_download : bool ,
130130 pub no_default_features : bool ,
131+ pub backend : Option < String > ,
131132}
132133
133134impl ConfigInfo {
@@ -178,6 +179,14 @@ impl ConfigInfo {
178179 return Err ( "Expected a value after `--cg_gcc-path`, found nothing" . to_string ( ) )
179180 }
180181 } ,
182+ "--use-backend" => match args. next ( ) {
183+ Some ( backend) if !backend. is_empty ( ) => self . backend = Some ( backend) ,
184+ _ => {
185+ return Err (
186+ "Expected an argument after `--use-backend`, found nothing" . into ( )
187+ )
188+ }
189+ } ,
181190 "--no-default-features" => self . no_default_features = true ,
182191 _ => return Ok ( false ) ,
183192 }
@@ -377,39 +386,27 @@ impl ConfigInfo {
377386 "debug"
378387 } ;
379388
380- let has_builtin_backend = env
381- . get ( "BUILTIN_BACKEND" )
382- . map ( |backend| !backend. is_empty ( ) )
383- . unwrap_or ( false ) ;
384-
385389 let mut rustflags = Vec :: new ( ) ;
386- if has_builtin_backend {
387- // It means we're building inside the rustc testsuite, so some options need to be handled
388- // a bit differently.
389- self . cg_backend_path = "gcc" . to_string ( ) ;
390-
391- match env . get ( "RUSTC_SYSROOT" ) {
392- Some ( rustc_sysroot ) if !rustc_sysroot . is_empty ( ) => {
393- rustflags . extend_from_slice ( & [ "-- sysroot". to_string ( ) , rustc_sysroot . clone ( ) ] ) ;
394- }
395- _ => { }
396- }
397- // This should not be needed, but is necessary for the CI in the rust repository.
398- // FIXME: Remove when the rust CI switches to the master version of libgccjit .
399- rustflags. push ( "-Cpanic=abort" . to_string ( ) ) ;
390+ self . cg_backend_path = current_dir
391+ . join ( "target" )
392+ . join ( channel )
393+ . join ( & format ! ( "librustc_codegen_gcc.{}" , self . dylib_ext ) )
394+ . display ( )
395+ . to_string ( ) ;
396+ self . sysroot_path = current_dir
397+ . join ( "build_sysroot/ sysroot")
398+ . display ( )
399+ . to_string ( ) ;
400+ if let Some ( backend ) = & self . backend {
401+ // This option is only used in the rust compiler testsuite. The sysroot is handled
402+ // by its build system directly so no need to set it ourselves .
403+ rustflags. push ( format ! ( "-Zcodegen-backend={}" , backend ) ) ;
400404 } else {
401- self . cg_backend_path = current_dir
402- . join ( "target" )
403- . join ( channel)
404- . join ( & format ! ( "librustc_codegen_gcc.{}" , self . dylib_ext) )
405- . display ( )
406- . to_string ( ) ;
407- self . sysroot_path = current_dir
408- . join ( "build_sysroot/sysroot" )
409- . display ( )
410- . to_string ( ) ;
411- rustflags. extend_from_slice ( & [ "--sysroot" . to_string ( ) , self . sysroot_path . clone ( ) ] ) ;
412- } ;
405+ rustflags. extend_from_slice ( & [
406+ "--sysroot" . to_string ( ) , self . sysroot_path . clone ( ) ,
407+ format ! ( "-Zcodegen-backend={}" , self . cg_backend_path) ,
408+ ] ) ;
409+ }
413410
414411 // This environment variable is useful in case we want to change options of rustc commands.
415412 if let Some ( cg_rustflags) = env. get ( "CG_RUSTFLAGS" ) {
@@ -427,10 +424,7 @@ impl ConfigInfo {
427424 rustflags. push ( "-Csymbol-mangling-version=v0" . to_string ( ) ) ;
428425 }
429426
430- rustflags. extend_from_slice ( & [
431- "-Cdebuginfo=2" . to_string ( ) ,
432- format ! ( "-Zcodegen-backend={}" , self . cg_backend_path) ,
433- ] ) ;
427+ rustflags. push ( "-Cdebuginfo=2" . to_string ( ) ) ;
434428
435429 // Since we don't support ThinLTO, disable LTO completely when not trying to do LTO.
436430 // TODO(antoyo): remove when we can handle ThinLTO.
@@ -454,9 +448,7 @@ impl ConfigInfo {
454448 ) ) ;
455449 let ld_library_path = format ! (
456450 "{target}:{sysroot}:{gcc_path}" ,
457- // FIXME: It's possible to pick another out directory. Would be nice to have a command
458- // line option to change it.
459- target = current_dir. join( "target/out" ) . display( ) ,
451+ target = self . cargo_target_dir,
460452 sysroot = sysroot. display( ) ,
461453 gcc_path = self . gcc_path,
462454 ) ;
@@ -481,7 +473,7 @@ impl ConfigInfo {
481473 self . rustc_command . extend_from_slice ( & rustflags) ;
482474 self . rustc_command . extend_from_slice ( & [
483475 "-L" . to_string ( ) ,
484- "crate=target/out" . to_string ( ) ,
476+ format ! ( "crate={}" , self . cargo_target_dir ) ,
485477 "--out-dir" . to_string ( ) ,
486478 self . cargo_target_dir . clone ( ) ,
487479 ] ) ;
@@ -504,7 +496,8 @@ impl ConfigInfo {
504496 --config-file : Location of the config file to be used
505497 --cg_gcc-path : Location of the rustc_codegen_gcc root folder (used
506498 when ran from another directory)
507- --no-default-features : Add `--no-default-features` flag to cargo commands"
499+ --no-default-features : Add `--no-default-features` flag to cargo commands
500+ --use-backend : Useful only for rustc testsuite"
508501 ) ;
509502 }
510503}
0 commit comments