## Summary - Update the experimental NativeAOT-LLVM build path (`EXPERIMENTAL_WASM_AOT=1`) to include all host function imports from ABI versions 10.0 through 10.4 - Fix the compiler package reference to work on both Windows x64 and Linux x64 (was hardcoded to Windows only) - Add a CI smoketest to verify AOT builds work on Linux x64 ## Context See #4514 for the full writeup on the C# AOT situation. The `wasi-experimental` workload that all C# module builds depend on is deprecated and removed from .NET 9+. NativeAOT-LLVM is the recommended path forward for ahead-of-time compilation of C# to WebAssembly. The existing NativeAOT-LLVM support (added by RReverser in #713) was stale: missing imports added since then and a Windows-only package reference. ## Changes **`SpacetimeDB.Runtime.targets`:** - Add 10 missing `WasmImport` declarations across spacetime_10.0 through 10.4 - Replace `runtime.win-x64.Microsoft.DotNet.ILCompiler.LLVM` with `runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM` so it resolves correctly on Linux x64 as well - Use explicit version strings instead of the `$(SpacetimeNamespace)` variable **`ci.yml`:** - Add AOT build smoketest step in the `csharp-testsuite` job ## Test plan - [x] CI smoketest passes: `EXPERIMENTAL_WASM_AOT=1 dotnet publish -c Release` builds successfully on Linux x64 - [ ] Existing C# tests continue to pass (no changes to the default interpreter path) --------- Signed-off-by: Ryan <r.ekhoff@clockworklabs.io> Co-authored-by: Ryan <r.ekhoff@clockworklabs.io> Co-authored-by: Jason Larabie <jason@clockworklabs.io> Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
⚠️ Internal Project ⚠️
This project is intended for internal use only. It is not stable and may change without notice.
SpacetimeDB.Runtime
This project contains the runtime bindings for SpacetimeDB WebAssembly modules. See the C# module library reference for stable, user-facing documentation.
SpacetimeDB modules are compiled to WebAssembly modules that expose a specific interface; see the module ABI reference.
The runtime bindings are currently implementing via Wasi.Sdk package, which is a .NET implementation of the WASI standard. This is likely to change in the future.
While not really documented, it allows to build raw WebAssembly modules with custom bindings as well, which is what we're using here. The process is somewhat complicated, but here are the steps:
bindings.cdeclares raw C bindings to the SpacetimeDB FFI imports and marks them with attributes like__attribute__((import_module("spacetime"), import_name("_insert")))that make them WebAssembly imports. (unfortunately, function name duplication is currently unavoidable)bindings.cimplements a bunch of Mono-compatible wrappers that convert between Mono types and raw types expected by the SpacetimeDB FFI and invoke corresponding raw bindings.Runtime.csdeclares corresponding functions with compatible signatures for Mono-compatible wrappers to attach to. It marks them all with[MethodImpl(MethodImplOptions.InternalCall)].bindings.cattaches all those Mono-compatible wrappers to their C# declarations in amono_stdb_attach_bindingsfunction.bindings.cadds FFI-compatible exports that search for a method by assembly name, namespace, class name and a method name in the Mono runtime and invoke it. Those exports are marked with attributes like__attribute__((export_name("__call_reducer__")))so that they're exported from Wasm by the linker.- Finally,
bindings.cimplements no-op shims for all the WASI APIs so that they're linked internally and not attempted to be imported from the runtime itself.
The result is a WebAssembly module FFI-compatible with SpacetimeDB and with no WASI imports, which is what we need.
Regenerating RawModuleDef
To regenenerate the Autogen folder, run:
cargo run -p spacetimedb-codegen --example regen-csharp-moduledef
This folder contains the type definitions used to serialize the RawModuleDef that is returned by __describe_module__.