Skip to content

Commit 7236748

Browse files
authored
Relax schema version constraints (#2546)
1 parent 4e677bb commit 7236748

File tree

8 files changed

+55
-45
lines changed

8 files changed

+55
-45
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,7 @@ Released 2019-04-10.
915915

916916
### Added
917917

918-
* Initial support for transitive NPM dependencies has been added, although
919-
support has not fully landed in `wasm-pack` yet so it's not 100% integrated.
918+
* Initial support for transitive NPM dependencies has been added.
920919
[#1305](https://github.com/rustwasm/wasm-bindgen/pull/1305)
921920

922921
* The `constructor` property of `Object` is now bound in `js-sys`.

benchmarks/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ $ cp ./benchmarks /some/other/directory
2020
Next, `cd` into that directory and execute:
2121

2222
```
23-
$ wasm-pack build --target web
23+
$ cargo build --release --target wasm32-unknown-unknown
24+
$ wasm-bindgen --target web ./target/wasm32-unknown-unknown/release/crate.wasm
2425
```
2526

2627
Next, use your favorite static file server to host the current directory. For

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,15 +1457,16 @@ fn extract_programs<'a>(
14571457
"
14581458
14591459
it looks like the Rust project used to create this wasm file was linked against
1460-
a different version of wasm-bindgen than this binary:
1460+
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
1465-
Currently the bindgen format is unstable enough that these two version must
1466-
exactly match, so it's required that these two version are kept in sync by
1467-
either updating the wasm-bindgen dependency or this binary. You should be able
1468-
to update the wasm-bindgen dependency with:
1465+
Currently the bindgen format is unstable enough that these two schema versions
1466+
must exactly match. You can accomplish this by either updating the wasm-bindgen
1467+
dependency or this binary.
1468+
1469+
You should be able to update the wasm-bindgen dependency with:
14691470
14701471
cargo update -p wasm-bindgen
14711472

crates/shared/build.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
use std::collections::hash_map::DefaultHasher;
2+
use std::hash::Hasher;
3+
use std::path::PathBuf;
14
use std::process::Command;
25

36
fn main() {
7+
set_schema_version_env_var();
8+
49
let rev = Command::new("git")
510
.arg("rev-parse")
611
.arg("HEAD")
@@ -14,3 +19,13 @@ fn main() {
1419
}
1520
}
1621
}
22+
23+
fn set_schema_version_env_var() {
24+
let schema_file = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/src/lib.rs"));
25+
let schema_file = std::fs::read(schema_file).unwrap();
26+
27+
let mut hasher = DefaultHasher::new();
28+
hasher.write(&schema_file);
29+
30+
println!("cargo:rustc-env=SCHEMA_FILE_HASH={}", hasher.finish());
31+
}

crates/shared/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
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-
// package's version changes, which happens on all publishes.
5-
pub const SCHEMA_VERSION: &str = env!("CARGO_PKG_VERSION");
3+
#[cfg(test)]
4+
mod schema_hash_approval;
5+
6+
// This gets changed whenever our schema changes.
7+
// At this time versions of wasm-bindgen and wasm-bindgen-cli are required to have the exact same
8+
// SCHEMA_VERSION in order to work together.
9+
pub const SCHEMA_VERSION: &str = "0.2.74";
610

711
#[macro_export]
812
macro_rules! shared_api {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Whenever the lib.rs changes, the SCHEMA_FILE_HASH environment variable will change and the
2+
// schema_version test below will fail.
3+
// Proceed as follows:
4+
//
5+
// If the schema in this library has changed then:
6+
// 1. Change this APPROVED_SCHEMA_FILE_HASH to the new hash.
7+
//
8+
// If the schema in this library has changed then:
9+
// 1. Bump the version in `crates/shared/Cargo.toml`
10+
// 2. Change the `SCHEMA_VERSION` in this library to this new Cargo.toml version
11+
const APPROVED_SCHEMA_FILE_HASH: &'static str = "12458387802132375736";
12+
13+
#[test]
14+
fn schema_version() {
15+
assert_eq!(env!("SCHEMA_FILE_HASH"), APPROVED_SCHEMA_FILE_HASH)
16+
}

guide/src/reference/cli.md

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,11 @@ The `wasm-bindgen` command line tool has a number of options available to it to
44
tweak the JavaScript that is generated. The most up-to-date set of flags can
55
always be listed via `wasm-bindgen --help`.
66

7-
> Note: usually, one should use a [`wasm-pack`-based workflow][wasm-pack] rather
8-
> than running the `wasm-bindgen` command line tool by hand.
9-
10-
[wasm-pack]: https://github.com/rustwasm/wasm-pack
11-
127
## Installation
138

14-
The recommend way to install the `wasm-bindgen` command line tool is with the
15-
`wasm-pack` installer described
16-
[here](https://rustwasm.github.io/wasm-pack/installer/). After installing
17-
`wasm-pack`, you are ready to build project invoking `wasm-pack build`.
18-
This command installs apropriate version of the `wasm-bindgen` command-line
19-
tool. The version of `wasm-bindgen` installed by `wasm-pack` is not available
20-
to be used directly via command line.
21-
22-
It is not recommended to install `wasm-bindgen-cli` as its version must match
23-
_exactly_ the version of `wasm-bindgen` that is specified in the project's
24-
cargo.lock file. Using `wasm-pack` for building simplifies the build process
25-
as `wasm-pack` ensures that the proper version of `wasm-bindgen` command-line
26-
tool is used. That means that `wasm-pack` may install many different versions
27-
of `wasm-bindgen`, but during the build `wasm-pack` will always make sure to
28-
use the correct one.
29-
30-
Note: if, for any reason, you decide to use wasm-bindgen directly (this is
31-
not recommended!) you will have to manually take care of using exactly the
32-
same version of wasm-bindgen command-line tool (wasm-bindgen-cli) that
33-
matches the version of wasm-bingden in cargo.lock.
34-
9+
```
10+
cargo install -f wasm-bindgen-cli
11+
```
3512

3613
## Usage
3714

guide/src/reference/deployment.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ as documentation for the various known options, and as always PRs are welcome
66
to update this if it's out of date!
77

88
The methods of deployment and integration here are primarily tied to the
9-
`--target` flag. Note that the `--target` flag of `wasm-pack` and `wasm-bindgen`
10-
should behave the same way in this respect. The values possible here are:
9+
`--target` flag.
1110

1211
| Value | Summary |
1312
|-----------------|------------------------------------------------------------|
@@ -55,8 +54,7 @@ If you're not using a bundler but you're still running code in a web browser,
5554
`--target web` flag. You can check out a [full example][nomex] in the
5655
documentation, but the highlights of this output are:
5756

58-
* When compiling you'll pass `--target web` to `wasm-pack` (or `wasm-bindgen`
59-
directly).
57+
* When compiling you'll pass `--target web` to `wasm-bindgen`
6058
* The output can natively be included on a web page, and doesn't require any
6159
further postprocessing. The output is included as an ES module.
6260
* The `--target web` mode is not able to use NPM dependencies.
@@ -79,8 +77,7 @@ information about `--target no-modules`.
7977
**`--target nodejs`**
8078

8179
If you're deploying WebAssembly into Node.js (perhaps as an alternative to a
82-
native module), then you'll want to pass the `--target nodejs` flag to
83-
`wasm-pack` or `wasm-bindgen`.
80+
native module), then you'll want to pass the `--target nodejs` flag to `wasm-bindgen`.
8481

8582
Like the "without a bundler" strategy, this method of deployment does not
8683
require any further postprocessing. The generated JS shims can be `require`'d

0 commit comments

Comments
 (0)