Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax same schema version requirement between wasm-bindgen-cli and wasm-bindgen #2544

Closed
chinedufn opened this issue May 2, 2021 · 1 comment · Fixed by #2546
Closed

Comments

@chinedufn
Copy link
Contributor

Background / Motivation

After getting lots of awesome mileage out of it, I'm looking to move away from wasm-pack (for reasons that I don't think are important for this issue).

The main problem that wasm-pack solves for me that would be difficult to make up for after moving away is the handling of version conformance between wasm-bindgen-cli (WB-CLI) and wasm-bindgen (WB).

As in, if WB in your Cargo.toml is 0.2.57 and your WB-CLI binary is 0.2.58, wasm-pack will download a different WB-CLI binary at 0.2.57 and use that instead. Nifty.

Current Status

The reason that you're forced to use the same version is because, historically, the schema has been unstable.

Forcing people to use the same version guaranteed that WB and WB-CLI would be using the same data format.

An alternative would be to simply maintain a schema version by hand, however this is prone to human error. Maintainers could forget to bump the schema version. So, I'm all for something human-error proof.

Potential Better Approach

Rather than use the Cargo.toml version as the schema version, it would be nice if the schema version was tied to the actual schema.

This could be accomplished with a build script.

  1. Move all of the relevant schema stuff into one or a few files. Isolated in this way so that when they change we know it's a schema change.

  2. Build script hashes these files and writes the hash to the OUT_DIR.

  3. pub const SCHEMA_VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/schema-hash"));

End State

By moving towards using a hash of what can actually change instead of an unrelated version, there would be much less churn in the WB and WB-CLI compatibility story.

This would make it feasible to simply depend on WB-CLI directly, and just upgrade the binary when you need to.

For example, as of May 2021, the last time that the shared crate changed was November 2020. If the trend is that this will continue to change less and less frequently, I'm very fine with occasionally needing to upgrade my WB-CLI binary.

Questions

  • Rather than look for everything that would need to be hashed.. I'd rather just ask someone who already knows. Is it really just some of the stuff in shared's lib.rs, or is there much more to it?

  • If it's just that file or just a few files, this seems like a no brainer to me. However, I might be missing or overlooking something. Please let me know if I am?


Thanks!

@alexcrichton
Copy link
Contributor

This seems like a reasonable approach to me! I think it'd be fine to hash the shared/lib.rs file and just make that the schema version.

chinedufn added a commit to chinedufn/wasm-bindgen that referenced this issue May 4, 2021
chinedufn added a commit to chinedufn/wasm-bindgen that referenced this issue May 4, 2021
chinedufn added a commit to chinedufn/wasm-bindgen that referenced this issue May 4, 2021
chinedufn added a commit to chinedufn/wasm-bindgen that referenced this issue May 4, 2021
chinedufn added a commit to chinedufn/wasm-bindgen that referenced this issue May 4, 2021
chinedufn added a commit to chinedufn/wasm-bindgen that referenced this issue May 4, 2021
chinedufn added a commit to chinedufn/wasm-bindgen that referenced this issue May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants