Skip to content

Commit

Permalink
Migrate wasm-bindgen to using walrus
Browse files Browse the repository at this point in the history
This commit moves `wasm-bindgen` the CLI tool from internally using
`parity-wasm` for wasm parsing/serialization to instead use `walrus`.
The `walrus` crate is something we've been working on recently with an
aim to replace the usage of `parity-wasm` in `wasm-bindgen` to make the
current CLI tool more maintainable as well as more future-proof.

The `walrus` crate provides a much nicer AST to work with as well as a
structured `Module`, whereas `parity-wasm` provides a very raw interface
to the wasm module which isn't really appropriate for our use case. The
many transformations and tweaks that wasm-bindgen does have a huge
amount of ad-hoc index management to carefully craft a final wasm
binary, but this is all entirely taken care for us with the `walrus`
crate.

Additionally, `wasm-bindgen` will ingest and rewrite the wasm file,
often changing the binary offsets of functions. Eventually with DWARF
debug information we'll need to be sure to preserve the debug
information throughout the transformations that `wasm-bindgen` does
today. This is practically impossible to do with the `parity-wasm`
architecture, but `walrus` was designed from the get-go to solve this
problem transparently in the `walrus` crate itself. (it doesn't today,
but this is planned work)

It is the intention that this does not end up regressing any
`wasm-bindgen` use cases, neither in functionality or in speed. As a
large change and refactoring, however, it's likely that at least
something will arise! We'll want to continue to remain vigilant to any
issues that come up with this commit.

Note that the `gc` crate has been deleted as part of this change, as the
`gc` crate is no longer necessary since `walrus` does it automatically.
Additionally the `gc` crate was one of the main problems with preserving
debug information as it often deletes wasm items!

Finally, this also starts moving crates to the 2018 edition where
necessary since `walrus` requires the 2018 edition, and in general it's
more pleasant to work within the 2018 edition!
  • Loading branch information
alexcrichton committed Feb 11, 2019
1 parent 311dafd commit c783d52
Show file tree
Hide file tree
Showing 76 changed files with 990 additions and 3,531 deletions.
14 changes: 3 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,9 @@ matrix:
script: cargo test -p ui-tests
if: branch = master

# wasm-gc tests work alright
- name: "test wasm-bindgen-gc crate"
install:
- git clone https://github.com/WebAssembly/wabt
- mkdir -p wabt/build
- (cd wabt/build && cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=sccache -DCMAKE_CXX_COMPILER_ARG1=c++ -DBUILD_TESTS=OFF && cmake --build . -- -j4)
- export PATH=$PATH:`pwd`/wabt/build
script:
- cargo test -p wasm-bindgen-gc
# Interpreter tests should quickly pass
- cargo test -p wasm-bindgen-wasm-interpreter
# wasm-interpreter tests work alright
- name: "test wasm-bindgen-wasm-interpreter crate"
script: cargo test -p wasm-bindgen-wasm-interpreter
if: branch = master

# Dist linux binary
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ wasm-bindgen = { path = '.' }
wasm-bindgen-futures = { path = 'crates/futures' }
js-sys = { path = 'crates/js-sys' }
web-sys = { path = 'crates/web-sys' }
walrus = { git = 'https://github.com/alexcrichton/walrus', branch = 'stack-neutral' }
5 changes: 3 additions & 2 deletions crates/cli-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ documentation = "https://docs.rs/wasm-bindgen-cli-support"
description = """
Shared support for the wasm-bindgen-cli package, an internal dependency
"""
edition = '2018'

[dependencies]
base64 = "0.9"
failure = "0.1.2"
parity-wasm = "0.36"
walrus = "0.1"
tempfile = "3.0"
wasm-bindgen-gc = { path = '../gc', version = '=0.2.33' }
wasm-bindgen-shared = { path = "../shared", version = '=0.2.33' }
wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.33' }
wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.33' }
rustc-demangle = "0.1.13"
2 changes: 1 addition & 1 deletion crates/cli-support/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ macro_rules! decode_api {
);
}

shared_api!(decode_api);
wasm_bindgen_shared::shared_api!(decode_api);
Loading

0 comments on commit c783d52

Please sign in to comment.