Skip to content

Commit a87ce69

Browse files
committed
Fail tests when schema has changes
1 parent 7cf11e0 commit a87ce69

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

crates/cli-support/src/wit/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,11 +1459,11 @@ fn extract_programs<'a>(
14591459
it looks like the Rust project used to create this wasm file was linked against
14601460
version of wasm-bindgen that uses a different bindgen format than this binary:
14611461
1462-
rust wasm file: {}
1463-
this binary: {}
1462+
rust wasm file schema version: {}
1463+
this binary schema version: {}
14641464
14651465
Currently the bindgen format is unstable enough that these two schema versions
1466-
must exactly match. You can accomplish ths by either updating the wasm-bindgen
1466+
must exactly match. You can accomplish this by either updating the wasm-bindgen
14671467
dependency or this binary.
14681468
14691469
You should be able to update the wasm-bindgen dependency with:

crates/shared/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ fn set_schema_version_env_var() {
2727
let mut hasher = DefaultHasher::new();
2828
hasher.write(&schema_file);
2929

30-
println!("cargo:rustc-env=SCHEMA_VERSION={}", hasher.finish());
30+
println!("cargo:rustc-env=SCHEMA_FILE_HASH={}", hasher.finish());
3131
}

crates/shared/src/lib.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#![doc(html_root_url = "https://docs.rs/wasm-bindgen-shared/0.2")]
22

3-
// The schema is so unstable right now we just force it to change whenever this
4-
// file changes.
5-
pub const SCHEMA_VERSION: &str = env!("SCHEMA_VERSION");
3+
// This gets changed whenever our schema changes.
4+
// At this time versions of wasm-bindgen and wasm-bindgen-cli are required to have the exact same
5+
// SCHEMA_VERSION in order to work together.
6+
pub const SCHEMA_VERSION: &str = "0.2.74";
67

78
#[macro_export]
89
macro_rules! shared_api {
@@ -191,3 +192,25 @@ pub fn version() -> String {
191192
}
192193
return v;
193194
}
195+
196+
#[cfg(test)]
197+
mod tests {
198+
use super::*;
199+
200+
// Whenever this file changes, the SCHEMA_FILE_HASH environment variable will change and the
201+
// schema_version test below will fail.
202+
// Proceed as follows:
203+
//
204+
// If the schema in this library has changed then:
205+
// 1. Change this APPROVED_SCHEMA_FILE_HASH to the new hash.
206+
//
207+
// If the schema in this library has changed then:
208+
// 1. Bump the version in `crates/shared/Cargo.toml`
209+
// 2. Change the `SCHEMA_VERSION` in this library to this new Cargo.toml version
210+
const APPROVED_SCHEMA_FILE_HASH: &'static str = "12345";
211+
212+
#[test]
213+
fn schema_version() {
214+
assert_eq!(env!("SCHEMA_FILE_HASH"), APPROVED_SCHEMA_FILE_HASH)
215+
}
216+
}

0 commit comments

Comments
 (0)