From 8e065ba9557e1e6c591c6b877823d93dc75d748d Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Mon, 4 Dec 2023 02:19:31 +0100 Subject: fix: wat feature flag, ensure wasm target compiles Signed-off-by: Henry Gressmann --- .gitignore | 3 ++- README.md | 3 ++- crates/cli/Cargo.toml | 4 ++-- crates/cli/bin.rs | 9 +++++++++ crates/tinywasm/Cargo.toml | 2 ++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 85d7b07..0d6dc9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -notes.md \ No newline at end of file +notes.md +examples/tinywasm.wat \ No newline at end of file diff --git a/README.md b/README.md index 4548033..f105a8d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,8 @@ # 🎯 Goals -* Interpreted Runtime +* Interpreted Runtime (no JIT) +* Self-hosted (can run itself compiled to WebAssembly) * No unsafe code * Works on `no_std` (with `alloc` the feature and nightly compiler) * Fully support WebAssembly MVP (1.0) diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 505b025..dfb418a 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -18,5 +18,5 @@ pretty_env_logger="0.5" wast={version="69.0", optional=true} [features] -default=["wast"] -wast=["dep:wast"] +default=["wat"] +wat=["dep:wast"] diff --git a/crates/cli/bin.rs b/crates/cli/bin.rs index a067ca8..f8b0e1e 100644 --- a/crates/cli/bin.rs +++ b/crates/cli/bin.rs @@ -5,6 +5,8 @@ use color_eyre::eyre::Result; use log::info; use tinywasm::{self, Module, WasmValue}; mod util; + +#[cfg(feature = "wat")] mod wat; #[derive(FromArgs)] @@ -75,11 +77,18 @@ fn main() -> Result<()> { TinyWasmSubcommand::Run(Run { wasm_file, engine }) => { let path = cwd.join(wasm_file.clone()); let module = match wasm_file.ends_with(".wat") { + #[cfg(feature = "wat")] true => { let wat = std::fs::read_to_string(path)?; let wasm = wat::wat2wasm(&wat); tinywasm::Module::parse_bytes(&wasm)? } + #[cfg(not(feature = "wat"))] + true => { + return Err(color_eyre::eyre::eyre!( + "wat support is not enabled, please enable it with --features wat" + )) + } false => tinywasm::Module::parse_file(path)?, }; diff --git a/crates/tinywasm/Cargo.toml b/crates/tinywasm/Cargo.toml index b54ef8b..acd6736 100644 --- a/crates/tinywasm/Cargo.toml +++ b/crates/tinywasm/Cargo.toml @@ -4,7 +4,9 @@ version="0.0.0" edition="2021" [lib] +name="tinywasm" path="src/lib.rs" +crate-type=["cdylib", "rlib"] [dependencies] log="0.4.20" -- cgit v1.3.1