Skip to content

Commit

Permalink
Add Serialize and JSON serialization support to the exported structs …
Browse files Browse the repository at this point in the history
…in wit-parser (#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>
  • Loading branch information
ydnar and Mossaka authored Sep 14, 2023
1 parent 3fa59ad commit 4975360
Show file tree
Hide file tree
Showing 56 changed files with 7,123 additions and 39 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ component = [
'wast',
'wasm-encoder',
'dep:wasmparser',
'serde_json',
]
metadata = ['dep:wasmparser', 'wasm-metadata', 'serde_json']
wit-smith = ['dep:wit-smith', 'arbitrary']
Expand Down
4 changes: 3 additions & 1 deletion crates/wit-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ Tooling for parsing `*.wit` files and working with their contents.
[dependencies]
id-arena = "2"
anyhow = { workspace = true }
indexmap = { workspace = true }
indexmap = { workspace = true, features = ["serde"] }
pulldown-cmark = { version = "0.9.3", default-features = false }
unicode-xid = "0.2.2"
log = { workspace = true }
url = { workspace = true }
semver = { workspace = true }
serde.workspace = true
serde_json = "1.0.105"

[dev-dependencies]
rayon = "1"
Expand Down
Loading

0 comments on commit 4975360

Please sign in to comment.