From 6c8e5ad0a755e67626603fd63a1f1f215a5bec37 Mon Sep 17 00:00:00 2001 From: semvis123 Date: Tue, 16 May 2023 11:59:38 +0200 Subject: [PATCH] Update Wazero to v1.1.0 --- go.mod | 2 +- go.sum | 4 ++-- webassembly/imports/imports.go | 8 ++++++-- webassembly/webassembly.go | 12 ++++++------ 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index d2e4473f..3c894b5c 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/onsi/ginkgo/v2 v2.9.2 github.com/onsi/gomega v1.27.5 github.com/stretchr/testify v1.8.2 - github.com/tetratelabs/wazero v1.0.0 + github.com/tetratelabs/wazero v1.1.0 golang.org/x/net v0.8.0 golang.org/x/text v0.8.0 ) diff --git a/go.sum b/go.sum index a3ae1433..1c3122a0 100644 --- a/go.sum +++ b/go.sum @@ -70,8 +70,8 @@ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1F github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/tetratelabs/wazero v1.0.0 h1:sCE9+mjFex95Ki6hdqwvhyF25x5WslADjDKIFU5BXzI= -github.com/tetratelabs/wazero v1.0.0/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ= +github.com/tetratelabs/wazero v1.1.0 h1:EByoAhC+QcYpwSZJSs/aV0uokxPwBgKxfiokSUwAknQ= +github.com/tetratelabs/wazero v1.1.0/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/webassembly/imports/imports.go b/webassembly/imports/imports.go index a79e42ea..c7bcc358 100644 --- a/webassembly/imports/imports.go +++ b/webassembly/imports/imports.go @@ -15,9 +15,13 @@ import ( // - Closing the wazero.Runtime has the same effect as closing the result. // - To add more functions to the "env" module, use FunctionExporter. // - To instantiate into another wazero.Namespace, use FunctionExporter. -func Instantiate(ctx context.Context, r wazero.Runtime) (api.Closer, error) { +func Instantiate(ctx context.Context, r wazero.Runtime, mod wazero.CompiledModule) (api.Closer, error) { builder := r.NewHostModuleBuilder("env") - emscripten.NewFunctionExporter().ExportFunctions(builder) + exporter, err := emscripten.NewFunctionExporterForModule(mod) + if err != nil { + return nil, err + } + exporter.ExportFunctions(builder) NewFunctionExporter().ExportFunctions(builder) return builder.Instantiate(ctx) } diff --git a/webassembly/webassembly.go b/webassembly/webassembly.go index fcc9817e..a215c432 100644 --- a/webassembly/webassembly.go +++ b/webassembly/webassembly.go @@ -116,18 +116,18 @@ func Init(config Config) (pdfium.Pool, error) { return nil, fmt.Errorf("could not instantiate webassembly wasi_snapshot_preview1 module: %w", err) } - // Add basic Emscripten specific methods. - if _, err := imports.Instantiate(poolContext, runtime); err != nil { - runtime.Close(poolContext) - return nil, fmt.Errorf("could not instantiate webassembly emscripten/env module: %w", err) - } - compiledModule, err := runtime.CompileModule(poolContext, config.WASM) if err != nil { runtime.Close(poolContext) return nil, fmt.Errorf("could not compile webassembly module: %w", err) } + // Add basic Emscripten specific methods. + if _, err := imports.Instantiate(poolContext, runtime, compiledModule); err != nil { + runtime.Close(poolContext) + return nil, fmt.Errorf("could not instantiate webassembly emscripten/env module: %w", err) + } + factory := pool.NewPooledObjectFactory( func(goctx.Context) (interface{}, error) { newWorker := &worker{