@@ -32,9 +32,21 @@ fn get_required_commit_hash() -> Result<String, Box<dyn Error>> {
3232}
3333
3434fn check_toolchain_version ( ) -> Result < ( ) , Box < dyn Error > > {
35- if !cfg ! ( feature = "skip-toolchain-check" ) {
36- // gets the commit hash from current rustc
35+ // if we're building from local source, check if REQUIRED_RUST_TOOLCHAIN matches ../../rust-toolchain
36+ println ! ( "{}" , std:: env:: current_dir( ) ?. display( ) ) ;
37+ if std:: env:: current_dir ( ) ?. ends_with ( "crates/rustc_codegen_spirv" ) {
38+ let current_toolchain = std:: fs:: read_to_string ( "../../rust-toolchain" ) ?;
39+ if !current_toolchain. contains ( REQUIRED_RUST_TOOLCHAIN ) {
40+ return Err ( Box :: < dyn Error > :: from ( format ! (
41+ "error: building from local source while `REQUIRED_RUST_TOOLCHAIN` (defined in `{}`) doesn't match `{}`" ,
42+ file!( ) ,
43+ std:: path:: Path :: new( "../../rust-toolchain" ) . canonicalize( ) ?. display( )
44+ ) ) ) ;
45+ }
46+ }
3747
48+ if !cfg ! ( feature = "skip-toolchain-check" ) {
49+ // check if our current rustc's commit hash matches with what we expect it to be
3850 let current_hash = get_rustc_commit_hash ( ) ?;
3951 let required_hash = get_required_commit_hash ( ) ?;
4052 if current_hash != required_hash {
@@ -46,8 +58,7 @@ fn check_toolchain_version() -> Result<(), Box<dyn Error>> {
4658 . unwrap_or_default ( ) ;
4759
4860 return Err ( Box :: < dyn Error > :: from ( format ! (
49- r#"
50- error: wrong toolchain detected (found commit hash `{current_hash}`, expected `{required_hash}`).
61+ r#"error: wrong toolchain detected (found commit hash `{current_hash}`, expected `{required_hash}`).
5162Make sure your `rust_toolchain` file contains the following:
5263-------------
5364{stripped_toolchain}
0 commit comments