Skip to content

Commit 54b142a

Browse files
committed
feat(go): setup go toolchain
1 parent bd811bd commit 54b142a

File tree

10 files changed

+250
-0
lines changed

10 files changed

+250
-0
lines changed

go_modules/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.wasm

go_modules/plugin-echo/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
internal
2+
*.wasm

go_modules/plugin-echo/go.mod

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module webassembly-repl/plugin-echo
2+
3+
go 1.24
4+
5+
tool go.bytecodealliance.org/cmd/wit-bindgen-go
6+
7+
require (
8+
github.com/coreos/go-semver v0.3.1 // indirect
9+
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
10+
github.com/klauspost/compress v1.18.0 // indirect
11+
github.com/opencontainers/go-digest v1.0.0 // indirect
12+
github.com/regclient/regclient v0.8.3 // indirect
13+
github.com/sirupsen/logrus v1.9.3 // indirect
14+
github.com/tetratelabs/wazero v1.9.0 // indirect
15+
github.com/ulikunitz/xz v0.5.12 // indirect
16+
github.com/urfave/cli/v3 v3.3.3 // indirect
17+
go.bytecodealliance.org v0.7.0 // indirect
18+
go.bytecodealliance.org/cm v0.3.0 // indirect
19+
golang.org/x/mod v0.24.0 // indirect
20+
golang.org/x/sys v0.33.0 // indirect
21+
)

go_modules/plugin-echo/go.sum

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
2+
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
3+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 h1:UhxFibDNY/bfvqU5CAUmr9zpesgbU6SWc8/B4mflAE4=
7+
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
8+
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
9+
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
10+
github.com/olareg/olareg v0.1.2 h1:75G8X6E9FUlzL/CSjgFcYfMgNzlc7CxULpUUNsZBIvI=
11+
github.com/olareg/olareg v0.1.2/go.mod h1:TWs+N6pO1S4bdB6eerzUm/ITRQ6kw91mVf9ZYeGtw+Y=
12+
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
13+
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
14+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
15+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
16+
github.com/regclient/regclient v0.8.3 h1:AFAPu/vmOYGyY22AIgzdBUKbzH+83lEpRioRYJ/reCs=
17+
github.com/regclient/regclient v0.8.3/go.mod h1:gjQh5uBVZoo/CngchghtQh9Hx81HOMKRRDd5WPcPkbk=
18+
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
19+
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
20+
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
21+
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
22+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
23+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
24+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
25+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
26+
github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I=
27+
github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM=
28+
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
29+
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
30+
github.com/urfave/cli/v3 v3.3.3 h1:byCBaVdIXuLPIDm5CYZRVG6NvT7tv1ECqdU4YzlEa3I=
31+
github.com/urfave/cli/v3 v3.3.3/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
32+
go.bytecodealliance.org v0.7.0 h1:CTJ1eb5kFhBKHw1/xycxxz4SmVWNKXYHhrA78oLNXhY=
33+
go.bytecodealliance.org v0.7.0/go.mod h1:PCLMft5yTQsHT9oNPWlq0I6Qdmo6THvdky2AZHjNUkA=
34+
go.bytecodealliance.org/cm v0.3.0 h1:VhV+4vjZPUGCozCg9+up+FNL3YU6XR+XKghk7kQ0vFc=
35+
go.bytecodealliance.org/cm v0.3.0/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI=
36+
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
37+
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
38+
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
39+
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
40+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
41+
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
42+
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
43+
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
44+
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
45+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
46+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
47+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
48+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

go_modules/plugin-echo/main.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"webassembly-repl/plugin-echo/internal/repl/api/plugin"
5+
"webassembly-repl/plugin-echo/internal/repl/api/transport"
6+
7+
"go.bytecodealliance.org/cm"
8+
)
9+
10+
func init() {
11+
// Export the plugin name function
12+
plugin.Exports.Name = func() string {
13+
return "echogo"
14+
}
15+
16+
// Export the manual function
17+
plugin.Exports.Man = func() string {
18+
return `NAME
19+
echogo - Echo a message (built with Go)
20+
21+
USAGE
22+
echogo <message>
23+
24+
DESCRIPTION
25+
Echo a message.`
26+
}
27+
28+
// Export the run function
29+
plugin.Exports.Run = func(payload string) cm.Result[plugin.PluginResponse, plugin.PluginResponse, struct{}] {
30+
response := plugin.PluginResponse{
31+
Status: transport.ReplStatusSuccess,
32+
Stdout: cm.Some(payload),
33+
Stderr: cm.None[string](),
34+
}
35+
return cm.OK[cm.Result[plugin.PluginResponse, plugin.PluginResponse, struct{}]](response)
36+
}
37+
}
38+
39+
// main is required for the wasip2 target
40+
func main() {}

