@@ -106,9 +106,9 @@ pub struct Cargo {
106106 rustdocflags : Rustflags ,
107107 hostflags : HostFlags ,
108108 allow_features : String ,
109- release_build : bool ,
110109 build_compiler_stage : u32 ,
111110 extra_rustflags : Vec < String > ,
111+ profile : Option < & ' static str > ,
112112}
113113
114114impl Cargo {
@@ -137,7 +137,11 @@ impl Cargo {
137137 }
138138
139139 pub fn release_build ( & mut self , release_build : bool ) {
140- self . release_build = release_build;
140+ self . profile = if release_build { Some ( "release" ) } else { None } ;
141+ }
142+
143+ pub fn profile ( & mut self , profile : & ' static str ) {
144+ self . profile = Some ( profile)
141145 }
142146
143147 pub fn compiler ( & self ) -> Compiler {
@@ -407,8 +411,8 @@ impl Cargo {
407411
408412impl From < Cargo > for BootstrapCommand {
409413 fn from ( mut cargo : Cargo ) -> BootstrapCommand {
410- if cargo. release_build {
411- cargo. args . insert ( 0 , "--release" . into ( ) ) ;
414+ if let Some ( profile ) = cargo. profile {
415+ cargo. args . insert ( 0 , format ! ( "--profile={profile}" ) . into ( ) ) ;
412416 }
413417
414418 for arg in & cargo. extra_rustflags {
@@ -598,7 +602,7 @@ impl Builder<'_> {
598602 build_stamp:: clear_if_dirty ( self , & my_out, & rustdoc) ;
599603 }
600604
601- let profile_var = |name : & str | cargo_profile_var ( name, & self . config ) ;
605+ let profile_var = |name : & str | cargo_profile_var ( name, & self . config , mode ) ;
602606
603607 // See comment in rustc_llvm/build.rs for why this is necessary, largely llvm-config
604608 // needs to not accidentally link to libLLVM in stage0/lib.
@@ -660,23 +664,15 @@ impl Builder<'_> {
660664 rustflags. arg ( sysroot_str) ;
661665 }
662666
663- let use_new_symbol_mangling = match self . config . rust_new_symbol_mangling {
664- Some ( setting) => {
665- // If an explicit setting is given, use that
666- setting
667- }
668- // Per compiler-team#938, v0 mangling is used on nightly
669- None if self . config . channel == "dev" || self . config . channel == "nightly" => true ,
670- None => {
671- if mode == Mode :: Std {
672- // The standard library defaults to the legacy scheme
673- false
674- } else {
675- // The compiler and tools default to the new scheme
676- true
677- }
667+ let use_new_symbol_mangling = self . config . rust_new_symbol_mangling . or_else ( || {
668+ if mode != Mode :: Std {
669+ // The compiler and tools default to the new scheme
670+ Some ( true )
671+ } else {
672+ // std follows the flag's default, which per compiler-team#938 is v0 on nightly
673+ None
678674 }
679- } ;
675+ } ) ;
680676
681677 // By default, windows-rs depends on a native library that doesn't get copied into the
682678 // sysroot. Passing this cfg enables raw-dylib support instead, which makes the native
@@ -687,10 +683,12 @@ impl Builder<'_> {
687683 rustflags. arg ( "--cfg=windows_raw_dylib" ) ;
688684 }
689685
690- if use_new_symbol_mangling {
691- rustflags. arg ( "-Csymbol-mangling-version=v0" ) ;
692- } else {
693- rustflags. arg ( "-Csymbol-mangling-version=legacy" ) ;
686+ if let Some ( usm) = use_new_symbol_mangling {
687+ rustflags. arg ( if usm {
688+ "-Csymbol-mangling-version=v0"
689+ } else {
690+ "-Csymbol-mangling-version=legacy"
691+ } ) ;
694692 }
695693
696694 // Always enable move/copy annotations for profiler visibility (non-stage0 only).
@@ -1434,9 +1432,18 @@ impl Builder<'_> {
14341432 . unwrap_or ( & self . config . rust_rustflags )
14351433 . clone ( ) ;
14361434
1437- let release_build = self . config . rust_optimize . is_release ( ) &&
1438- // cargo bench/install do not accept `--release` and miri doesn't want it
1439- !matches ! ( cmd_kind, Kind :: Bench | Kind :: Install | Kind :: Miri | Kind :: MiriSetup | Kind :: MiriTest ) ;
1435+ let profile =
1436+ if matches ! ( cmd_kind, Kind :: Bench | Kind :: Miri | Kind :: MiriSetup | Kind :: MiriTest ) {
1437+ // Use the default profile for bench/miri
1438+ None
1439+ } else {
1440+ match ( mode, self . config . rust_optimize . is_release ( ) ) {
1441+ // Some std configuration exists in its own profile
1442+ ( Mode :: Std , _) => Some ( "dist" ) ,
1443+ ( _, true ) => Some ( "release" ) ,
1444+ ( _, false ) => Some ( "dev" ) ,
1445+ }
1446+ } ;
14401447
14411448 Cargo {
14421449 command : cargo,
@@ -1448,14 +1455,19 @@ impl Builder<'_> {
14481455 rustdocflags,
14491456 hostflags,
14501457 allow_features,
1451- release_build,
14521458 build_compiler_stage,
14531459 extra_rustflags,
1460+ profile,
14541461 }
14551462 }
14561463}
14571464
1458- pub fn cargo_profile_var ( name : & str , config : & Config ) -> String {
1459- let profile = if config. rust_optimize . is_release ( ) { "RELEASE" } else { "DEV" } ;
1465+ pub fn cargo_profile_var ( name : & str , config : & Config , mode : Mode ) -> String {
1466+ let profile = match ( mode, config. rust_optimize . is_release ( ) ) {
1467+ // Some std configuration exists in its own profile
1468+ ( Mode :: Std , _) => "DIST" ,
1469+ ( _, true ) => "RELEASE" ,
1470+ ( _, false ) => "DEV" ,
1471+ } ;
14601472 format ! ( "CARGO_PROFILE_{profile}_{name}" )
14611473}
0 commit comments