feat: add WASI Preview 1 stubs for wasip1-targeting languages#4641
Open
djgilcrease wants to merge 2 commits intoclockworklabs:masterfrom
Open
feat: add WASI Preview 1 stubs for wasip1-targeting languages#4641djgilcrease wants to merge 2 commits intoclockworklabs:masterfrom
djgilcrease wants to merge 2 commits intoclockworklabs:masterfrom
Conversation
Add minimal WASI function stubs (fd_write, clock_time_get, random_get, etc.) so that modules compiled to `wasip1` (e.g. Go with `-buildmode=c-shared`) can run in SpacetimeDB's wasmtime runtime. This includes: - wasi_stubs.rs: stub implementations for wasi_snapshot_preview1 imports - Linking the stubs into the wasmtime linker - Calling `_initialize`/`_start` exports before other module exports to initialize the language runtime (WASI reactor/command convention) These changes are additive — existing Rust/C# modules are unaffected since they don't import WASI functions or export `_initialize`/`_start`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Changes
Summary
Add minimal WASI Preview 1 stub implementations so that modules compiled to
wasip1(e.g. Go with-buildmode=c-shared) can be instantiated and run in SpacetimeDB's wasmtimeruntime.
wasi_stubs.rswith stub implementations forwasi_snapshot_preview1imports (fd_write,clock_time_get,random_get,proc_exit,args_sizes_get,environ_sizes_get,sched_yield, etc.)_initialize/_startexports (WASI reactor/command convention) before preinit functions to initialize the guest language runtimeWhy
Languages like Go use
//go:wasmimportfor WASI functions, which must be satisfied by the host. Without these stubs, wasmtime fails to instantiatewasip1-targeting modules becausethe
wasi_snapshot_preview1imports are unresolved. The C++ SDK handles this differently by embedding shims in the compiled module itself(
crates/bindings-cpp/src/abi/wasi_shims.cpp), but Go (and potentially other languages) require host-side stubs.This is a prerequisite for the Go server SDK but is language-agnostic — any
wasip1-targeting language benefits from these stubs.This can also replace the stubs that were added separately for C # and C++, so those and Go can all share the same stubs. I did not update the C# and cpp modules to use these stubs in this MR as I want it to be as minimal as possible so I could start using my go server module asap.
What the stubs do
fd_writelog::info!/log::warn!)clock_time_getrandom_getargs_sizes_get/args_getenviron_sizes_get/environ_getpoll_oneoffproc_exit/sched_yieldfd_close/fd_seek/fd_read/fd_fdstat_get/fd_fdstat_set_flags/fd_prestat_get/fd_prestat_dir_nameERRNO_BADForERRNO_NOSYSImpact on existing modules
None. These changes are purely additive:
wasi_snapshot_preview1namespace, which existing Rust/C# modules don't import_initialize/_startdetection is a no-op for modules that don't export themAPI and ABI breaking changes
None
Expected complexity level and risk
1 - very low complexity and risk, the stubs are not used by anything, BUT will enable me to externalize a go-sdk for server modules
Testing
ran the full test suite locally