@@ -11,7 +11,7 @@ use crate::utils::build_stamp;
11
11
use crate :: utils:: helpers:: { self , LldThreads , check_cfg_arg, linker_args, linker_flags} ;
12
12
use crate :: {
13
13
BootstrapCommand , CLang , Compiler , Config , DocTests , DryRun , EXTRA_CHECK_CFGS , GitRepo , Mode ,
14
- TargetSelection , command, prepare_behaviour_dump_dir, t,
14
+ RemapScheme , TargetSelection , command, prepare_behaviour_dump_dir, t,
15
15
} ;
16
16
17
17
/// Represents flag values in `String` form with whitespace delimiter to pass it to the compiler
@@ -636,6 +636,15 @@ impl Builder<'_> {
636
636
for ( restricted_mode, name, values) in EXTRA_CHECK_CFGS {
637
637
if restricted_mode. is_none ( ) || * restricted_mode == Some ( mode) {
638
638
rustflags. arg ( & check_cfg_arg ( name, * values) ) ;
639
+
640
+ if * name == "bootstrap" {
641
+ // Cargo doesn't pass RUSTFLAGS to proc_macros:
642
+ // https://github.com/rust-lang/cargo/issues/4423
643
+ // Thus, if we are on stage 0, we explicitly set `--cfg=bootstrap`.
644
+ // We also declare that the flag is expected, which we need to do to not
645
+ // get warnings about it being unexpected.
646
+ hostflags. arg ( check_cfg_arg ( name, * values) ) ;
647
+ }
639
648
}
640
649
}
641
650
@@ -645,13 +654,6 @@ impl Builder<'_> {
645
654
if stage == 0 {
646
655
hostflags. arg ( "--cfg=bootstrap" ) ;
647
656
}
648
- // Cargo doesn't pass RUSTFLAGS to proc_macros:
649
- // https://github.com/rust-lang/cargo/issues/4423
650
- // Thus, if we are on stage 0, we explicitly set `--cfg=bootstrap`.
651
- // We also declare that the flag is expected, which we need to do to not
652
- // get warnings about it being unexpected.
653
- hostflags. arg ( "-Zunstable-options" ) ;
654
- hostflags. arg ( "--check-cfg=cfg(bootstrap)" ) ;
655
657
656
658
// FIXME: It might be better to use the same value for both `RUSTFLAGS` and `RUSTDOCFLAGS`,
657
659
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
@@ -920,13 +922,46 @@ impl Builder<'_> {
920
922
hostflags. arg ( format ! ( "-Ctarget-feature={sign}crt-static" ) ) ;
921
923
}
922
924
923
- if let Some ( map_to) = self . build . debuginfo_map_to ( GitRepo :: Rustc ) {
924
- let map = format ! ( "{}={}" , self . build. src. display( ) , map_to) ;
925
- cargo. env ( "RUSTC_DEBUGINFO_MAP" , map) ;
925
+ // `rustc` needs to know the remapping scheme, in order to know how to reverse it (unremap)
926
+ // later. Two env vars are set and made available to the compiler
927
+ //
928
+ // - `CFG_VIRTUAL_RUST_SOURCE_BASE_DIR`: `rust-src` remap scheme (`NonCompiler`)
929
+ // - `CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR`: `rustc-dev` remap scheme (`Compiler`)
930
+ //
931
+ // Keep this scheme in sync with `rustc_metadata::rmeta::decoder`'s
932
+ // `try_to_translate_virtual_to_real`.
933
+ //
934
+ // `RUSTC_DEBUGINFO_MAP` is used to pass through to the underlying rustc
935
+ // `--remap-path-prefix`.
936
+ match mode {
937
+ Mode :: Rustc | Mode :: Codegen => {
938
+ if let Some ( ref map_to) =
939
+ self . build . debuginfo_map_to ( GitRepo :: Rustc , RemapScheme :: NonCompiler )
940
+ {
941
+ cargo. env ( "CFG_VIRTUAL_RUST_SOURCE_BASE_DIR" , map_to) ;
942
+ }
926
943
927
- // `rustc` needs to know the virtual `/rustc/$hash` we're mapping to,
928
- // in order to opportunistically reverse it later.
929
- cargo. env ( "CFG_VIRTUAL_RUST_SOURCE_BASE_DIR" , map_to) ;
944
+ if let Some ( ref map_to) =
945
+ self . build . debuginfo_map_to ( GitRepo :: Rustc , RemapScheme :: Compiler )
946
+ {
947
+ // When building compiler sources, we want to apply the compiler remap scheme.
948
+ cargo. env (
949
+ "RUSTC_DEBUGINFO_MAP" ,
950
+ format ! ( "{}={}" , self . build. src. display( ) , map_to) ,
951
+ ) ;
952
+ cargo. env ( "CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR" , map_to) ;
953
+ }
954
+ }
955
+ Mode :: Std | Mode :: ToolBootstrap | Mode :: ToolRustc | Mode :: ToolStd => {
956
+ if let Some ( ref map_to) =
957
+ self . build . debuginfo_map_to ( GitRepo :: Rustc , RemapScheme :: NonCompiler )
958
+ {
959
+ cargo. env (
960
+ "RUSTC_DEBUGINFO_MAP" ,
961
+ format ! ( "{}={}" , self . build. src. display( ) , map_to) ,
962
+ ) ;
963
+ }
964
+ }
930
965
}
931
966
932
967
if self . config . rust_remap_debuginfo {
0 commit comments