Testing wasm module with Rust?

I am writing WAT code (WASM text format) and compile this code with wat2wasm from the wabt toolset to generate a binary module.

I'm trying to find ways to write test code for this module in a higher level language (preferably not JS). So I was aondering if there is a way to write test code for this module in Rust, compile the test code in WASM, link it with the wasm module to be tested. All this with Rust and Rust tools.

Thank you!

i think this is possible with a build.rs in the rust wasm project, that emits instructions to link in the manually assembled wasm library e.g.

    let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
    let name = "....";
        format!("bin/{}.wasm", target),
        out_dir.join(format!("lib{}.wasm", name)),
    println!("cargo:rustc-link-lib=static={}", name);

alternatively, a test harness could use a rust-based wasm interpreter like wasmi to emulate and test the webassembly code

@vmedea, thank you for the tip. I'm going to give it a try. In the meantime I also discovered that wasmer in addition to being a fast runtime offers APIs in a variety of languages (Go, Ruby, ...) and you can litterally drive the WASM VM from outside the box. Very handy to build a test frame work.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.