go_modules/wit/host-api.wit

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package repl:api;
2+
3+
interface host-state {
4+
use transport.{readline-response};
5+
use transport.{repl-var};
6+
7+
get-plugins-names: func() -> list<string>;
8+
get-repl-vars: func() -> list<repl-var>;
9+
set-repl-var: func(var: repl-var);
10+
}
11+
12+
interface guest-state {
13+
get-reserved-commands: func() -> list<string>;
14+
}
15+
16+
interface repl-logic {
17+
use transport.{readline-response};
18+
readline: func(line: string) -> readline-response;
19+
}
20+
21+
world host-api {
22+
import host-state;
23+
export guest-state;
24+
export repl-logic;
25+
}

go_modules/wit/plugin-api.wit

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
interface plugin {
2+
use transport.{plugin-response};
3+
4+
name: func() -> string;
5+
man: func() -> string;
6+
run: func(payload: string) -> result<plugin-response>;
7+
}
8+
9+
/// Provided by the host, accessible by plugins
10+
interface http-client {
11+
record http-header {
12+
name: string,
13+
value: string,
14+
}
15+
16+
record http-response {
17+
status: u16,
18+
ok: bool,
19+
headers: list<http-header>,
20+
body: string,
21+
}
22+
23+
get: func(url: string, headers: list<http-header>) -> result<http-response, string>;
24+
}
25+
26+
interface host-state-plugin {
27+
get-repl-var: func(key: string) -> option<string>;
28+
}
29+
30+
world plugin-api {
31+
// The wasip2 target of TinyGo assumes that the component is targeting wasi:cli/command@0.2.0 world (part of wasi:cli),
32+
// so it needs to include the imports from that world.
33+
include wasi:cli/imports@0.2.0;
34+
import http-client;
35+
import host-state-plugin;
36+
export plugin;
37+
}

go_modules/wit/shared.wit

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
interface transport {
2+
record plugin-response {
3+
status: repl-status,
4+
stdout: option<string>,
5+
stderr: option<string>,
6+
}
7+
8+
enum repl-status {
9+
success,
10+
error,
11+
}
12+
13+
record parsed-line {
14+
command: string,
15+
payload: string,
16+
}
17+
18+
variant readline-response {
19+
to-run(parsed-line),
20+
ready(plugin-response),
21+
}
22+
23+
record repl-var {
24+
key: string,
25+
value: string,
26+
}
27+
}

go_modules/wkg.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is automatically generated.
2+
# It is not intended for manual editing.
3+
version = 1
4+
5+
[[packages]]
6+
name = "wasi:cli"
7+
registry = "wasi.dev"
8+
9+
[[packages.versions]]
10+
requirement = "=0.2.0"
11+
version = "0.2.0"
12+
digest = "sha256:e7e85458e11caf76554b724ebf4f113259decf0f3b1ee2e2930de096f72114a7"

justfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,41 @@ build-c-plugins:
4444
#!/usr/bin/env bash
4545
just list-c-plugins|xargs -I {} just build-c-plugin {}
4646

47+
# Bundle wit files into a single file `repl:api.wasm`
48+
go-wit-build:
49+
#!/usr/bin/env bash
50+
cd go_modules/
51+
wkg wit build
52+
53+
# Generate Go bindings for the plugin
54+
go-wit-bindgen-plugin plugin: go-wit-build
55+
#!/usr/bin/env bash
56+
cd go_modules/{{plugin}}
57+
rm -rf internal
58+
go tool wit-bindgen-go generate --world plugin-api --out internal ../repl:api.wasm
59+
60+
# Generate Go bindings for all plugins
61+
go-wit-bindgen-plugins:
62+
#!/usr/bin/env bash
63+
just list-go-plugins|xargs -I {} just go-wit-bindgen-plugin {}
64+
65+
# Build a specific Go plugin
66+
build-go-plugin plugin:
67+
#!/usr/bin/env bash
68+
just go-wit-bindgen-plugin {{plugin}}
69+
cd go_modules/{{plugin}}
70+
tinygo build -target=wasip2 --wit-package ../repl:api.wasm --wit-world plugin-api -o {{plugin}}-go.wasm main.go
71+
72+
# Build all Go plugins
73+
build-go-plugins:
74+
#!/usr/bin/env bash
75+
just list-go-plugins|xargs -I {} just build-go-plugin {}
76+
77+
# List all Go plugins
78+
list-go-plugins:
79+
#!/usr/bin/env bash
80+
ls -1 go_modules|grep plugin-
81+
4782
# Build all rust plugins in debug mode
4883
build-rust-plugins:
4984
#!/usr/bin/env bash
@@ -71,13 +106,15 @@ build-plugins:
71106
just build-repl-logic-guest
72107
just build-rust-plugins
73108
just build-c-plugins
109+
just build-go-plugins
74110

75111
# Build all plugins in release mode
76112
build-plugins-release:
77113
#!/usr/bin/env bash
78114
just build-repl-logic-guest-release
79115
just build-rust-plugins-release
80116
just build-c-plugins
117+
just build-go-plugins
81118

82119
# Build a specific plugin
83120
build-plugin plugin:

0 commit comments

Comments
 (0)