-
Notifications
You must be signed in to change notification settings - Fork 36
C#-only way to declare wasm imports and exports #30
Comments
There's any simpler example of how use export/import, when using the C? |
No, https://github.com/SteveSandersonMS/dotnet-wasi-sdk/blob/main/src/Wasi.AspNetCore.Server.CustomHost/native/server_interop.c is about as simple as it gets. That's why we should make a simpler mechanism with C# only. |
I understand the motivation to add C#-only. I'm trying to figure out how server_interop.c works. Just to make sure, I need to have the Mono toolchain and compile the |
No, you don't need Mono. No other build tools are needed. Just reference your |
@inkeliz: you might want to take a look at https://github.com/flavio/wapc-guest-dotnet/blob/main/src/WapcGuest/native/wapc_ffi.c I hope that helps! |
Thank you, @flavio. I think that will be very useful for any future readers. My primary concern was how to compile that, since I'm not familiar with C#/Dotnet, so I'm not sure how things are suppose to compile. 😅 I manage to use force the compilation including the |
Good, that's the right thing to do if you're just testing! Having |
Maybe the experimental LLVM-based approach could be a way forward...? |
``Hello, i do have an unresolved doubt: I tried, for ease of testing, to build a classlib with a generic method
and in another console project use wasmtime.net to load the module
but, debugging, module only exports the basic methods (malloc, free, _run, etc..), and run is null, meaning that the method is not exported. thanks to everyone in advance! |
I tried exporting wasi-wasm function by using ILCompiler.LLVM. And it worked. https://github.com/iwate/learn-wasm-with-dotnet/tree/main/challenge09/wasilib |
Currently to declare a custom WebAssembly
import
orexport
you have to write C code, e.g., https://github.com/SteveSandersonMS/dotnet-wasi-sdk/blob/main/src/Wasi.AspNetCore.Server.CustomHost/native/server_interop.c#L7-L17We should make it possible to declare such imports/exports using just C# only without any native code.
At a basic level this could be achieved fairly easily by codegenerating the equivalent C code that uses the Mono embedding APIs to invoke C#. However going further, we'd want to be able to receive and return nontrivial types, which probably involves a C# sourcegenerator for WIT.
The text was updated successfully, but these errors were encountered: