https://github.com/wapc/wapc-guest-tinygo
SDK for creating waPC WebAssembly Guest Modules in TinyGo
https://github.com/wapc/wapc-guest-tinygo
sdk tinygo wasm webassembly
Last synced: 9 months ago
JSON representation
SDK for creating waPC WebAssembly Guest Modules in TinyGo
- Host: GitHub
- URL: https://github.com/wapc/wapc-guest-tinygo
- Owner: wapc
- License: apache-2.0
- Created: 2020-03-03T15:16:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-31T06:13:41.000Z (over 3 years ago)
- Last Synced: 2024-01-25T03:14:31.778Z (over 2 years ago)
- Topics: sdk, tinygo, wasm, webassembly
- Language: Go
- Size: 23.4 KB
- Stars: 20
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# waPC Guest Library for TinyGo
This is the TinyGo implementation of the **waPC** standard for WebAssembly guest modules. It allows any waPC-compliant WebAssembly host to invoke to procedures inside a TinyGo compiled guest and similarly for the guest to invoke procedures exposed by the host.
## Example
The following is a simple example of synchronous, bi-directional procedure calls between a WebAssembly host runtime and the guest module.
> It is recommended to use the latest versions Go and TinyGo
For TinyGo 0.35+
```go
package main
import (
wapc "github.com/wapc/wapc-guest-tinygo"
)
//go:wasmexport wapc_init
func Initialize() {
wapc.RegisterFunctions(wapc.Functions{
"hello": hello,
})
}
func hello(payload []byte) ([]byte, error) {
wapc.HostCall("myBinding", "sample", "hello", []byte("Simon"))
return []byte("Hello"), nil
}
```
```sh
tinygo build -o example/hello.wasm -scheduler=none --no-debug -target=wasip1 -buildmode=c-shared example/hello.go
```