Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to create plain WASM module with .NET 8

I would like to write some of my application logic in C# and be able to update (sideload) it after deploying the host application. Since WASM support has further improved with .NET 8, I considered to package up my application code into a WASM module and execute it securely in a WASM sandbox. I specifically don't require WASI support which could introduce security issues.

Is that at all possible with the current wasm-tools workload or other tooling?

How would I annotate C# functions to be exported from the WASM module?

Is there a minimal working example that replicates e.g. this gct.wat code in C#? https://docs.wasmtime.dev/examples-c-gcd.html

I tried to use the wasmconsole and wasmbrowser project templates but both of them yield .wasm modules that have dependencies on additional external functions from either the browser or wasi interfaces.

like image 354
Robert Schmid Avatar asked Oct 16 '25 20:10

Robert Schmid


1 Answers

Its experimental, but https://github.com/dotnet/runtimelab/blob/feature/NativeAOT-LLVM/docs/using-nativeaot/compiling.md#webassembly will build plain wasm modules. To export functions, use UnmanagedCallersOnly attribute.

like image 115
S Waye Avatar answered Oct 19 '25 09:10

S Waye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!