@@ -24,6 +24,7 @@ pub use crate::flags::Subcommand;
24
24
use crate :: flags:: { Color , Flags , Warnings } ;
25
25
use crate :: util:: { exe, output, t} ;
26
26
use once_cell:: sync:: OnceCell ;
27
+ use semver:: Version ;
27
28
use serde:: { Deserialize , Deserializer } ;
28
29
use serde_derive:: Deserialize ;
29
30
@@ -1019,6 +1020,7 @@ impl Config {
1019
1020
config. download_beta_toolchain ( ) ;
1020
1021
config. out . join ( config. build . triple ) . join ( "stage0/bin/rustc" )
1021
1022
} ) ;
1023
+
1022
1024
config. initial_cargo = build
1023
1025
. cargo
1024
1026
. map ( |cargo| {
@@ -1680,6 +1682,42 @@ impl Config {
1680
1682
self . rust_codegen_backends . get ( 0 ) . cloned ( )
1681
1683
}
1682
1684
1685
+ pub fn check_build_rustc_version ( & self ) {
1686
+ if self . dry_run ( ) {
1687
+ return ;
1688
+ }
1689
+
1690
+ // check rustc version is same or lower with 1 apart from the building one
1691
+ let mut cmd = Command :: new ( & self . initial_rustc ) ;
1692
+ cmd. arg ( "--version" ) ;
1693
+ let rustc_output = output ( & mut cmd)
1694
+ . lines ( )
1695
+ . next ( )
1696
+ . unwrap ( )
1697
+ . split ( ' ' )
1698
+ . nth ( 1 )
1699
+ . unwrap ( )
1700
+ . split ( '-' )
1701
+ . next ( )
1702
+ . unwrap ( )
1703
+ . to_owned ( ) ;
1704
+ let rustc_version = Version :: parse ( & rustc_output. trim ( ) ) . unwrap ( ) ;
1705
+ let source_version =
1706
+ Version :: parse ( & fs:: read_to_string ( self . src . join ( "src/version" ) ) . unwrap ( ) . trim ( ) )
1707
+ . unwrap ( ) ;
1708
+ if !( source_version == rustc_version
1709
+ || ( source_version. major == rustc_version. major
1710
+ && source_version. minor == rustc_version. minor + 1 ) )
1711
+ {
1712
+ let prev_version = format ! ( "{}.{}.x" , source_version. major, source_version. minor - 1 ) ;
1713
+ eprintln ! (
1714
+ "Unexpected rustc version: {}, we should use {}/{} to build source with {}" ,
1715
+ rustc_version, prev_version, source_version, source_version
1716
+ ) ;
1717
+ crate :: detail_exit ( 1 ) ;
1718
+ }
1719
+ }
1720
+
1683
1721
/// Returns the commit to download, or `None` if we shouldn't download CI artifacts.
1684
1722
fn download_ci_rustc_commit ( & self , download_rustc : Option < StringOrBool > ) -> Option < String > {
1685
1723
// If `download-rustc` is not set, default to rebuilding.
0 commit comments