Skip to content

Commit

Permalink
Add wasm-go example
Browse files Browse the repository at this point in the history
  • Loading branch information
ysndr committed Oct 16, 2024
1 parent c5208f4 commit e790936
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions wasm-go/.flox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
run/
cache/
lib/
log/
4 changes: 4 additions & 0 deletions wasm-go/.flox/env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "wasm-go",
"version": 1
}
14 changes: 14 additions & 0 deletions wasm-go/.flox/env/manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version = 1
[install]
wasmtime.pkg-path = "wasmtime"
go.pkg-path = "go"

[vars]
GOOS="wasip1"
GOARCH="wasm"

[hook]
[profile]
[services]
[options]
systems = ["aarch64-darwin", "aarch64-linux", "x86_64-darwin", "x86_64-linux"]
25 changes: 25 additions & 0 deletions wasm-go/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

set -eo pipefail

echo '
package main
import "fmt"
func main() {
fmt.Println("Hello world!")
}
' > main.go

go build -o main.wasm main.go

ACTUAL="$(wasmtime main.wasm)"
EXPECTED="Hello world!"

if [ "$ACTUAL" != "$EXPECTED" ]; then
echo "Error: 'wasmtime main.wasm' did not return '$EXPECTED'."
exit 1
fi

rm main.go main.wasm

0 comments on commit e790936

Please sign in to comment.