Commit 36fb419
wasip2: build against wasi-libc instead of the Go mini-libc
Wasip2 previously got its libc from a ~1300-line hand-written Go
implementation (src/syscall/libc_wasip2.go) calling wasi:cli/filesystem/io
component bindings directly. wasi-libc upstream already ships a C
implementation of the same wasip2 surface (wasip2.c, wasip2_stdio.c,
descriptor_table.c, socket support), generated from the same WIT
interfaces, so link wasip2 against that instead.
- builder/wasilibc.go: turn libWasiLibc into a newWasiLibc(preview, name)
factory. libWasiLibcWasip2 builds with __wasip2__ defined and the
descriptor-table-based socket/stdio sources instead of wasip1's
cloudlibc syscalls. Distinct library name since the build cache is
keyed by name+triple and both targets share the same wasm32 triple.
- builder/build.go / targets/wasip2.json: route the "wasi-libc" case to
the wasip2 variant when the wasip2 build tag is set.
- src/syscall/syscall_libc.go and syscall_libc_wasi.go were already
shared between wasip1/wasip2 (linker-resolved //export symbols), so
they needed no changes. env_libc.go/errno_wasilibc.go are now shared
too; the wasip2-only mini-libc files are deleted.
- Environ() needed to move to wasip1/wasip2-specific files
(environ_libc.go / environ_wasip2.go): wasi-libc's eager,
constructor-based environ population is fine for wasip1 (a plain core
wasm module) but traps under wasip2's component model when it fires
reentrantly during cabi_realloc ("cannot leave component instance").
wasip2 uses wasi-libc's documented lazy __wasilibc_get_environ()
accessor instead.
- runtime_wasip2.go: cabi_realloc now goes through the malloc-tracked
libc_realloc instead of the GC-internal realloc, since wasi-libc's C
code (e.g. wasip2_string_free) frees buffers allocated during
component-ABI lifting with a plain free().
- lib/wasi-libc-wasip2-stub.c: satisfies wasip2.c's forced-link
reference to wasi-libc's own crt1 component-type metadata, which
TinyGo doesn't build (it provides its own entry points and its own
component-embedding step).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent 657e1dc commit 36fb419
16 files changed
Lines changed: 396 additions & 1697 deletions
File tree
- builder
- compileopts
- lib
- src
- runtime
- syscall
- targets
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
171 | 175 | | |
172 | 176 | | |
173 | 177 | | |
| |||
0 commit comments