@@ -24,6 +24,7 @@ pub use crate::flags::Subcommand;
2424use  crate :: flags:: { Color ,  Flags ,  Warnings } ; 
2525use  crate :: util:: { exe,  output,  t} ; 
2626use  once_cell:: sync:: OnceCell ; 
27+ use  semver:: Version ; 
2728use  serde:: { Deserialize ,  Deserializer } ; 
2829use  serde_derive:: Deserialize ; 
2930
@@ -1019,6 +1020,7 @@ impl Config {
10191020            config. download_beta_toolchain ( ) ; 
10201021            config. out . join ( config. build . triple ) . join ( "stage0/bin/rustc" ) 
10211022        } ) ; 
1023+ 
10221024        config. initial_cargo  = build
10231025            . cargo 
10241026            . map ( |cargo| { 
@@ -1680,6 +1682,42 @@ impl Config {
16801682        self . rust_codegen_backends . get ( 0 ) . cloned ( ) 
16811683    } 
16821684
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+ 
16831721    /// Returns the commit to download, or `None` if we shouldn't download CI artifacts. 
16841722fn  download_ci_rustc_commit ( & self ,  download_rustc :  Option < StringOrBool > )  -> Option < String >  { 
16851723        // If `download-rustc` is not set, default to rebuilding. 
0 commit comments