Skip to content

Commit 4975360

Browse files
ydnarMossaka
andauthored
Add Serialize and JSON serialization support to the exported structs in wit-parser (bytecodealliance#1203)
* add serialize to all the exported structs Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com> * rustfmt Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com> * simplify the JSON output 1. serialize the Arena fields of Resolve as arrays, instead of an object with arena_id 2. serialize world items with kebab indexed 3. remove arena_id Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com> * wit-parser: add implementation of id_arena::ArenaBehavior for serde support * wit-parser: rename world arg to world_id * wit-parser: use InterfaceId and WorldId types * wit-parser: skip serialization of package name index * wit-parser: additional Serialize implementations * wit-parser: use derived Serialize for more types * wit-parser: change Params type from an alias to a single-value tuple with Deref/MutDeref This allows us to implement Serialize on the Params type. * wit-parser: cleanup on aisle params * wit-parser: lowercase serialization for enums Might change this? * wit-parser: implement Serialize in a function This should allow wit-parser to serialize without the upstream patch to id_arena. * wit-parser: remove dependency on fork of id-arena crate * wit-parser: remove custom Serialize impl for Function * wit-parser: remove custom Serialize impl for Docs * wit-parser: custom Serialize implementation for Handle and TypeOwner * wit-parser: custom Serialize impl for WorldItem * wit-parser: Serialize enums with less code * wit-parser: implement lowercase derived impl Serialize for FunctionKind * wit-parser: serialize WIT types in JSON in their lowercase form * wit-component, wit-parser: remove custom Params type Handle serialization using existing type alias to not break existing public API. * wit-parser: remove commented-out serialize fn * wit-parser: remove custom Serialize impl for Results * wit-parser: remove custom ArenaBehavior in favor of serialize_\* functions * wit-component: revert unnecessary line change * wit-parser: revert unrelated change * wit-parser: remove Serialize impl from Int * wit-parser: remove From<Int> for String * wit-parser: remove Serialize impl from FlagsRepr Not needed? * fixed the tests and run rustfmt Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com> * add serde_json to component feature Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com> * modified the tests to generate json for each valid WIT package. This uses the "BLESS=1" env var to tell `cargo test` to force to write to files. Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com> * delete the unit tests in resolve.rs Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com> * wit-parser: remove Serialize from IncludeName PR feedback on wasm-tools#177 * wit-parser: skip serializing Docs if empty PR feedback on wasm-tools#177 * wit-parser: commit blessed JSON output with empty Docs skipped * wit-parser: remove SerializableVersion This doesn’t seem to be necessary? * wit-parser: revert formatting changes PR feedback on wasm-tools#1177 * wit-parser: rustfmt --------- Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com> Co-authored-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com>
1 parent 3fa59ad commit 4975360

56 files changed

Lines changed: 7123 additions & 39 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ component = [
170170
'wast',
171171
'wasm-encoder',
172172
'dep:wasmparser',
173+
'serde_json',
173174
]
174175
metadata = ['dep:wasmparser', 'wasm-metadata', 'serde_json']
175176
wit-smith = ['dep:wit-smith', 'arbitrary']

crates/wit-parser/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ Tooling for parsing `*.wit` files and working with their contents.
1515
[dependencies]
1616
id-arena = "2"
1717
anyhow = { workspace = true }
18-
indexmap = { workspace = true }
18+
indexmap = { workspace = true, features = ["serde"] }
1919
pulldown-cmark = { version = "0.9.3", default-features = false }
2020
unicode-xid = "0.2.2"
2121
log = { workspace = true }
2222
url = { workspace = true }
2323
semver = { workspace = true }
24+
serde.workspace = true
25+
serde_json = "1.0.105"
2426

2527
[dev-dependencies]
2628
rayon = "1"

0 commit comments

Comments
 (0)