From fee68d05ba85be2a358c48697bdeba2bc360b9c6 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Wed, 11 Sep 2024 21:56:15 +0200 Subject: [PATCH] chore: update deps, improve contributing guidelines, improve ci Signed-off-by: Henry Gressmann --- .github/workflows/test.yaml | 159 ++++-------- CONTRIBUTING.md | 73 +++++- Cargo.lock | 231 ++++++------------ Cargo.toml | 8 +- crates/parser/Cargo.toml | 3 +- crates/tinywasm/Cargo.toml | 21 +- .../tests/generated/wasm-annotations.csv | 2 +- .../tests/generated/wasm-multi-memory.csv | 2 +- .../tinywasm/tests/test-wasm-annotations.rs | 1 + .../tinywasm/tests/test-wasm-multi-memory.rs | 1 + crates/tinywasm/tests/testsuite/run.rs | 2 +- crates/types/Cargo.toml | 5 +- crates/types/src/archive.rs | 49 ++-- crates/types/src/instructions.rs | 6 +- crates/types/src/lib.rs | 38 +-- crates/types/src/value.rs | 2 +- examples/rust/Cargo.toml | 2 +- examples/rust/build.sh | 7 +- 18 files changed, 271 insertions(+), 341 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c1640e0..47708fb 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -24,132 +24,73 @@ jobs: name: wasm path: examples/rust/out - test-std: + run-tests: needs: build-wasm - name: Test with default features on stable Rust - runs-on: ubuntu-latest - + strategy: + matrix: + include: + - os: ubuntu-latest + rust: stable + name: "Linux (stable)" + - os: ubuntu-latest + rust: nightly + name: "Linux (nightly)" + - os: ubuntu-latest + rust: stable + name: "Linux (stable, no default features)" + args: "--no-default-features" + - os: ubuntu-latest + rust: nightly + name: "Linux (nightly, no default features)" + args: "--no-default-features" + - os: macos-14 + rust: stable + name: "macOS arm64 (Apple M1)" + - os: ubuntu-latest + rust: stable + name: "armv7 (32-Bit Raspberry Pi)" + target: armv7-unknown-linux-gnueabihf + + runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 with: submodules: true - - name: Install latest stable Rust toolchain - run: rustup update stable - - - name: Load wasm - uses: actions/download-artifact@v4 - with: - name: wasm - path: examples/rust/out - - - name: Build (stable) - run: cargo +stable build --workspace - - - name: Run tests (stable) - run: cargo +stable test --workspace && cargo +stable run --example wasm-rust all - - - name: Run MVP testsuite - run: cargo +stable test-wasm-1 - - - name: Run 2.0 testsuite - run: cargo +stable test-wasm-2 - - test-no-std: - needs: build-wasm - name: Test without default features on nightly Rust - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 + - name: Install Rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 with: - submodules: true - - - name: Install latest nightly Rust toolchain - run: rustup update nightly + toolchain: ${{ matrix.rust }} + rustflags: "" + components: rustfmt, clippy + if: matrix.target == '' - name: Load wasm uses: actions/download-artifact@v4 with: name: wasm - path: examples/rust/out - - - name: Build (nightly, no default features) - run: cargo +nightly build --workspace --no-default-features - - name: Run tests (nightly, no default features) - run: cargo +nightly test --workspace --no-default-features && cargo +nightly run --example wasm-rust all + - name: Run tests + run: cargo test --workspace ${{ matrix.args }} && cargo run --example wasm-rust all + if: matrix.target == '' - - name: Run MVP testsuite - run: cargo +nightly test-wasm-1 - - - name: Run 2.0 testsuite - run: cargo +nightly test-wasm-2 - - test-m1: - needs: build-wasm - name: Test on arm64 (Apple M1) - runs-on: macos-14 - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - name: Install stable Rust toolchain - run: rustup update stable + - name: Run clippy + run: cargo clippy --workspace --all-targets --all-features + if: matrix.target == '' - - name: Load wasm - uses: actions/download-artifact@v4 - with: - name: wasm - path: examples/rust/out - - - name: Build (stable) - run: cargo +stable build - - - name: Run tests (stable) - run: cargo +stable test - - - name: Run MVP testsuite - run: cargo +stable test-wasm-1 - - - name: Run 2.0 testsuite - run: cargo +stable test-wasm-2 - - test-armv7: - needs: build-wasm - name: Test on armv7 (32-Bit Raspberry Pi) - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - - name: Load wasm - uses: actions/download-artifact@v4 - with: - name: wasm - path: examples/rust/out - - - name: Run all tests (for the default workspace members) + - name: Run tests (${{ matrix.target }}) uses: houseabsolute/actions-rust-cross@v0.0.13 with: command: test - target: armv7-unknown-linux-gnueabihf - toolchain: nightly + target: ${{ matrix.target }} + toolchain: ${{ matrix.rust }} + if: matrix.target != '' - - name: Run MVP testsuite + - name: Run clippy (${{ matrix.target }}) uses: houseabsolute/actions-rust-cross@v0.0.13 with: - command: test - args: "-p tinywasm --test test-wasm-1 --release" - target: armv7-unknown-linux-gnueabihf - toolchain: nightly - - - name: Run 2.0 testsuite - uses: houseabsolute/actions-rust-cross@v0.0.13 - with: - command: test - args: "-p tinywasm --test test-wasm-2 --release" - target: armv7-unknown-linux-gnueabihf - toolchain: nightly + command: clippy + target: ${{ matrix.target }} + toolchain: ${{ matrix.rust }} + if: matrix.target != '' diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 933b19f..a0eb744 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,12 +1,69 @@ -# Scripts and Commands +# Contributing -> To improve the development experience, a number of custom commands and aliases have been added to the `.cargo/config.toml` file. These can be run using `cargo `. +Thank you for considering contributing to this project! This document outlines the process for contributing to this project. For small changes or bug fixes, feel free to open a pull request directly. For larger changes, please open an issue first to discuss the proposed changes. Also, please ensure that you open up your pull request against the `next` branch and [allow maintainers of the project to edit your code](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork). -- **`cargo test-wasm-1`**\ - Run the WebAssembly MVP (1.0) test suite. Be sure to cloned this repo with `--recursive` or initialize the submodules with `git submodule update --init --recursive` +## 1. Clone the Repository -- **`cargo test-wasm-2`**\ - Run the full WebAssembly test suite (2.0) +Ensure you clone this repository with the `--recursive` flag to include the submodules: -- **`cargo test-wast `**\ - Run a single WAST test file. e.g. `cargo test-wast ./examples/wast/i32.wast`. Useful for debugging failing test-cases. +```bash +git clone --recursive https://github.com/explodingcamera/tinywasm.git +``` + +If you have already cloned the repository, you can initialize the submodules with: + +```bash +git submodule update --init --recursive +``` + +This is required to run the WebAssembly test suite. + +## 2. Set up the Development Environment + +This project mostly uses a pretty standard Rust setup. Some common tasks: + +```bash +# Run a specific benchmark (run without arguments to see available benchmarks) +$ cargo bench --bench {bench_name} + +# Run all tests +$ cargo test + +# Run only the WebAssembly MVP (1.0) test suite +$ cargo test-wasm-1 + +# Run only the full WebAssembly test suite (2.0) +$ cargo test-wasm-2 + +# Run a specific test (run without arguments to see available tests) +$ cargo test --test {test_name} + +# Run a single WAST test file +$ cargo test-wast {path} + +# Run a specific example (run without arguments to see available examples) +# The wasm test files required to run the `wasm-rust` examples are not +# included in the main repository. +# To build these, you will need to run `./examples/rust/build.sh`. +$ cargo run --example {example_name} +``` + +### Profiling + +Either [samply](https://github.com/mstange/samply/) or [cargo-flamegraph](https://github.com/flamegraph-rs/flamegraph) are recommended for profiling. + +Example usage: + +```bash +cargo install --locked samply +cargo samply --example wasm-rust -- selfhosted +``` + +# Commits + +This project uses [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for commit messages. For pull requests, the commit messages will be squashed so you don't need to worry about this too much. However, it is still recommended to follow this convention for consistency. + +# Branches + +- `main`: The main branch. This branch is used for the latest stable release. +- `next`: The next branch. Development happens here. diff --git a/Cargo.lock b/Cargo.lock index c8bc86c..695bde4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,17 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "ahash" version = "0.8.11" @@ -65,7 +54,7 @@ dependencies = [ "argh_shared", "proc-macro2", "quote", - "syn 2.0.77", + "syn", ] [[package]] @@ -89,18 +78,6 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -128,46 +105,25 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytecheck" -version = "0.6.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23cdc57ce23ac53c931e88a43d06d070a6fd142f2617be5855eb75efc9beb1c2" -dependencies = [ - "bytecheck_derive 0.6.12", - "ptr_meta", - "simdutf8", -] - -[[package]] -name = "bytecheck" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41502630fe304ce54cbb2f8389e017784dee2b0328147779fcbe43b9db06d35d" +checksum = "50c8f430744b23b54ad15161fcbc22d82a29b73eacbe425fea23ec822600bc6f" dependencies = [ - "bytecheck_derive 0.7.0", + "bytecheck_derive", "ptr_meta", + "rancor", "simdutf8", ] [[package]] name = "bytecheck_derive" -version = "0.6.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3db406d29fbcd95542e92559bed4d8ad92636d1ca8b3b72ede10b4bcc010e659" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "bytecheck_derive" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eda88c587085bc07dc201ab9df871bd9baa5e07f7754b745e4d7194b43ac1eda" +checksum = "523363cbe1df49b68215efdf500b103ac3b0fb4836aed6d15689a076eadb8fff" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -370,12 +326,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -386,22 +336,11 @@ dependencies = [ "version_check", ] -[[package]] -name = "getrandom" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - [[package]] name = "globset" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" +checksum = "15f1ce686646e7f1e19bf7d5533fe443a45dbfb990e00629110797578b42fb19" dependencies = [ "aho-corasick", "bstr", @@ -420,22 +359,13 @@ dependencies = [ "crunchy", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = [ - "ahash 0.7.8", -] - [[package]] name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ - "ahash 0.8.11", + "ahash", ] [[package]] @@ -463,7 +393,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", - "hashbrown 0.14.5", + "hashbrown", ] [[package]] @@ -522,6 +452,26 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "munge" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64142d38c84badf60abf06ff9bd80ad2174306a5b11bd4706535090a30a419df" +dependencies = [ + "munge_macro", +] + +[[package]] +name = "munge_macro" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bb5c1d8184f13f7d0ccbeeca0def2f9a181bce2624302793005f5ca8aa62e5e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -545,9 +495,9 @@ checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" [[package]] name = "owo-colors" -version = "4.0.0" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caff54706df99d2a78a5a4e3455ff45448d81ef1bb63c22cd14052ca0e993a3f" +checksum = "fb37767f6569cd834a413442455e0f066d0d522de8630436e2a1761d9726ba56" [[package]] name = "pretty_env_logger" @@ -570,22 +520,22 @@ dependencies = [ [[package]] name = "ptr_meta" -version = "0.1.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" +checksum = "fe9e76f66d3f9606f44e45598d155cb13ecf09f4a28199e48daf8c8fc937ea90" dependencies = [ "ptr_meta_derive", ] [[package]] name = "ptr_meta_derive" -version = "0.1.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" +checksum = "ca414edb151b4c8d125c12566ab0d74dc9cdba36fb80eb7b848c15f495fd32d1" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -598,10 +548,13 @@ dependencies = [ ] [[package]] -name = "radium" -version = "0.7.0" +name = "rancor" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +checksum = "caf5f7161924b9d1cea0e4cabc97c372cea92b5f927fc13c6bca67157a0ad947" +dependencies = [ + "ptr_meta", +] [[package]] name = "rayon" @@ -654,40 +607,41 @@ checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "rend" -version = "0.4.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71fe3824f5629716b1589be05dacd749f6aa084c87e00e016714a8cdfccc997c" +checksum = "bc8d57aa48e8477046d7d6296d920a1f50bbbaf45047ec46c52f6d6cccea7ef7" dependencies = [ - "bytecheck 0.6.12", + "bytecheck", ] [[package]] name = "rkyv" -version = "0.7.45" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9008cd6385b9e161d8229e1f6549dd23c3d022f132a2ea37ac3a10ac4935779b" +checksum = "6d7fa2297190bd08087add407c3dedf28eb3be1d75955ffbd3bc312834325760" dependencies = [ - "bitvec", - "bytecheck 0.6.12", + "bytecheck", "bytes", - "hashbrown 0.12.3", + "hashbrown", + "indexmap", + "munge", "ptr_meta", + "rancor", "rend", "rkyv_derive", - "seahash", "tinyvec", "uuid", ] [[package]] name = "rkyv_derive" -version = "0.7.45" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "503d1d27590a2b0a3a4ca4c94755aa2875657196ecbf401a42eff41d7de532c0" +checksum = "4aad510db4f88722adf0e4586ff0dedfca4af57b17c075b2420bac1db446d22c" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -710,7 +664,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn 2.0.77", + "syn", "walkdir", ] @@ -740,12 +694,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "seahash" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" - [[package]] name = "semver" version = "1.0.23" @@ -769,7 +717,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn", ] [[package]] @@ -801,17 +749,6 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.77" @@ -823,12 +760,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "termcolor" version = "1.4.1" @@ -916,7 +847,6 @@ dependencies = [ name = "tinywasm-types" version = "0.8.0" dependencies = [ - "bytecheck 0.7.0", "log", "rkyv", ] @@ -929,9 +859,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-width" @@ -961,17 +891,11 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "wasm-encoder" -version = "0.216.0" +version = "0.217.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04c23aebea22c8a75833ae08ed31ccc020835b12a41999e58c31464271b94a88" +checksum = "7b88b0814c9a2b323a9b46c687e726996c255ac8b64aa237dd11c81ed4854760" dependencies = [ "leb128", ] @@ -985,22 +909,22 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.216.0" +version = "0.217.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcdee6bea3619d311fb4b299721e89a986c3470f804b6d534340e412589028e3" +checksum = "ca917a21307d3adf2b9857b94dd05ebf8496bdcff4437a9b9fb3899d3e6c74e7" dependencies = [ - "ahash 0.8.11", + "ahash", "bitflags", - "hashbrown 0.14.5", + "hashbrown", "indexmap", "semver", ] [[package]] name = "wast" -version = "216.0.0" +version = "217.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7eb1f2eecd913fdde0dc6c3439d0f24530a98ac6db6cb3d14d92a5328554a08" +checksum = "79004ecebded92d3c710d4841383368c7f04b63d0992ddd6b0c7d5029b7629b7" dependencies = [ "bumpalo", "leb128", @@ -1011,9 +935,9 @@ dependencies = [ [[package]] name = "wat" -version = "1.216.0" +version = "1.217.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac0409090fb5154f95fb5ba3235675fd9e579e731524d63b6a2f653e1280c82a" +checksum = "c126271c3d92ca0f7c63e4e462e40c69cca52fd4245fcda730d1cf558fb55088" dependencies = [ "wast", ] @@ -1109,15 +1033,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - [[package]] name = "zerocopy" version = "0.7.35" @@ -1135,5 +1050,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn", ] diff --git a/Cargo.toml b/Cargo.toml index 7196533..ae231c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,8 @@ default-members=[".", "crates/tinywasm", "crates/types", "crates/parser"] resolver="2" [workspace.dependencies] -wast="216" -wat="1.216" +wast="217" +wat="1.217" eyre="0.6" log="0.4" pretty_env_logger="0.5" @@ -51,3 +51,7 @@ lto="thin" codegen-units=1 panic="abort" inherits="release" + +[profile.samply] +inherits = "release" +debug = true diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index efb0817..fa16664 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -9,7 +9,7 @@ repository.workspace=true rust-version.workspace=true [dependencies] -wasmparser={version="0.216", default-features=false, features=["validate"]} +wasmparser={version="0.217", default-features=false, features=["validate", "features"]} log={workspace=true, optional=true} tinywasm-types={version="0.8.0-alpha.0", path="../types", default-features=false} @@ -17,4 +17,3 @@ tinywasm-types={version="0.8.0-alpha.0", path="../types", default-features=false default=["std", "logging"] logging=["log"] std=["tinywasm-types/std", "wasmparser/std"] -nightly=[] diff --git a/crates/tinywasm/Cargo.toml b/crates/tinywasm/Cargo.toml index ebe7ffd..264d4b9 100644 --- a/crates/tinywasm/Cargo.toml +++ b/crates/tinywasm/Cargo.toml @@ -33,49 +33,42 @@ serde={version="1.0", features=["derive"]} default=["std", "parser", "logging", "archive"] logging=["log", "tinywasm-parser?/logging", "tinywasm-types/logging"] std=["tinywasm-parser?/std", "tinywasm-types/std"] -parser=["tinywasm-parser"] +parser=["dep:tinywasm-parser"] archive=["tinywasm-types/archive"] -simd=[] -nightly=["tinywasm-parser?/nightly"] +nightly=[] [[test]] name="test-wasm-1" harness=false -test=false [[test]] name="test-wasm-2" harness=false -test=false [[test]] name="test-wasm-multi-memory" harness=false -test=false [[test]] -name="test-wasm-memory64" +name="test-wasm-annotations" harness=false -test=false [[test]] -name="test-wasm-annotations" +name="test-wasm-custom-page-sizes" harness=false -test=false [[test]] -name="test-wasm-extended-const" +name="test-wasm-memory64" harness=false test=false [[test]] -name="test-wasm-simd" +name="test-wasm-extended-const" harness=false test=false - [[test]] -name="test-wasm-custom-page-sizes" +name="test-wasm-simd" harness=false test=false diff --git a/crates/tinywasm/tests/generated/wasm-annotations.csv b/crates/tinywasm/tests/generated/wasm-annotations.csv index 582bc1b..1e66217 100644 --- a/crates/tinywasm/tests/generated/wasm-annotations.csv +++ b/crates/tinywasm/tests/generated/wasm-annotations.csv @@ -1 +1 @@ -0.8.0,331,286,[{"name":"annotations.wast","passed":74,"failed":0},{"name":"id.wast","passed":7,"failed":0},{"name":"simd_lane.wast","passed":189,"failed":286},{"name":"token.wast","passed":61,"failed":0}] +0.8.0,142,0,[{"name":"annotations.wast","passed":74,"failed":0},{"name":"annotations/simd_lane.wast (skipped)","passed":0,"failed":0},{"name":"id.wast","passed":7,"failed":0},{"name":"token.wast","passed":61,"failed":0}] diff --git a/crates/tinywasm/tests/generated/wasm-multi-memory.csv b/crates/tinywasm/tests/generated/wasm-multi-memory.csv index e4c4533..b730f97 100644 --- a/crates/tinywasm/tests/generated/wasm-multi-memory.csv +++ b/crates/tinywasm/tests/generated/wasm-multi-memory.csv @@ -1 +1 @@ -0.8.0,1870,1,[{"name":"address0.wast","passed":92,"failed":0},{"name":"address1.wast","passed":127,"failed":0},{"name":"align.wast","passed":160,"failed":0},{"name":"align0.wast","passed":5,"failed":0},{"name":"binary.wast","passed":124,"failed":0},{"name":"binary0.wast","passed":7,"failed":0},{"name":"data.wast","passed":61,"failed":0},{"name":"data0.wast","passed":7,"failed":0},{"name":"data1.wast","passed":14,"failed":0},{"name":"data_drop0.wast","passed":11,"failed":0},{"name":"exports0.wast","passed":8,"failed":0},{"name":"float_exprs0.wast","passed":14,"failed":0},{"name":"float_exprs1.wast","passed":3,"failed":0},{"name":"float_memory0.wast","passed":30,"failed":0},{"name":"imports.wast","passed":175,"failed":0},{"name":"imports0.wast","passed":8,"failed":0},{"name":"imports1.wast","passed":5,"failed":0},{"name":"imports2.wast","passed":20,"failed":0},{"name":"imports3.wast","passed":10,"failed":0},{"name":"imports4.wast","passed":16,"failed":0},{"name":"linking0.wast","passed":6,"failed":0},{"name":"linking1.wast","passed":14,"failed":0},{"name":"linking2.wast","passed":11,"failed":0},{"name":"linking3.wast","passed":14,"failed":0},{"name":"load.wast","passed":118,"failed":0},{"name":"load0.wast","passed":3,"failed":0},{"name":"load1.wast","passed":18,"failed":0},{"name":"load2.wast","passed":38,"failed":0},{"name":"memory-multi.wast","passed":6,"failed":0},{"name":"memory.wast","passed":86,"failed":0},{"name":"memory_copy0.wast","passed":29,"failed":0},{"name":"memory_copy1.wast","passed":14,"failed":0},{"name":"memory_fill0.wast","passed":16,"failed":0},{"name":"memory_grow.wast","passed":157,"failed":0},{"name":"memory_init0.wast","passed":13,"failed":0},{"name":"memory_size.wast","passed":49,"failed":0},{"name":"memory_size0.wast","passed":8,"failed":0},{"name":"memory_size1.wast","passed":15,"failed":0},{"name":"memory_size2.wast","passed":21,"failed":0},{"name":"memory_size3.wast","passed":2,"failed":0},{"name":"memory_trap0.wast","passed":14,"failed":0},{"name":"memory_trap1.wast","passed":168,"failed":0},{"name":"simd_memory-multi.wast","passed":0,"failed":1},{"name":"start0.wast","passed":9,"failed":0},{"name":"store.wast","passed":111,"failed":0},{"name":"store0.wast","passed":5,"failed":0},{"name":"store1.wast","passed":13,"failed":0},{"name":"traps0.wast","passed":15,"failed":0}] +0.8.0,1870,0,[{"name":"address0.wast","passed":92,"failed":0},{"name":"address1.wast","passed":127,"failed":0},{"name":"align.wast","passed":160,"failed":0},{"name":"align0.wast","passed":5,"failed":0},{"name":"binary.wast","passed":124,"failed":0},{"name":"binary0.wast","passed":7,"failed":0},{"name":"data.wast","passed":61,"failed":0},{"name":"data0.wast","passed":7,"failed":0},{"name":"data1.wast","passed":14,"failed":0},{"name":"data_drop0.wast","passed":11,"failed":0},{"name":"exports0.wast","passed":8,"failed":0},{"name":"float_exprs0.wast","passed":14,"failed":0},{"name":"float_exprs1.wast","passed":3,"failed":0},{"name":"float_memory0.wast","passed":30,"failed":0},{"name":"imports.wast","passed":175,"failed":0},{"name":"imports0.wast","passed":8,"failed":0},{"name":"imports1.wast","passed":5,"failed":0},{"name":"imports2.wast","passed":20,"failed":0},{"name":"imports3.wast","passed":10,"failed":0},{"name":"imports4.wast","passed":16,"failed":0},{"name":"linking0.wast","passed":6,"failed":0},{"name":"linking1.wast","passed":14,"failed":0},{"name":"linking2.wast","passed":11,"failed":0},{"name":"linking3.wast","passed":14,"failed":0},{"name":"load.wast","passed":118,"failed":0},{"name":"load0.wast","passed":3,"failed":0},{"name":"load1.wast","passed":18,"failed":0},{"name":"load2.wast","passed":38,"failed":0},{"name":"memory-multi.wast","passed":6,"failed":0},{"name":"memory.wast","passed":86,"failed":0},{"name":"memory_copy0.wast","passed":29,"failed":0},{"name":"memory_copy1.wast","passed":14,"failed":0},{"name":"memory_fill0.wast","passed":16,"failed":0},{"name":"memory_grow.wast","passed":157,"failed":0},{"name":"memory_init0.wast","passed":13,"failed":0},{"name":"memory_size.wast","passed":49,"failed":0},{"name":"memory_size0.wast","passed":8,"failed":0},{"name":"memory_size1.wast","passed":15,"failed":0},{"name":"memory_size2.wast","passed":21,"failed":0},{"name":"memory_size3.wast","passed":2,"failed":0},{"name":"memory_trap0.wast","passed":14,"failed":0},{"name":"memory_trap1.wast","passed":168,"failed":0},{"name":"multi-memory/simd_memory-multi.wast (skipped)","passed":0,"failed":0},{"name":"start0.wast","passed":9,"failed":0},{"name":"store.wast","passed":111,"failed":0},{"name":"store0.wast","passed":5,"failed":0},{"name":"store1.wast","passed":13,"failed":0},{"name":"traps0.wast","passed":15,"failed":0}] diff --git a/crates/tinywasm/tests/test-wasm-annotations.rs b/crates/tinywasm/tests/test-wasm-annotations.rs index fa40467..c521156 100644 --- a/crates/tinywasm/tests/test-wasm-annotations.rs +++ b/crates/tinywasm/tests/test-wasm-annotations.rs @@ -7,6 +7,7 @@ fn main() -> Result<()> { let mut test_suite = TestSuite::new(); TestSuite::set_log_level(log::LevelFilter::Off); + test_suite.skip("annotations/simd_lane.wast"); test_suite.run_spec_group(wasm_testsuite::get_proposal_tests("annotations"))?; test_suite.save_csv("./tests/generated/wasm-annotations.csv", env!("CARGO_PKG_VERSION"))?; diff --git a/crates/tinywasm/tests/test-wasm-multi-memory.rs b/crates/tinywasm/tests/test-wasm-multi-memory.rs index 2cee13d..9b1f8b7 100644 --- a/crates/tinywasm/tests/test-wasm-multi-memory.rs +++ b/crates/tinywasm/tests/test-wasm-multi-memory.rs @@ -7,6 +7,7 @@ fn main() -> Result<()> { let mut test_suite = TestSuite::new(); TestSuite::set_log_level(log::LevelFilter::Off); + test_suite.skip("multi-memory/simd_memory-multi.wast"); test_suite.run_spec_group(wasm_testsuite::get_proposal_tests("multi-memory"))?; test_suite.save_csv("./tests/generated/wasm-multi-memory.csv", env!("CARGO_PKG_VERSION"))?; diff --git a/crates/tinywasm/tests/testsuite/run.rs b/crates/tinywasm/tests/testsuite/run.rs index a179956..ac11eda 100644 --- a/crates/tinywasm/tests/testsuite/run.rs +++ b/crates/tinywasm/tests/testsuite/run.rs @@ -184,7 +184,7 @@ impl TestSuite { let span = directive.span(); use wast::WastDirective::{ AssertExhaustion, AssertInvalid, AssertMalformed, AssertReturn, AssertTrap, AssertUnlinkable, Invoke, - Register, Wat, + Module as Wat, Register, }; match directive { diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml index b643964..7531ab4 100644 --- a/crates/types/Cargo.toml +++ b/crates/types/Cargo.toml @@ -10,11 +10,10 @@ rust-version.workspace=true [dependencies] log={workspace=true, optional=true} -rkyv={version="0.7", optional=true, default-features=false, features=["size_32", "validation"]} -bytecheck={version="0.7", optional=true} +rkyv={version="0.8.0-rc.2", optional=true, default-features=false, features=["alloc", "bytecheck"]} [features] default=["std", "logging", "archive"] std=["rkyv?/std"] -archive=["dep:rkyv", "dep:bytecheck"] +archive=["dep:rkyv"] logging=["dep:log"] diff --git a/crates/types/src/archive.rs b/crates/types/src/archive.rs index cce0501..cc60314 100644 --- a/crates/types/src/archive.rs +++ b/crates/types/src/archive.rs @@ -2,17 +2,19 @@ use core::fmt::{Display, Formatter}; use crate::TinyWasmModule; use rkyv::{ - check_archived_root, - ser::{serializers::AllocSerializer, Serializer}, - Deserialize, + access, + api::high::to_bytes_in_with_alloc, + deserialize, + ser::{allocator::Arena, WriterExt}, + Archived, }; const TWASM_MAGIC_PREFIX: &[u8; 4] = b"TWAS"; -const TWASM_VERSION: &[u8; 2] = b"01"; +const TWASM_VERSION: &[u8; 2] = b"02"; #[rustfmt::skip] const TWASM_MAGIC: [u8; 16] = [ TWASM_MAGIC_PREFIX[0], TWASM_MAGIC_PREFIX[1], TWASM_MAGIC_PREFIX[2], TWASM_MAGIC_PREFIX[3], TWASM_VERSION[0], TWASM_VERSION[1], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; -pub use rkyv::AlignedVec; +pub use rkyv::util::AlignedVec; fn validate_magic(wasm: &[u8]) -> Result { if wasm.len() < TWASM_MAGIC.len() || &wasm[..TWASM_MAGIC_PREFIX.len()] != TWASM_MAGIC_PREFIX { @@ -28,7 +30,7 @@ fn validate_magic(wasm: &[u8]) -> Result { Ok(TWASM_MAGIC.len()) } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum TwasmError { InvalidMagic, InvalidVersion, @@ -56,20 +58,21 @@ impl TinyWasmModule { /// Creates a `TinyWasmModule` from a slice of bytes. pub fn from_twasm(wasm: &[u8]) -> Result { let len = validate_magic(wasm)?; - let root = check_archived_root::(&wasm[len..]).map_err(|_e| TwasmError::InvalidArchive)?; - Ok(root.deserialize(&mut rkyv::Infallible).unwrap()) + let root = + access::, rkyv::rancor::Error>(&wasm[len..]).map_err(|_| TwasmError::InvalidArchive)?; + deserialize::(root).map_err(|_e| TwasmError::InvalidArchive) } /// Serializes the `TinyWasmModule` into a vector of bytes. /// `AlignedVec` can be deferenced as a slice of bytes and /// implements `io::Write` when the `std` feature is enabled. - pub fn serialize_twasm(&self) -> rkyv::AlignedVec { - let mut serializer = AllocSerializer::<0>::default(); - serializer.pad(TWASM_MAGIC.len()).unwrap(); - serializer.serialize_value(self).unwrap(); - let mut out = serializer.into_serializer().into_inner(); - out[..TWASM_MAGIC.len()].copy_from_slice(&TWASM_MAGIC); - out + pub fn serialize_twasm(&self) -> AlignedVec { + let mut arena = Arena::new(); + let mut bytes = AlignedVec::new(); + >::pad(&mut bytes, TWASM_MAGIC.len()).unwrap(); + let mut bytes = to_bytes_in_with_alloc::<_, _, rkyv::rancor::Error>(self, bytes, arena.acquire()).unwrap(); + bytes[..TWASM_MAGIC.len()].copy_from_slice(&TWASM_MAGIC); + bytes } } @@ -84,4 +87,20 @@ mod tests { let wasm2 = TinyWasmModule::from_twasm(&twasm).unwrap(); assert_eq!(wasm, wasm2); } + + #[test] + fn test_invalid_magic() { + let wasm = TinyWasmModule::default(); + let mut twasm = wasm.serialize_twasm(); + twasm[0] = 0; + assert_eq!(TinyWasmModule::from_twasm(&twasm), Err(TwasmError::InvalidMagic)); + } + + #[test] + fn test_invalid_version() { + let wasm = TinyWasmModule::default(); + let mut twasm = wasm.serialize_twasm(); + twasm[4] = 0; + assert_eq!(TinyWasmModule::from_twasm(&twasm), Err(TwasmError::InvalidVersion)); + } } diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs index d77d66d..2030942 100644 --- a/crates/types/src/instructions.rs +++ b/crates/types/src/instructions.rs @@ -3,7 +3,7 @@ use crate::{DataAddr, ElemAddr, MemAddr}; /// Represents a memory immediate in a WebAssembly memory instruction. #[derive(Debug, Copy, Clone, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub struct MemoryArg { pub offset: u64, pub mem_addr: MemAddr, @@ -15,7 +15,7 @@ type EndOffset = u32; type ElseOffset = u32; #[derive(Debug, Clone, Copy, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub enum ConstInstruction { I32Const(i32), I64Const(i64), @@ -38,7 +38,7 @@ pub enum ConstInstruction { /// /// See #[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] // should be kept as small as possible (16 bytes max) #[rustfmt::skip] pub enum Instruction { diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index ce0d4ac..8ee044f 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -51,7 +51,7 @@ pub mod archive; /// `TinyWasmModules` are validated before being created, so they are guaranteed to be valid (as long as they were created by `TinyWasm`). /// This means you should not trust a `TinyWasmModule` created by a third party to be valid. #[derive(Debug, Clone, Default, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub struct TinyWasmModule { /// Optional address of the start function /// @@ -108,7 +108,7 @@ pub struct TinyWasmModule { /// /// See #[derive(Debug, Clone, Copy, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub enum ExternalKind { /// A WebAssembly Function. Func, @@ -179,14 +179,14 @@ impl ExternVal { /// /// See #[derive(Debug, Clone, PartialEq, Default)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub struct FuncType { pub params: Box<[ValType]>, pub results: Box<[ValType]>, } #[derive(Debug, Default, Clone, Copy, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub struct ValueCounts { pub c32: u32, pub c64: u32, @@ -195,7 +195,7 @@ pub struct ValueCounts { } #[derive(Debug, Default, Clone, Copy, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub struct ValueCountsSmall { pub c32: u16, pub c64: u16, @@ -204,7 +204,7 @@ pub struct ValueCountsSmall { } #[derive(Debug, Clone, PartialEq, Default)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub struct WasmFunction { pub instructions: Box<[Instruction]>, pub locals: ValueCounts, @@ -214,7 +214,7 @@ pub struct WasmFunction { /// A WebAssembly Module Export #[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub struct Export { /// The name of the export. pub name: Box, @@ -225,21 +225,21 @@ pub struct Export { } #[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub struct Global { pub ty: GlobalType, pub init: ConstInstruction, } #[derive(Debug, Clone, Copy, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub struct GlobalType { pub mutable: bool, pub ty: ValType, } #[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub struct TableType { pub element_type: ValType, pub size_initial: u32, @@ -258,7 +258,7 @@ impl TableType { /// Represents a memory's type. #[derive(Debug, Copy, Clone, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub struct MemoryType { arch: MemoryArch, page_count_initial: u64, @@ -297,14 +297,14 @@ impl MemoryType { } #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub enum MemoryArch { I32, I64, } #[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub struct Import { pub module: Box, pub name: Box, @@ -312,7 +312,7 @@ pub struct Import { } #[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub enum ImportKind { Function(TypeAddr), Table(TableType), @@ -333,7 +333,7 @@ impl From<&ImportKind> for ExternalKind { } #[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub struct Data { pub data: Box<[u8]>, pub range: Range, @@ -341,14 +341,14 @@ pub struct Data { } #[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub enum DataKind { Active { mem: MemAddr, offset: ConstInstruction }, Passive, } #[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub struct Element { pub kind: ElementKind, pub items: Box<[ElementItem]>, @@ -357,7 +357,7 @@ pub struct Element { } #[derive(Debug, Clone, Copy, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub enum ElementKind { Passive, Active { table: TableAddr, offset: ConstInstruction }, @@ -365,7 +365,7 @@ pub enum ElementKind { } #[derive(Debug, Clone, Copy, PartialEq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub enum ElementItem { Func(FuncAddr), Expr(ConstInstruction), diff --git a/crates/types/src/value.rs b/crates/types/src/value.rs index 825fa1f..8bbcaf2 100644 --- a/crates/types/src/value.rs +++ b/crates/types/src/value.rs @@ -182,7 +182,7 @@ impl WasmValue { /// Type of a WebAssembly value. #[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))] +#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] pub enum ValType { /// A 32-bit integer. I32, diff --git a/examples/rust/Cargo.toml b/examples/rust/Cargo.toml index f88fde4..af2391a 100644 --- a/examples/rust/Cargo.toml +++ b/examples/rust/Cargo.toml @@ -16,7 +16,7 @@ argon2={version="0.5"} [[bin]] name="hello" path="src/hello.rs" - + [[bin]] name="print" path="src/print.rs" diff --git a/examples/rust/build.sh b/examples/rust/build.sh index fcfd01c..ceb1de6 100755 --- a/examples/rust/build.sh +++ b/examples/rust/build.sh @@ -6,16 +6,17 @@ exclude_wat=("tinywasm") out_dir="./target/wasm32-unknown-unknown/wasm" dest_dir="out" -features="+reference-types,+bulk-memory,+mutable-globals" +rust_features="+reference-types,+bulk-memory,+mutable-globals,+multivalue,+sign-ext,+nontrapping-fptoint" +wasmopt_features="--enable-reference-types --enable-bulk-memory --enable-mutable-globals --enable-multivalue --enable-sign-ext --enable-nontrapping-float-to-int" # ensure out dir exists mkdir -p "$dest_dir" for bin in "${bins[@]}"; do - RUSTFLAGS="-C target-feature=$features -C panic=abort" cargo build --target wasm32-unknown-unknown --package rust-wasm-examples --profile=wasm --bin "$bin" + RUSTFLAGS="-C target-feature=$rust_features -C panic=abort" cargo build --target wasm32-unknown-unknown --package rust-wasm-examples --profile=wasm --bin "$bin" cp "$out_dir/$bin.wasm" "$dest_dir/" - wasm-opt "$dest_dir/$bin.wasm" -o "$dest_dir/$bin.opt.wasm" -O3 --enable-bulk-memory --enable-reference-types --enable-mutable-globals + wasm-opt "$dest_dir/$bin.wasm" -o "$dest_dir/$bin.opt.wasm" -O3 $wasmopt_features if [[ ! " ${exclude_wat[@]} " =~ " $bin " ]]; then wasm2wat "$dest_dir/$bin.wasm" -o "$dest_dir/$bin.wat"