For fun I made this project to compile a bunch of different programming languages to WebAssembly and run all of the generated WASM using the wasmi library.
Each language test generates a standalone WASM binary that has a shared WASM function that can be called from wasmi by the test runner.
Disclaimer
This project is not associated with the wasmi project and is merely for researching how WebAssembly can be just another abstraction in any project.
Parity Technologies are developing/using WebAssembly with wasmi as a target for their smart cryptocurrency contracts but WebAssembly potentially has other uses cases than cryptocurrency or the web.
The languages currently supported are the following.
- C
- C++
- Rust
Any language that supports compiling to WebAssembly should be able to complete the tests.
For Rust WebAssembly can be generated using nightly Rust with the following command.
cargo +nightly build --target wasm32-unknown-unknown --release
For further assistance with setting up the Rust environment for compiling WebAssembly see this old but functional walkthrough
Install Emscripten to install the C/C++ -> WASM tools and then run make
in the respective folder for each language tests.
Add Simple addition function with the following form
a + b
Factorial Factorial function with the following form
if n > 1 {
return n * factorial(n - 1);
} else {
return 1;
}
The wasm-runner cargo project in the repository root when executed will recursively find any wasm modules in the 'generated' folder and, if they are named appropriately, run the matching test on it.
For Example:
generated/rust/factorial.wasm
will be executed by test function factorial_test
in the runner
generated/rust/add.wasm
will be executed by test function add_test
in the runner