From 461126ce309f99e4ad2a6ddcbc175ea01c5e8fee Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Fri, 26 Jan 2024 01:26:09 +0100 Subject: feat: full no_std support Signed-off-by: Henry Gressmann --- .github/workflows/test.yaml | 4 +- Cargo.lock | 101 +++++++++++++++++++++ Cargo.toml | 10 +- README.md | 2 +- crates/parser/src/conversion.rs | 6 +- crates/parser/src/lib.rs | 2 + crates/parser/src/module.rs | 4 +- crates/tinywasm/Cargo.toml | 1 + crates/tinywasm/src/func.rs | 6 +- crates/tinywasm/src/imports.rs | 2 +- crates/tinywasm/src/instance.rs | 5 +- crates/tinywasm/src/lib.rs | 6 ++ crates/tinywasm/src/runtime/interpreter/mod.rs | 12 ++- .../src/runtime/interpreter/no_std_floats.rs | 77 ++++++++++++++++ crates/tinywasm/src/runtime/interpreter/traits.rs | 3 + crates/tinywasm/src/runtime/stack/call_stack.rs | 1 + crates/tinywasm/src/runtime/stack/value_stack.rs | 1 + crates/tinywasm/src/store.rs | 8 +- crates/types/src/lib.rs | 19 ++-- examples/rust/Cargo.toml | 23 +++++ examples/rust/README.md | 1 + examples/rust/src/hello.rs | 18 ++++ examples/rust/src/tinywasm.rs | 41 +++++++++ examples/wasm-rust.rs | 41 +++++++++ 24 files changed, 363 insertions(+), 31 deletions(-) create mode 100644 crates/tinywasm/src/runtime/interpreter/no_std_floats.rs create mode 100644 examples/rust/Cargo.toml create mode 100644 examples/rust/README.md create mode 100644 examples/rust/src/hello.rs create mode 100644 examples/rust/src/tinywasm.rs create mode 100644 examples/wasm-rust.rs diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 41dd979..92d56f4 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -41,10 +41,10 @@ jobs: run: rustup update nightly - name: Build (nightly, no default features) - run: cargo +nightly build --workspace --exclude wasm-testsuite --no-default-features + run: cargo +nightly build --workspace --exclude wasm-testsuite --exclude rust-wasm-examples --no-default-features - name: Run tests (nightly, no default features) - run: cargo +nightly test --workspace --exclude wasm-testsuite --no-default-features + run: cargo +nightly test --workspace --exclude wasm-testsuite --exclude rust-wasm-examples --no-default-features - name: Run MVP testsuite (nightly) run: cargo +nightly test-mvp diff --git a/Cargo.lock b/Cargo.lock index e13a9f1..84cd8cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -229,10 +229,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" dependencies = [ "backtrace", + "color-spantrace", "eyre", "indenter", "once_cell", "owo-colors 3.5.0", + "tracing-error", +] + +[[package]] +name = "color-spantrace" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2" +dependencies = [ + "once_cell", + "owo-colors 3.5.0", + "tracing-core", + "tracing-error", ] [[package]] @@ -684,6 +698,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + [[package]] name = "libredox" version = "0.0.1" @@ -778,6 +798,12 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + [[package]] name = "pkg-config" version = "0.3.29" @@ -1116,6 +1142,15 @@ dependencies = [ "digest", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "simd-adler32" version = "0.3.7" @@ -1185,6 +1220,16 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -1205,6 +1250,7 @@ name = "tinywasm" version = "0.3.0-alpha.0" dependencies = [ "eyre", + "libm", "log", "owo-colors 4.0.0", "plotters", @@ -1238,6 +1284,14 @@ dependencies = [ "wasmparser-nostd", ] +[[package]] +name = "tinywasm-root" +version = "0.0.0" +dependencies = [ + "color-eyre", + "tinywasm", +] + [[package]] name = "tinywasm-types" version = "0.3.0-alpha.0" @@ -1246,6 +1300,47 @@ dependencies = [ "rkyv", ] +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-error" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" +dependencies = [ + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "sharded-slab", + "thread_local", + "tracing-core", +] + [[package]] name = "ttf-parser" version = "0.17.1" @@ -1276,6 +1371,12 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 0d5f97b..2be4dcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,5 @@ [workspace] members=["crates/*"] -default-members=["crates/cli"] resolver="2" [workspace.package] @@ -9,3 +8,12 @@ edition="2021" license="MIT OR Apache-2.0" authors=["Henry Gressmann "] repository="https://github.com/explodingcamera/tinywasm" + +[package] +name="tinywasm-root" +publish=false +edition="2021" + +[dev-dependencies] +color-eyre="0.6" +tinywasm={path="crates/tinywasm"} diff --git a/README.md b/README.md index ac755c7..3197cf1 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ $ cargo add tinywasm - **`parser`**\ Enables the `tinywasm-parser` crate. This is enabled by default. -With all these features disabled, TinyWasm does not depend on any external crates and can be used in `no_std` environments. +With all these features disabled, TinyWasm only depends on `core`, `alloc` and `libm` and can be used in `no_std` environments.