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 f7b0150
Show file tree
Hide file tree
Showing 5 changed files with 314 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
}
270 changes: 270 additions & 0 deletions wasm-go/.flox/env/manifest.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
{
"lockfile-version": 1,
"manifest": {
"version": 1,
"install": {
"go": {
"pkg-path": "go"
},
"wasmtime": {
"pkg-path": "wasmtime"
}
},
"vars": {
"GOARCH": "wasm",
"GOOS": "wasip1"
},
"hook": {},
"profile": {},
"options": {
"systems": [
"aarch64-darwin",
"aarch64-linux",
"x86_64-darwin",
"x86_64-linux"
],
"allow": {
"licenses": []
},
"semver": {}
}
},
"packages": [
{
"attr_path": "go",
"broken": false,
"derivation": "/nix/store/m82cyrgfqssf9aqfas6nhlrppiw21yhl-go-1.23.2.drv",
"description": "Go Programming language",
"install_id": "go",
"license": "BSD-3-Clause",
"locked_url": "https://github.com/flox/nixpkgs?rev=a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"name": "go-1.23.2",
"pname": "go",
"rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"rev_count": 692963,
"rev_date": "2024-10-14T06:48:30Z",
"scrape_date": "2024-10-16T03:55:11Z",
"stabilities": [
"unstable"
],
"unfree": false,
"version": "1.23.2",
"outputs_to_install": [
"out"
],
"outputs": {
"out": "/nix/store/35jikx2wg5r0qj47sic0p99bqnmwi6cn-go-1.23.2"
},
"system": "aarch64-darwin",
"group": "toplevel",
"priority": 5
},
{
"attr_path": "go",
"broken": false,
"derivation": "/nix/store/fvhf2xd1fis6ris4dviqzvnipc7p5gj0-go-1.23.2.drv",
"description": "Go Programming language",
"install_id": "go",
"license": "BSD-3-Clause",
"locked_url": "https://github.com/flox/nixpkgs?rev=a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"name": "go-1.23.2",
"pname": "go",
"rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"rev_count": 692963,
"rev_date": "2024-10-14T06:48:30Z",
"scrape_date": "2024-10-16T03:55:11Z",
"stabilities": [
"unstable"
],
"unfree": false,
"version": "1.23.2",
"outputs_to_install": [
"out"
],
"outputs": {
"out": "/nix/store/6bx6d90kpy537yab22wja70ibpp4gkww-go-1.23.2"
},
"system": "aarch64-linux",
"group": "toplevel",
"priority": 5
},
{
"attr_path": "go",
"broken": false,
"derivation": "/nix/store/a9jji6d0ic7ix8vjw888kmpgcgbkck1a-go-1.23.2.drv",
"description": "Go Programming language",
"install_id": "go",
"license": "BSD-3-Clause",
"locked_url": "https://github.com/flox/nixpkgs?rev=a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"name": "go-1.23.2",
"pname": "go",
"rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"rev_count": 692963,
"rev_date": "2024-10-14T06:48:30Z",
"scrape_date": "2024-10-16T03:55:11Z",
"stabilities": [
"unstable"
],
"unfree": false,
"version": "1.23.2",
"outputs_to_install": [
"out"
],
"outputs": {
"out": "/nix/store/yi89mimkmw48qhzrll1aaibxbvllpsjv-go-1.23.2"
},
"system": "x86_64-darwin",
"group": "toplevel",
"priority": 5
},
{
"attr_path": "go",
"broken": false,
"derivation": "/nix/store/k4sd1nf7nl549wcyx4z3g59sxd2h8xim-go-1.23.2.drv",
"description": "Go Programming language",
"install_id": "go",
"license": "BSD-3-Clause",
"locked_url": "https://github.com/flox/nixpkgs?rev=a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"name": "go-1.23.2",
"pname": "go",
"rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"rev_count": 692963,
"rev_date": "2024-10-14T06:48:30Z",
"scrape_date": "2024-10-16T03:55:11Z",
"stabilities": [
"unstable"
],
"unfree": false,
"version": "1.23.2",
"outputs_to_install": [
"out"
],
"outputs": {
"out": "/nix/store/klw1ipjsqx1np7pkk833x7sad7f3ivv9-go-1.23.2"
},
"system": "x86_64-linux",
"group": "toplevel",
"priority": 5
},
{
"attr_path": "wasmtime",
"broken": false,
"derivation": "/nix/store/lkfz47y8pyvdmzn8drj1f965sckh92y3-wasmtime-25.0.2.drv",
"description": "Standalone JIT-style runtime for WebAssembly, using Cranelift",
"install_id": "wasmtime",
"license": "Apache-2.0",
"locked_url": "https://github.com/flox/nixpkgs?rev=a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"name": "wasmtime-25.0.2",
"pname": "wasmtime",
"rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"rev_count": 692963,
"rev_date": "2024-10-14T06:48:30Z",
"scrape_date": "2024-10-16T03:55:11Z",
"stabilities": [
"unstable"
],
"unfree": false,
"version": "25.0.2",
"outputs_to_install": [
"out"
],
"outputs": {
"dev": "/nix/store/hxdxvj9lc3zwpivi9998q9kx7j4vrgrg-wasmtime-25.0.2-dev",
"out": "/nix/store/jrxzqnfm3fdh4rh6q0cfil7r9cwiwkx2-wasmtime-25.0.2"
},
"system": "aarch64-darwin",
"group": "toplevel",
"priority": 5
},
{
"attr_path": "wasmtime",
"broken": false,
"derivation": "/nix/store/q1q2nf5ry8cxzpmh8ccdvg1zakg0126p-wasmtime-25.0.2.drv",
"description": "Standalone JIT-style runtime for WebAssembly, using Cranelift",
"install_id": "wasmtime",
"license": "Apache-2.0",
"locked_url": "https://github.com/flox/nixpkgs?rev=a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"name": "wasmtime-25.0.2",
"pname": "wasmtime",
"rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"rev_count": 692963,
"rev_date": "2024-10-14T06:48:30Z",
"scrape_date": "2024-10-16T03:55:11Z",
"stabilities": [
"unstable"
],
"unfree": false,
"version": "25.0.2",
"outputs_to_install": [
"out"
],
"outputs": {
"dev": "/nix/store/sr83czmp16hj7znf96n4ilqncd7s9byk-wasmtime-25.0.2-dev",
"out": "/nix/store/gimn6kpqpgzvwih2hzm6pqphyfy7hc1y-wasmtime-25.0.2"
},
"system": "aarch64-linux",
"group": "toplevel",
"priority": 5
},
{
"attr_path": "wasmtime",
"broken": false,
"derivation": "/nix/store/d5jcwc2qadpq6piabcqbxfhrlmhd25y1-wasmtime-25.0.2.drv",
"description": "Standalone JIT-style runtime for WebAssembly, using Cranelift",
"install_id": "wasmtime",
"license": "Apache-2.0",
"locked_url": "https://github.com/flox/nixpkgs?rev=a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"name": "wasmtime-25.0.2",
"pname": "wasmtime",
"rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"rev_count": 692963,
"rev_date": "2024-10-14T06:48:30Z",
"scrape_date": "2024-10-16T03:55:11Z",
"stabilities": [
"unstable"
],
"unfree": false,
"version": "25.0.2",
"outputs_to_install": [
"out"
],
"outputs": {
"dev": "/nix/store/y3dg5s92hbz1kcngh7x6vrvb9zw759pf-wasmtime-25.0.2-dev",
"out": "/nix/store/3sy3q7cm1s6kg0jvbl4dk43b0rbdl8cz-wasmtime-25.0.2"
},
"system": "x86_64-darwin",
"group": "toplevel",
"priority": 5
},
{
"attr_path": "wasmtime",
"broken": false,
"derivation": "/nix/store/2hsjd0y8wsgmwmwy8m5dj6qbrnz0ry8g-wasmtime-25.0.2.drv",
"description": "Standalone JIT-style runtime for WebAssembly, using Cranelift",
"install_id": "wasmtime",
"license": "Apache-2.0",
"locked_url": "https://github.com/flox/nixpkgs?rev=a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"name": "wasmtime-25.0.2",
"pname": "wasmtime",
"rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
"rev_count": 692963,
"rev_date": "2024-10-14T06:48:30Z",
"scrape_date": "2024-10-16T03:55:11Z",
"stabilities": [
"unstable"
],
"unfree": false,
"version": "25.0.2",
"outputs_to_install": [
"out"
],
"outputs": {
"dev": "/nix/store/q2x15x5gmnscdnqxnib2kvsjwjlxlf3v-wasmtime-25.0.2-dev",
"out": "/nix/store/6cvl86rivzga6pdd7ia994fwnwi9xj0x-wasmtime-25.0.2"
},
"system": "x86_64-linux",
"group": "toplevel",
"priority": 5
}
]
}
11 changes: 11 additions & 0 deletions wasm-go/.flox/env/manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version = 1
[install]
wasmtime.pkg-path = "wasmtime"
go.pkg-path = "go"

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

[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 f7b0150

Please sign in to comment.