Hi
I was trying to integrate two apps one simple rust program, which prints a line and another go program which prints a line. I am trying to integrate the two apps into wasmtime and here is my main.rs file which is located in src folder
use anyhow::Result;
use wasi_cap_std_sync::WasiCtxBuilder;
use wasmtime::*;
fn main() -> Result<()> {
// Define the WASI functions globally on the `Config`.
let engine = Engine::default();
let mut linker = Linker::new(&engine);
wasmtime_wasi::add_to_linker(&mut linker, |s| s)?;
// Create a WASI context and put it in a Store; all instances in the store
// share this context. `WasiCtxBuilder` provides a number of ways to
// configure what the target program will have access to.
let wasi = WasiCtxBuilder::new()
.inherit_stdio()
.inherit_args()?
.build();
let mut store = Store::new(&engine, wasi);
// Load our WebAssembly modules.
let module_rust_app = Module::from_file(&engine, "/Users/celinesantosh/Desktop/sem_5/rust_app/target/wasm32-wasi/release/rust_app.wasm")?;
let module_go_app = Module::from_file(&engine, "/Users/celinesantosh/Desktop/sem_5/go_program/go_app.wasm")?;
// Instantiate the Rust app module.
let instance_rust_app = linker.instantiate(&mut store, &module_rust_app)?;
// Instantiate the Go app module.
let instance_go_app = linker.instantiate(&mut store, &module_go_app)?;
// Get the `_start` function from the Rust app instance.
let start_rust_app = instance_rust_app.get_typed_func::<(), ()>(&mut store, "_start")?;
// Get the `_start` function from the Go app instance.
let start_go_app = instance_go_app.get_typed_func::<(), ()>(&mut store, "_start")?;
// Call the `_start` function on both modules.
start_rust_app.call(&mut store, ())?;
start_go_app.call(&mut store, ())?;
Ok(())
}
But I am getting an issue while building
error: failed to run custom build command for cranelift-codegen v0.111.0 (/Users/celinesantosh/Desktop/sem_5/wasmtime_dev/cranelift/codegen)
Caused by:
process didn't exit successfully: /Users/celinesantosh/Desktop/sem_5/wasmtime_dev/target/release/build/cranelift-codegen-4791549fd0e2d9a3/build-script-build
(exit status: 101)
--- stderr
thread 'main' panicked at cranelift/codegen/build.rs:50:53:
error when identifying target: "no supported isa found for arch wasm32
"
note: run with RUST_BACKTRACE=1
environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
The following warnings were emitted during compilation:
warning: zstd-sys@2.0.9+zstd.1.5.5: error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-wasi"'
warning: zstd-sys@2.0.9+zstd.1.5.5: 1 error generated.
warning: zstd-sys@2.0.9+zstd.1.5.5: ToolExecError: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-wasi" "-I" "wasm-shim/" "-I" "zstd/lib/" "-I" "zstd/lib/common" "-fvisibility=hidden" "-DXXH_STATIC_ASSERT=0" "-DZSTD_LIB_DEPRECATED=0" "-DXXH_PRIVATE_API=" "-DZSTDLIB_VISIBILITY=" "-DZSTDERRORLIB_VISIBILITY=" "-o" "/Users/celinesantosh/Desktop/sem_5/wasmtime_dev/target/wasm32-wasi/release/build/zstd-sys-83613bc565f26643/out/zstd/lib/common/debug.o" "-c" "zstd/lib/common/debug.c" with args "clang" did not execute successfully (status code exit status: 1).running: "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-wasi" "-I" "wasm-shim/" "-I" "zstd/lib/" "-I" "zstd/lib/common" "-fvisibility=hidden" "-DXXH_STATIC_ASSERT=0" "-DZSTD_LIB_DEPRECATED=0" "-DXXH_PRIVATE_API=" "-DZSTDLIB_VISIBILITY=" "-DZSTDERRORLIB_VISIBILITY=" "-o" "/Users/celinesantosh/Desktop/sem_5/wasmtime_dev/target/wasm32-wasi/release/build/zstd-sys-83613bc565f26643/out/zstd/lib/common/entropy_common.o" "-c" "zstd/lib/common/entropy_common.c"
warning: zstd-sys@2.0.9+zstd.1.5.5: error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-wasi"'
warning: zstd-sys@2.0.9+zstd.1.5.5: 1 error generated.
warning: zstd-sys@2.0.9+zstd.1.5.5: error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-wasi"'
warning: zstd-sys@2.0.9+zstd.1.5.5: 1 error generated.
warning: zstd-sys@2.0.9+zstd.1.5.5: ToolExecError: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-wasi" "-I" "wasm-shim/" "-I" "zstd/lib/" "-I" "zstd/lib/common" "-fvisibility=hidden" "-DXXH_STATIC_ASSERT=0" "-DZSTD_LIB_DEPRECATED=0" "-DXXH_PRIVATE_API=" "-DZSTDLIB_VISIBILITY=" "-DZSTDERRORLIB_VISIBILITY=" "-o" "/Users/celinesantosh/Desktop/sem_5/wasmtime_dev/target/wasm32-wasi/release/build/zstd-sys-83613bc565f26643/out/zstd/lib/common/entropy_common.o" "-c" "zstd/lib/common/entropy_common.c" with args "clang" did not execute successfully (status code exit status: 1).
Any help would be appreciated
Thanks
It looks like you have the target set to wasm32 for your host program, not just your guest programs. This could be either passed as e.g. cargo build --target wasm32-wasi
or set by a config file e.g. .cargo/config.toml
.
Thanks .
Now I can build successfully, but while running I am getting an error
(base) celinesantosh@celines-MacBook-Air-2 celine_app % cargo run
Compiling celine_app v0.1.0 (/Users/celinesantosh/Desktop/sem_5/wasmtime_dev/examples/celine_app)
Finished dev
profile [unoptimized + debuginfo] target(s) in 2.94s
Running /Users/celinesantosh/Desktop/sem_5/wasmtime_dev/target/debug/celine_app
Error: unknown import: gojs::runtime.scheduleTimeoutEvent
has not been defined
Thanks .. I have solved it now
Last updated: Nov 22 2024 at 16:03 UTC