Stream: wit-bindgen

Topic: ✔ wit-parser crate: JSON format changes


view this post on Zulip Randy Reddig (Jun 08 2024 at 19:59):

Hi @Alex Crichton ! I’m adding support for @since and @unstable to wit-bindgen-go and had a couple questions:

  1. wit-bindgen-go shells out to wasm-tools component wit -j to parse WIT into JSON. The addition of feature gates means that the caller must pass in specific --features a,b,c arguments in order for the emitted JSON to faithfully represent the original WIT. Would you be amenable to a change that effectively enables --all-features when converting the WIT to JSON?
  2. The JSON representation (via serde) for the Stability enum is inconsistent with other enums used in a Resolve, e.g. your commit added tag = "type", which emits the following JSON:
{ "type": "unstable", "feature": "foo" }

TL;DR: In the Go representation (wasm-tools-go), enums are represented as a Go interface, with a set of types that implement that interface. Parsing the JSON with tag = "type" is trickier because it requires an intermediate representation before finalizing to one of the cases.

Would you accept a patch that makes it consistent with other enums? e.g.:

{ "unstable": { "feature": "foo" } }

The change is effectively changing crates/wit-parser/lib.rs:830 to:

#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]

view this post on Zulip Alex Crichton (Jun 09 2024 at 02:08):

Both changes sound reasonable to me! I was thinking as well that we'll want --all-features but I ended up forgetting to add that, so would be great to add :+1:. Also happy to change the JSON output if you find an alternative structure easier to parse. Would you like to send a PR for these changes? If not that's ok and I can try to find some time next week as well

view this post on Zulip Randy Reddig (Jun 09 2024 at 19:24):

JSON schema PR done: https://github.com/bytecodealliance/wasm-tools/pull/1598

This PR makes the JSON representation of enum Stability consistent with other enums in this crate, using the externally tagged representation: https://serde.rs/enum-representations.html#externally-...

view this post on Zulip Randy Reddig (Jun 09 2024 at 20:42):

And second PR that adds --all-features. Confirmed this works via uncommitted changes to wit-bindgen-go. Happy to take feedback on the coding style.

https://github.com/bytecodealliance/wasm-tools/pull/1599

This PR adds the --all-features option to wasm-tools component, primarily so wasm-tools component wit -j can emit a JSON representation of the original WIT with all @unstable gated features intact....

view this post on Zulip Alex Crichton (Jun 10 2024 at 15:05):

Thanks for this!

view this post on Zulip Notification Bot (Jun 10 2024 at 21:27):

Randy Reddig has marked this topic as resolved.

view this post on Zulip Randy Reddig (Jun 10 2024 at 21:39):

@Alex Crichton when’s the next warm-tools scheduled release?

view this post on Zulip Alex Crichton (Jun 10 2024 at 21:40):

Ah I tried to document that here in that there's no release cadence right now, it's all request-based at this time, but I can go kick it off

CLI and Rust libraries for low-level manipulation of WebAssembly modules - GitHub - bytecodealliance/wasm-tools: CLI and Rust libraries for low-level manipulation of WebAssembly modules

view this post on Zulip Alex Crichton (Jun 10 2024 at 22:47):

apologies I forgot to hit approve until just now


Last updated: Nov 22 2024 at 16:03 UTC