@@ -666,6 +666,14 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Car
666
666
cargo. rustdocflag ( "-Zcrate-attr=warn(rust_2018_idioms)" ) ;
667
667
}
668
668
669
+ /// Link all libstd rlibs/dylibs into a sysroot of `target_compiler`.
670
+ ///
671
+ /// Links those artifacts generated by `compiler` to the `stage` compiler's
672
+ /// sysroot for the specified `host` and `target`.
673
+ ///
674
+ /// Note that this assumes that `compiler` has already generated the libstd
675
+ /// libraries for `target`, and this method will find them in the relevant
676
+ /// output directory.
669
677
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
670
678
pub struct StdLink {
671
679
pub compiler : Compiler ,
@@ -952,14 +960,8 @@ impl Rustc {
952
960
}
953
961
954
962
impl Step for Rustc {
955
- /// We return the stage of the "actual" compiler (not the uplifted one).
956
- ///
957
- /// By "actual" we refer to the uplifting logic where we may not compile the requested stage;
958
- /// instead, we uplift it from the previous stages. Which can lead to bootstrap failures in
959
- /// specific situations where we request stage X from other steps. However we may end up
960
- /// uplifting it from stage Y, causing the other stage to fail when attempting to link with
961
- /// stage X which was never actually built.
962
- type Output = u32 ;
963
+ type Output = ( ) ;
964
+
963
965
const IS_HOST : bool = true ;
964
966
const DEFAULT : bool = false ;
965
967
@@ -998,7 +1000,7 @@ impl Step for Rustc {
998
1000
/// This will build the compiler for a particular stage of the build using
999
1001
/// the `build_compiler` targeting the `target` architecture. The artifacts
1000
1002
/// created will also be linked into the sysroot directory.
1001
- fn run ( self , builder : & Builder < ' _ > ) -> u32 {
1003
+ fn run ( self , builder : & Builder < ' _ > ) {
1002
1004
let build_compiler = self . build_compiler ;
1003
1005
let target = self . target ;
1004
1006
@@ -1014,7 +1016,7 @@ impl Step for Rustc {
1014
1016
& sysroot,
1015
1017
builder. config . ci_rustc_dev_contents ( ) ,
1016
1018
) ;
1017
- return build_compiler . stage ;
1019
+ return ;
1018
1020
}
1019
1021
1020
1022
// Build a standard library for `target` using the `build_compiler`.
@@ -1028,31 +1030,33 @@ impl Step for Rustc {
1028
1030
builder. info ( "WARNING: Use `--keep-stage-std` if you want to rebuild the compiler when it changes" ) ;
1029
1031
builder. ensure ( RustcLink :: from_rustc ( self , build_compiler) ) ;
1030
1032
1031
- return build_compiler . stage ;
1033
+ return ;
1032
1034
}
1033
1035
1034
- let compiler_to_use =
1035
- builder. compiler_for ( build_compiler. stage , build_compiler. host , target) ;
1036
- if compiler_to_use != build_compiler {
1037
- builder. ensure ( Rustc :: new ( compiler_to_use, target) ) ;
1038
- let msg = if compiler_to_use. host == target {
1039
- format ! (
1040
- "Uplifting rustc (stage{} -> stage{})" ,
1041
- compiler_to_use. stage,
1042
- build_compiler. stage + 1
1043
- )
1036
+ // The stage of the compiler that we're building
1037
+ let stage = build_compiler. stage + 1 ;
1038
+
1039
+ // If we are building a stage3+ compiler, and full bootstrap is disabled, and we have a
1040
+ // previous rustc available, we will uplift a compiler from a previous stage.
1041
+ if build_compiler. stage >= 2
1042
+ && !builder. config . full_bootstrap
1043
+ && ( target == builder. host_target || builder. hosts . contains ( & target) )
1044
+ {
1045
+ // If we're cross-compiling, the earliest rustc that we could have is stage 2.
1046
+ // If we're not cross-compiling, then we should have rustc stage 1.
1047
+ let stage_to_uplift = if target == builder. host_target { 1 } else { 2 } ;
1048
+ let rustc_to_uplift = builder. compiler ( stage_to_uplift, target) ;
1049
+ let msg = if rustc_to_uplift. host == target {
1050
+ format ! ( "Uplifting rustc (stage{} -> stage{stage})" , rustc_to_uplift. stage, )
1044
1051
} else {
1045
1052
format ! (
1046
- "Uplifting rustc (stage{}:{} -> stage{}:{})" ,
1047
- compiler_to_use. stage,
1048
- compiler_to_use. host,
1049
- build_compiler. stage + 1 ,
1050
- target
1053
+ "Uplifting rustc (stage{}:{} -> stage{stage}:{target})" ,
1054
+ rustc_to_uplift. stage, rustc_to_uplift. host,
1051
1055
)
1052
1056
} ;
1053
1057
builder. info ( & msg) ;
1054
- builder. ensure ( RustcLink :: from_rustc ( self , compiler_to_use ) ) ;
1055
- return compiler_to_use . stage ;
1058
+ builder. ensure ( RustcLink :: from_rustc ( self , rustc_to_uplift ) ) ;
1059
+ return ;
1056
1060
}
1057
1061
1058
1062
// Build a standard library for the current host target using the `build_compiler`.
@@ -1129,8 +1133,6 @@ impl Step for Rustc {
1129
1133
self ,
1130
1134
builder. compiler ( build_compiler. stage , builder. config . host_target ) ,
1131
1135
) ) ;
1132
-
1133
- build_compiler. stage
1134
1136
}
1135
1137
1136
1138
fn metadata ( & self ) -> Option < StepMetadata > {
@@ -1910,12 +1912,18 @@ impl Step for Sysroot {
1910
1912
}
1911
1913
}
1912
1914
1915
+ /// Prepare a compiler sysroot.
1916
+ ///
1917
+ /// The sysroot may contain various things useful for running the compiler, like linkers and
1918
+ /// linker wrappers (LLD, LLVM bitcode linker, etc.).
1919
+ ///
1920
+ /// This will assemble a compiler in `build/$target/stage$stage`.
1913
1921
#[ derive( Debug , PartialOrd , Ord , Clone , PartialEq , Eq , Hash ) ]
1914
1922
pub struct Assemble {
1915
1923
/// The compiler which we will produce in this step. Assemble itself will
1916
1924
/// take care of ensuring that the necessary prerequisites to do so exist,
1917
- /// that is, this target can be a stage2 compiler and Assemble will build
1918
- /// previous stages for you.
1925
+ /// that is, this can be e.g. a stage2 compiler and Assemble will build
1926
+ /// the previous stages for you.
1919
1927
pub target_compiler : Compiler ,
1920
1928
}
1921
1929
@@ -1933,11 +1941,6 @@ impl Step for Assemble {
1933
1941
} ) ;
1934
1942
}
1935
1943
1936
- /// Prepare a new compiler from the artifacts in `stage`
1937
- ///
1938
- /// This will assemble a compiler in `build/$host/stage$stage`. The compiler
1939
- /// must have been previously produced by the `stage - 1` builder.build
1940
- /// compiler.
1941
1944
fn run ( self , builder : & Builder < ' _ > ) -> Compiler {
1942
1945
let target_compiler = self . target_compiler ;
1943
1946
@@ -2066,7 +2069,7 @@ impl Step for Assemble {
2066
2069
target_compiler. stage - 1 ,
2067
2070
builder. config. host_target,
2068
2071
) ;
2069
- let mut build_compiler =
2072
+ let build_compiler =
2070
2073
builder. compiler ( target_compiler. stage - 1 , builder. config . host_target ) ;
2071
2074
2072
2075
// Build enzyme
@@ -2090,24 +2093,13 @@ impl Step for Assemble {
2090
2093
}
2091
2094
2092
2095
// Build the libraries for this compiler to link to (i.e., the libraries
2093
- // it uses at runtime). NOTE: Crates the target compiler compiles don't
2094
- // link to these. (FIXME: Is that correct? It seems to be correct most
2095
- // of the time but I think we do link to these for stage2/bin compilers
2096
- // when not performing a full bootstrap).
2096
+ // it uses at runtime).
2097
2097
debug ! (
2098
2098
?build_compiler,
2099
2099
"target_compiler.host" = ?target_compiler. host,
2100
2100
"building compiler libraries to link to"
2101
2101
) ;
2102
- let actual_stage = builder. ensure ( Rustc :: new ( build_compiler, target_compiler. host ) ) ;
2103
- // Current build_compiler.stage might be uplifted instead of being built; so update it
2104
- // to not fail while linking the artifacts.
2105
- debug ! (
2106
- "(old) build_compiler.stage" = build_compiler. stage,
2107
- "(adjusted) build_compiler.stage" = actual_stage,
2108
- "temporarily adjusting `build_compiler.stage` to account for uplifted libraries"
2109
- ) ;
2110
- build_compiler. stage = actual_stage;
2102
+ builder. ensure ( Rustc :: new ( build_compiler, target_compiler. host ) ) ;
2111
2103
2112
2104
let stage = target_compiler. stage ;
2113
2105
let host = target_compiler. host ;
0 commit comments