@@ -32,9 +32,21 @@ fn get_required_commit_hash() -> Result<String, Box<dyn Error>> {
32
32
}
33
33
34
34
fn 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
+ }
37
47
48
+ if !cfg ! ( feature = "skip-toolchain-check" ) {
49
+ // check if our current rustc's commit hash matches with what we expect it to be
38
50
let current_hash = get_rustc_commit_hash ( ) ?;
39
51
let required_hash = get_required_commit_hash ( ) ?;
40
52
if current_hash != required_hash {
@@ -46,8 +58,7 @@ fn check_toolchain_version() -> Result<(), Box<dyn Error>> {
46
58
. unwrap_or_default ( ) ;
47
59
48
60
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}`).
51
62
Make sure your `rust_toolchain` file contains the following:
52
63
-------------
53
64
{stripped_toolchain}
0 commit comments