From 83330ad4d2243767e166826c59e058ba2acbd891 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Sun, 20 Nov 2022 16:18:30 +0900 Subject: [PATCH] Fixes for TinyGo 0.26.0 (#9) Signed-off-by: Takeshi Yoneda --- .github/workflows/test.yaml | 18 +++++++++++++----- examples/helloworld/greeting/greet_host.pb.go | 3 +++ .../host-functions/greeting/greet_host.pb.go | 3 +++ examples/known-types/known/known_host.pb.go | 3 +++ examples/wasi/cat/cat_host.pb.go | 3 +++ gen/host.go | 4 +++- tests/fields/proto/fields_host.pb.go | 3 +++ tests/host-functions/proto/host_host.pb.go | 3 +++ tests/import/proto/bar/bar_host.pb.go | 3 +++ tests/import/proto/foo/foo_host.pb.go | 3 +++ tests/well-known/proto/known_host.pb.go | 6 ++++++ wasm/host.go | 8 +++++++- 12 files changed, 53 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 14b33ae..8c89b7d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,11 +11,19 @@ on: env: GO_VERSION: "1.18" PROTOC_VERSION: "21.5" - TINYGO_VERSION: "0.24.0" + jobs: test: - name: Test + name: Test (TinyGo ${{ matrix.tinygo-version }}) runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + tinygo-version: + - "0.24.0" + - "0.25.0" + - "0.26.0" + steps: - uses: actions/checkout@v3 @@ -41,8 +49,8 @@ jobs: - name: Install TinyGo run: | - wget https://github.com/tinygo-org/tinygo/releases/download/v${TINYGO_VERSION}/tinygo_${TINYGO_VERSION}_amd64.deb - sudo dpkg -i tinygo_${TINYGO_VERSION}_amd64.deb + wget https://github.com/tinygo-org/tinygo/releases/download/v${{ matrix.tinygo-version }}/tinygo_${{ matrix.tinygo-version }}_amd64.deb + sudo dpkg -i tinygo_${{ matrix.tinygo-version }}_amd64.deb - name: Run unit tests - run: make test \ No newline at end of file + run: make test diff --git a/examples/helloworld/greeting/greet_host.pb.go b/examples/helloworld/greeting/greet_host.pb.go index e75cad1..ce25a19 100644 --- a/examples/helloworld/greeting/greet_host.pb.go +++ b/examples/helloworld/greeting/greet_host.pb.go @@ -129,6 +129,9 @@ func (p *greeterPlugin) Greet(ctx context.Context, request GreetRequest) (respon return response, err } dataSize := uint64(len(data)) + if dataSize == 0 { + return response, nil + } results, err := p.malloc.Call(ctx, dataSize) if err != nil { return response, err diff --git a/examples/host-functions/greeting/greet_host.pb.go b/examples/host-functions/greeting/greet_host.pb.go index 31e2433..124702a 100644 --- a/examples/host-functions/greeting/greet_host.pb.go +++ b/examples/host-functions/greeting/greet_host.pb.go @@ -221,6 +221,9 @@ func (p *greeterPlugin) Greet(ctx context.Context, request GreetRequest) (respon return response, err } dataSize := uint64(len(data)) + if dataSize == 0 { + return response, nil + } results, err := p.malloc.Call(ctx, dataSize) if err != nil { return response, err diff --git a/examples/known-types/known/known_host.pb.go b/examples/known-types/known/known_host.pb.go index 806b777..308faa3 100644 --- a/examples/known-types/known/known_host.pb.go +++ b/examples/known-types/known/known_host.pb.go @@ -129,6 +129,9 @@ func (p *wellKnownPlugin) Diff(ctx context.Context, request DiffRequest) (respon return response, err } dataSize := uint64(len(data)) + if dataSize == 0 { + return response, nil + } results, err := p.malloc.Call(ctx, dataSize) if err != nil { return response, err diff --git a/examples/wasi/cat/cat_host.pb.go b/examples/wasi/cat/cat_host.pb.go index bfdcaa5..792c8d8 100644 --- a/examples/wasi/cat/cat_host.pb.go +++ b/examples/wasi/cat/cat_host.pb.go @@ -129,6 +129,9 @@ func (p *fileCatPlugin) Cat(ctx context.Context, request FileCatRequest) (respon return response, err } dataSize := uint64(len(data)) + if dataSize == 0 { + return response, nil + } results, err := p.malloc.Call(ctx, dataSize) if err != nil { return response, err diff --git a/gen/host.go b/gen/host.go index ceb1cac..54c48ec 100644 --- a/gen/host.go +++ b/gen/host.go @@ -289,7 +289,9 @@ func genPluginMethod(g *protogen.GeneratedFile, f *fileInfo, method *protogen.Me g.P("data, err := request.MarshalVT()") g.P(errorHandling) g.P("dataSize := uint64(len(data))") - + g.P(`if dataSize == 0 { + return response, nil + }`) g.P("results, err := p.malloc.Call(ctx, dataSize)") g.P(errorHandling) diff --git a/tests/fields/proto/fields_host.pb.go b/tests/fields/proto/fields_host.pb.go index d7368a5..c805e8f 100644 --- a/tests/fields/proto/fields_host.pb.go +++ b/tests/fields/proto/fields_host.pb.go @@ -129,6 +129,9 @@ func (p *fieldTestPlugin) Test(ctx context.Context, request Request) (response R return response, err } dataSize := uint64(len(data)) + if dataSize == 0 { + return response, nil + } results, err := p.malloc.Call(ctx, dataSize) if err != nil { return response, err diff --git a/tests/host-functions/proto/host_host.pb.go b/tests/host-functions/proto/host_host.pb.go index 633a756..2ee00bf 100644 --- a/tests/host-functions/proto/host_host.pb.go +++ b/tests/host-functions/proto/host_host.pb.go @@ -185,6 +185,9 @@ func (p *greeterPlugin) Greet(ctx context.Context, request GreetRequest) (respon return response, err } dataSize := uint64(len(data)) + if dataSize == 0 { + return response, nil + } results, err := p.malloc.Call(ctx, dataSize) if err != nil { return response, err diff --git a/tests/import/proto/bar/bar_host.pb.go b/tests/import/proto/bar/bar_host.pb.go index 6ead4e8..2cb9244 100644 --- a/tests/import/proto/bar/bar_host.pb.go +++ b/tests/import/proto/bar/bar_host.pb.go @@ -129,6 +129,9 @@ func (p *barPlugin) Hello(ctx context.Context, request Request) (response Reply, return response, err } dataSize := uint64(len(data)) + if dataSize == 0 { + return response, nil + } results, err := p.malloc.Call(ctx, dataSize) if err != nil { return response, err diff --git a/tests/import/proto/foo/foo_host.pb.go b/tests/import/proto/foo/foo_host.pb.go index f11e337..efd4496 100644 --- a/tests/import/proto/foo/foo_host.pb.go +++ b/tests/import/proto/foo/foo_host.pb.go @@ -130,6 +130,9 @@ func (p *fooPlugin) Hello(ctx context.Context, request Request) (response bar.Re return response, err } dataSize := uint64(len(data)) + if dataSize == 0 { + return response, nil + } results, err := p.malloc.Call(ctx, dataSize) if err != nil { return response, err diff --git a/tests/well-known/proto/known_host.pb.go b/tests/well-known/proto/known_host.pb.go index c827368..54f5951 100644 --- a/tests/well-known/proto/known_host.pb.go +++ b/tests/well-known/proto/known_host.pb.go @@ -130,6 +130,9 @@ func (p *knownTypesTestPlugin) Test(ctx context.Context, request Request) (respo return response, err } dataSize := uint64(len(data)) + if dataSize == 0 { + return response, nil + } results, err := p.malloc.Call(ctx, dataSize) if err != nil { return response, err @@ -275,6 +278,9 @@ func (p *emptyTestPlugin) DoNothing(ctx context.Context, request emptypb.Empty) return response, err } dataSize := uint64(len(data)) + if dataSize == 0 { + return response, nil + } results, err := p.malloc.Call(ctx, dataSize) if err != nil { return response, err diff --git a/wasm/host.go b/wasm/host.go index cb63fbb..7f4bf2e 100644 --- a/wasm/host.go +++ b/wasm/host.go @@ -25,7 +25,13 @@ func WriteMemory(ctx context.Context, m api.Module, data []byte) (uint64, error) if malloc == nil { return 0, errors.New("malloc is not exported") } - results, err := malloc.Call(ctx, uint64(len(data))) + + l := uint64(len(data)) + if l == 0 { + return 0, nil + } + + results, err := malloc.Call(ctx, l) if err != nil { return 0, err }