Skip to content

Commit

Permalink
fix: wat feature flag, ensure wasm target compiles
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
  • Loading branch information
explodingcamera committed Dec 4, 2023
1 parent 829db60 commit 8e065ba
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
notes.md
notes.md
examples/tinywasm.wat
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
9 changes: 9 additions & 0 deletions crates/cli/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)?,
};

Expand Down
2 changes: 2 additions & 0 deletions crates/tinywasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8e065ba

Please sign in to comment.