Commit eac68b21 authored by Guy Watson's avatar Guy Watson
Browse files

Add support for wasmtime

parent 1851bbcc
......@@ -17,19 +17,19 @@ lazy_static = "1.4.0"
structopt = "0.3.21"
### Enable these for use on the testing machines (for fresh-built from source)
wasmer = { path = "/local/work/wasmer/lib/api" }
wasmer-compiler-singlepass = { path = "/local/work/wasmer/lib/compiler-singlepass" }
wasmer-compiler-cranelift = { path = "/local/work/wasmer/lib/compiler-cranelift" }
wasmer-compiler-llvm = { path = "/local/work/wasmer/lib/compiler-llvm" }
wasmer-engine-universal = { path = "/local/work/wasmer/lib/engine-universal", features = ["compiler"] }
wasmer-engine-dylib = { path = "/local/work/wasmer/lib/engine-dylib", features = ["compiler"] }
wasmer-engine-staticlib = { path = "/local/work/wasmer/lib/engine-staticlib", features = ["compiler"] }
# wasmer = { path = "/local/work/wasmer/lib/api" }
# wasmer-compiler-singlepass = { path = "/local/work/wasmer/lib/compiler-singlepass" }
# wasmer-compiler-cranelift = { path = "/local/work/wasmer/lib/compiler-cranelift" }
# wasmer-compiler-llvm = { path = "/local/work/wasmer/lib/compiler-llvm" }
# wasmer-engine-universal = { path = "/local/work/wasmer/lib/engine-universal", features = ["compiler"] }
# wasmer-engine-dylib = { path = "/local/work/wasmer/lib/engine-dylib", features = ["compiler"] }
# wasmer-engine-staticlib = { path = "/local/work/wasmer/lib/engine-staticlib", features = ["compiler"] }
### Enable these for local development with an already set up rust environment
# wasmer = { version = "2.0.0" }
# wasmer-compiler-singlepass = { version = "2.0.0" }
# wasmer-compiler-cranelift = { version = "2.0.0" }
# wasmer-compiler-llvm = { version = "2.0.0" }
# wasmer-engine-universal = { version = "2.0.0", features = ["compiler"] }
# wasmer-engine-dylib = { version = "2.0.0", features = ["compiler"] }
# wasmer-engine-staticlib = { version = "2.0.0", features = ["compiler"] }
wasmer = { version = "2.0.0" }
wasmer-compiler-singlepass = { version = "2.0.0" }
wasmer-compiler-cranelift = { version = "2.0.0" }
wasmer-compiler-llvm = { version = "2.0.0" }
wasmer-engine-universal = { version = "2.0.0", features = ["compiler"] }
wasmer-engine-dylib = { version = "2.0.0", features = ["compiler"] }
wasmer-engine-staticlib = { version = "2.0.0", features = ["compiler"] }
......@@ -8,3 +8,5 @@ edition = "2021"
[dependencies]
wasmtime = "0.31.0"
structopt = "0.3.25"
crc = "2.1.0"
anyhow = "1.0.51"
use std::convert::TryInto;
use std::fs;
use structopt::StructOpt;
use crc::{Crc, CRC_32_ISO_HDLC};
......@@ -141,7 +140,7 @@ fn main() -> anyhow::Result<()> {
// Env { digest: shared_digest.clone() }, // These clones clone the Arc, not the underlying data
// add_to_crc
// );
let add_to_crc_func = Func::wrap(&store, |mut caller: Caller<'_, Env>, val: u32| {
let add_to_crc_func = Func::wrap(&mut store, |caller: Caller<'_, Env>, val: u32| {
add_to_crc(caller.data(), val);
});
......@@ -162,16 +161,16 @@ fn main() -> anyhow::Result<()> {
// let main_func: NativeFunc<(), i32> = instance.exports.get_native_function("_main")?;
// let crc_globals_func: NativeFunc<(), ()> = instance.exports.get_native_function("_crc_globals")?;
// let memory = instance.exports.get_memory("_memory")?;
let main_func = instance.get_typed_func::<(), i32, _>(&store, "_main")?;
let crc_globals_func = instance.get_typed_func::<(), (), _>(&store, "_crc_globals")?;
let memory = instance.get_memory(&store, "_memory")?;
let main_func = instance.get_typed_func::<(), i32, _>(&mut store, "_main")?;
let crc_globals_func = instance.get_typed_func::<(), (), _>(&mut store, "_crc_globals")?;
let memory = instance.get_memory(&mut store, "_memory").unwrap();
// Call main and add the result to the crc
let main_result: i32 = main_func.call(&mut store, ())?;
add_to_crc(&Env{ digest: shared_digest.clone() },main_result.into());
add_to_crc(&Env{ digest: shared_digest.clone() },main_result as u32);
// Call the crc globals function to have wasm add all of it's globals to the crc
crc_globals_func.call(&store, ())?;
crc_globals_func.call(&mut store, ())?;
// Add the contents of memory to the crc
// Get the pointer and size in bytes
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment