Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ FROM golang:1.21

WORKDIR /app

COPY . ./

ENV GO111MODULE=on
ENV GOARCH=amd64

RUN apt-get update
RUN apt-get install gcc
RUN wget https://github.com/tinygo-org/tinygo/releases/download/v0.30.0/tinygo_0.30.0_amd64.deb && dpkg -i tinygo_0.30.0_amd64.deb
RUN curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -v 0.13.4

COPY . ./

RUN go get
RUN cp -r /usr/local/go/src/cmd/internal /usr/local/go/src/cmd/objfile
RUN go build -buildmode=plugin -o plugin.so golangplugin/main.go
RUN go build -o ./hashicorpgoplugin ./hashicorp-go-plugin/main.go
RUN go build -o ./pieplugin ./pie/main.go
RUN go build -o ./pingoplugin ./pingo/main.go
RUN go build -o ./plugplugin ./plug/plugin/main.go
RUN tinygo build -o ./wasm-edge.wasm -target wasi ./wasm-edge/main.go
RUN go list -export -f '{{if .Export}}packagefile {{.ImportPath}}={{.Export}}{{end}}' std `go list -f {{.Imports}} ./goloader/main.go | awk '{sub(/^\[/, ""); print }' | awk '{sub(/\]$/, ""); print }'` > importcfg
RUN CGO_ENABLED=0 go tool compile -importcfg importcfg -o ./goloader.o ./goloader/main.go

CMD ["go", "test", "-bench=."]

CMD . $HOME/.wasmedge/env && go test -bench=.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ require (
github.com/hashicorp/go-plugin v1.5.2
github.com/natefinch/pie v0.0.0-20170715172608-9a0d72014007
github.com/pkujhd/goloader v0.0.0-20230918021236-475614750c78
github.com/second-state/WasmEdge-go v0.13.4
github.com/second-state/wasmedge-bindgen v0.4.1
github.com/traefik/yaegi v0.9.19
google.golang.org/protobuf v1.31.0
)
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ github.com/pkujhd/goloader v0.0.0-20230918021236-475614750c78/go.mod h1:JQc0eCq8
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/second-state/WasmEdge-go v0.13.4 h1:NHfJC+aayUW93ydAzlcX7Jx1WDRpI24KvY5SAbeTyvY=
github.com/second-state/WasmEdge-go v0.13.4/go.mod h1:HyBf9hVj1sRAjklsjc1Yvs9b5RcmthPG9z99dY78TKg=
github.com/second-state/wasmedge-bindgen v0.4.1 h1:N1OPuonO4P0rfHym2iOT4l/kCopSSDmjyuxHkSr4WsU=
github.com/second-state/wasmedge-bindgen v0.4.1/go.mod h1:2dJ3iNlgMK+EBanG7PbEMCPGBMO/i85VdfLfPXllF9g=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
Expand Down
31 changes: 31 additions & 0 deletions plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
hashicorpplugin "github.com/hashicorp/go-plugin"
"github.com/natefinch/pie"
"github.com/pkujhd/goloader"
"github.com/second-state/WasmEdge-go/wasmedge"
bindgen "github.com/second-state/wasmedge-bindgen/host/go"
"github.com/traefik/yaegi/interp"
"github.com/traefik/yaegi/stdlib"
plugplugin "github.com/uberswe/go-plugin-benchmark/plug"
Expand Down Expand Up @@ -211,3 +213,32 @@ func BenchmarkGoloaderRandInt(b *testing.B) {
codeModule.Unload()
})
}

func BenchmarkWasmEdgeRandInt(b *testing.B) {
var conf = wasmedge.NewConfigure(wasmedge.WASI)
defer conf.Release()

var vm = wasmedge.NewVMWithConfig(conf)
defer vm.Release()

var wasi = vm.GetImportModule(wasmedge.WASI)
wasi.InitWasi([]string{"./wasm-edge.wasm"}, os.Environ(), []string{".:."})
vm.LoadWasmFile("./wasm-edge.wasm")
vm.Validate()

bg := bindgen.New(vm)
defer bg.Release()
bg.Instantiate()

b.Run("wasm-edge", func(b *testing.B) {
for i := 0; i < b.N; i++ {
res, _, err := bg.Execute("RandInt")
if err != nil {
fmt.Println("Error when executing RandInt:", err)
return
}

fmt.Println("Success! Returned value:", res)
}
})
}
12 changes: 12 additions & 0 deletions wasm-edge/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import (
"math/rand"
)

func main() {}

//export RandInt
func RandInt() int {
return rand.Int()
}