diff --git a/.gitignore b/.gitignore index a19894a8a..ada91db4c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ debug/ target/ target-tarpaulin/ target-custom/ +venv/ # These are backup files generated by rustfmt **/*.rs.bk diff --git a/Cargo.toml b/Cargo.toml index da1b4bea9..547eded86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ # the part of this workspace [workspace] -exclude = ["sdk"] +exclude = ["sdk", "ws2riscvtest"] members = [ "circuits", "cli", @@ -32,6 +32,7 @@ resolver = "2" [profile.dev] lto = "thin" # We are running our tests with optimizations turned on to make them faster. + # Please turn optimizations off, when you want accurate stack traces for debugging. opt-level = 2 diff --git a/ws2riscvtest/Cargo.toml b/ws2riscvtest/Cargo.toml new file mode 100644 index 000000000..a992abd01 --- /dev/null +++ b/ws2riscvtest/Cargo.toml @@ -0,0 +1,10 @@ +[package] +edition = "2021" +name = "ws2riscvtest" +version = "0.1.0" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +wasm-bindgen = "0.2" diff --git a/ws2riscvtest/README.md b/ws2riscvtest/README.md new file mode 100644 index 000000000..664faef72 --- /dev/null +++ b/ws2riscvtest/README.md @@ -0,0 +1,27 @@ +# What +This directory aims at testing if we can convert a WASM binary to RISC-V target and make it run well on `mozak-vm`. We simulate a naive implementation of Fibonacci for this. + +## Building and testing a WASM module +We need `wasm-pack` via +``` +cargo install wasm-pack +``` + +Inside the directory `wasmtest`, we build a WASM module via: +``` +wasm-pack build --target web +``` +This builds binary for the target `wasm-unknown-unknown` + +This would build artifacts accessible in the directory `./pkg`. Most importantly, these files would be generated: +1. `pkg/ws2riscvtest_bg.wasm`, the WASM binary file. +2. `pkg/ws2riscvtest.js`, the JS file required to run WASM code in browser + +Run a dummy testing server (on port 8000 by default) via: +``` +python3 -m http.server +``` +and load up `http://localhost:8000/` in the browser. The correct run should output: +``` +WASM TESTER! Function result: 34 +``` diff --git a/ws2riscvtest/index.html b/ws2riscvtest/index.html new file mode 100644 index 000000000..edd0402f2 --- /dev/null +++ b/ws2riscvtest/index.html @@ -0,0 +1,9 @@ + + +
+ +