Repository navigation
feat: update README and WASM memory management for TinyGo compatibility - #11
Merged
Merged
Conversation
Contributor
Greptile SummaryThis PR updates the documented WASI build process for TinyGo and changes WASM memory management to avoid TinyGo allocator-export collisions.
Confidence Score: 3/5The PR should not merge until the allocator can hold simultaneously live request and response data and the documented standard Go minimum is corrected. A valid near-limit request can exhaust the newly reduced shared arena while its response is packed, and users on the newly advertised Go 1.21–1.23 range cannot build the documented standard-Go fallback. Files Needing Attention: wasm_backends.go, README.md
|
| Filename | Overview |
|---|---|
| wasm_backends.go | Reduces the shared bump-allocation arena to 1 MiB, which cannot hold a near-limit request and its response simultaneously. |
| wasm_exports.go | Renames allocator exports for TinyGo and retains the response allocation flow that shares the request arena until reset. |
| README.md | Adds useful TinyGo reactor guidance but incorrectly advertises the standard Go c-shared WASI path as supported from Go 1.21. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
H[Host] -->|paca_malloc request size| A[1 MiB bump arena]
H -->|write request| A
H -->|HandleRequest| P[Plugin handler]
P -->|serialize response| R[packWASMResult]
R -->|wasmMalloc response size| A
A -->|combined size exceeds 1 MiB| F[Allocation returns 0]
H -->|copy response, then ResetAllocator| X[Reset arena]
Reviews (1): Last reviewed commit: "feat: update README and WASM memory mana..." | Re-trigger Greptile
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
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.
Summary
Fixes plugin builds under TinyGo, which is the recommended compiler per the README but was previously broken in two ways when actually used against the host runtime.
wasm_exports.go: Export the SDK's allocator functions aspaca_malloc/paca_freeinstead ofmalloc/free. TinyGo's bundled wasi-libc already exports its ownmalloc/free, so exporting under the same names produced a WASM module with duplicate exports — invalid per spec and rejected at load time.wasm_backends.go: ShrinkmallocBufferfrom 10MB to 1MB to matchservices/api'sDefaultResourceLimits.MaxRequestBodyBytes(paca/services/api/internal/platform/plugin/runtime.go). The host already rejects any payload larger than that before writing to this buffer, so 10MB was unnecessary — and since every loaded plugin gets its own independent copy of this buffer, the smaller size meaningfully reduces the host's per-plugin memory footprint.README.md: Update the build instructions to usetinygo build -target=wasip1 -buildmode=c-shared.-buildmode=c-sharedis required, not optional — without it, TinyGo doesn't wire up the WASI reactor entry point (_initialize) this SDK's runtime depends on, and the plugin panics at load with"//go:wasmexport function called before runtime initialization"(it still compiles fine without the flag, so this only surfaces once the host actually loads the plugin). Also documents the standard-Go fallback for TinyGo stdlib gaps, and a required workaround (wrap in a closure) for plugins that declare their own//go:wasmimporthost function and pass it toCallHostFunction, since TinyGo doesn't support taking the address of ago:wasmimportfunction.Test plan
tinygo build -target=wasip1 -buildmode=c-sharedand confirm it loads and handles requests against the host runtimemalloc/freeexportsCallHostFunctionwith a closure-wrapped//go:wasmimportfunction builds under both TinyGo and standard Go