Skip to content

Add a minimal TinyGo guest example - #98

Open
AndyFerns wants to merge 5 commits into
GianIac:mainfrom
AndyFerns:feat/tinygo-guest
Open

Add a minimal TinyGo guest example#98
AndyFerns wants to merge 5 commits into
GianIac:mainfrom
AndyFerns:feat/tinygo-guest

Conversation

@AndyFerns

Copy link
Copy Markdown
Contributor

Summary

Adds a new Guest example for TinyGo performing simple logging and KV access

Additions

A TinyGo guest (living under the src/ subdir) that exports run and imports host_log_v2 and db_set from the nx namespace.

  • Explicit memory boundary handling (converting Go strings to uint32 pointers/lengths).
  • Windows (build.bat) and Linux/macOS (build.sh) build scripts.
  • A README detailing requirements, build steps, and TinyGo-specific ABI observations.

notes

  • used //go:wasmimport and //go:export directives to keep the WASM ABI clean (no C-esque name mangling)
  • compiled with -target wasi to prevent TinyGo from injecting JS-specific runtime hooks (which previously caused gojs::runtime.ticks linking errors)
  • skipped optimizations (-opt=0) in the build scripts so users don't strictly need wasm-opt (Binaryen) installed on their machines just to run the example.

Closes #51

@GianIac GianIac left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the PR! the README is honest about the -target wasi / -opt=0 trade-offs, the Windows + Unix scripts are a nice extra, and using //go:wasmimport / //go:export is exactly the right approach.

A few small things before merge:

Small fixes

  • Please add a trailing newline to the new files (all 5 are missing it, some linters/pre-commit hooks complain).
  • Could you set the executable bit on build.sh directly in the commit? That way users don't need the chmod +x step from the README. From your side:
    git update-index --chmod=+x examples/guest_tinygo/build.sh

Please add two short notes to the README

  • Because of -target wasi, the module also imports wasi_snapshot_preview1 in addition to the nx namespace. Worth calling that out so readers know the import surface is larger than the AssemblyScript/Zig examples.
  • stringToWasmPtr takes the address of a heap-allocated []byte and passes it to the host. It works with TinyGo's default GC on wasi, but a one-line caveat about GC / pointer lifetime would be great (or, if you feel like it, switch to a static []byte global — no pressure though).

Not blocking

  • Other recent guest examples (AssemblyScript #95, Zig #97) added a CI job that builds and smoke-tests the module. Not asking you to do it here. I'll open a follow-up issue for CI coverage after merge.

Once the small fixes above are in, happy to merge. Thanks again !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a TinyGo WebAssembly guest example for Numax

2 participants