-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WASM that runs in wasmtime will not run in the library #278
Comments
It looks like you need to enable WASI for this code to work. |
@martindevans thank you so much - I closed this when I realized what a bonehead I was... that said, since you were kind enough to respond, I wonder if you could answer a followup... I have this multi-threaded C code:
I compile it thusly:
I can then run it without issue:
However, even after (I think) enabling threads in this C# code, it fails:
on the linker.Instantiate line, I get error:
Any ideas or tips you could give me? |
I really don't know a lot about WASI threads, the following is from some very quick research I just did right now and could definitely be wrong! It looks like a WASI threads program imports a "shared memory" called Wasmtime has a However looking through the Wasmtime C-API (which is what wasmtime-dotnet uses to interact with wasmtime) I don't see a mention of the word "shared" anywhere in memory.h or wasi.h. It's possible this can't be done through the C-API. |
To follow up to that, there's this comment in Config.h:
|
I have a similar issue. An unhandled exception occurred when I ran it from C#. // zig build-exe main.zig -target wasm32-wasi -OReleaseSmall
const std = @import("std");
pub fn main() void {
std.debug.print("wasm: Hello, world!\n", .{});
} Console.WriteLine("Hello, World!");
var resourceStream = await Assembly.GetExecutingAssembly().ReadResourceAsync("main.wasm");
var wasiConfig = new WasiConfiguration()
.WithInheritedStandardInput()
.WithInheritedStandardOutput()
.WithInheritedStandardError()
.WithInheritedArgs()
.WithInheritedEnvironment();
using var config = new Config()
.WithDebugInfo(true)
.WithCraneliftDebugVerifier(true)
.WithOptimizationLevel(OptimizationLevel.SpeedAndSize)
.WithWasmThreads(true)
.WithBulkMemory(true)
.WithMultiMemory(true);
using var engine = new Engine(config);
using var linker = new Linker(engine);
using var store = new Store(engine);
using var module = Wasmtime.Module.FromStream(engine, "main.wasm", resourceStream);
store.SetWasiConfiguration(wasiConfig);
linker.DefineWasi();
linker.DefineModule(store,module);
var instance = linker.Instantiate(store, module);
instance.GetAction("_start")?.Invoke(); // line 44 here Output:
The wat is: (module
(type $t0 (func (param i32)))
(type $t1 (func (param i32 i32 i32 i32) (result i32)))
(type $t2 (func))
(import "wasi_snapshot_preview1" "proc_exit" (func $wasi_snapshot_preview1.proc_exit (type $t0)))
(import "wasi_snapshot_preview1" "fd_write" (func $wasi_snapshot_preview1.fd_write (type $t1)))
(func $_start (export "_start") (type $t2)
(call $f3)
(call $wasi_snapshot_preview1.proc_exit
(i32.const 0))
(unreachable))
(func $f3 (type $t2)
(local $l0 i32) (local $l1 i32)
(global.set $g0
(local.tee $l0
(i32.sub
(global.get $g0)
(i32.const 16))))
(local.set $l1
(i32.const 0))
(block $B0
(br_if $B0
(i32.load8_u offset=1048597
(i32.const 0)))
(i32.store8 offset=1048597
(i32.const 0)
(i32.const 1)))
(block $B1
(loop $L2
(br_if $B1
(i32.eq
(local.get $l1)
(i32.const 20)))
(i32.store offset=8
(local.get $l0)
(i32.sub
(i32.const 20)
(local.get $l1)))
(i32.store offset=4
(local.get $l0)
(i32.add
(local.get $l1)
(i32.const 1048576)))
(br_if $B1
(i32.and
(call $wasi_snapshot_preview1.fd_write
(i32.const 2)
(i32.add
(local.get $l0)
(i32.const 4))
(i32.const 1)
(i32.add
(local.get $l0)
(i32.const 12)))
(i32.const 65535)))
(local.set $l1
(i32.add
(i32.load offset=12
(local.get $l0))
(local.get $l1)))
(br $L2)))
(i32.store8 offset=1048597
(i32.const 0)
(i32.const 0))
(global.set $g0
(i32.add
(local.get $l0)
(i32.const 16))))
(memory $memory (export "memory") 17)
(global $g0 (mut i32) (i32.const 1048576))
(data $d0 (i32.const 1048576) "wasm: Hello, world!\0a\00"))
|
Hi @peaceshi. When running a WASI program with the .NET bindings, you'll want to catch
It's a little unfortunate that Zig is calling |
Hello, I have a Rust hello world app:
I compile it:
and can run it in wasmtime
wasmtime run hello-world.wasm
without issue. However, when I run it in my C# app:and I get this error:
any thoughts?
The text was updated successfully, but these errors were encountered: