forked from gohugoio/hugo
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See gohugoio#11927
- Loading branch information
Showing
4 changed files
with
253 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package ext | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"sync" | ||
|
||
"github.com/tetratelabs/wazero" | ||
"github.com/tetratelabs/wazero/api" | ||
"github.com/tetratelabs/wazero/experimental" | ||
) | ||
|
||
func deleteMe(name string, wasm []byte, needsQuickJSProvider bool) func(ctx context.Context, r wazero.Runtime, inouts []*inOut) (func() error, error) { | ||
return func(ctx context.Context, r wazero.Runtime, inouts []*inOut) (func() error, error) { | ||
compiledModule, err := r.CompileModule(ctx, wasm) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var compiledQuickJS wazero.CompiledModule | ||
if needsQuickJSProvider { | ||
compiledQuickJS, err = r.CompileModule(ctx, quickjsWasm) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return func() error { | ||
var wg sync.WaitGroup | ||
for i, c := range inouts { | ||
name := fmt.Sprintf("%s_%d", name, i) | ||
c := c | ||
|
||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
configBase := wazero.NewModuleConfig().WithStderr(os.Stderr).WithStartFunctions() | ||
config := configBase.WithName(name) | ||
if needsQuickJSProvider { | ||
// TODO1 else, configure with stdout etc. | ||
qmod, err := r.InstantiateModule(ctx, compiledQuickJS, configBase.WithName("").WithStdout(c.stdout).WithStdin(c.stdin)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
ctx = experimental.WithImportResolver(ctx, | ||
func(name string) api.Module { | ||
if name == "javy_quickjs_provider_v2" { | ||
return qmod | ||
} | ||
return nil | ||
}) | ||
|
||
} | ||
|
||
mod, err := r.InstantiateModule(ctx, compiledModule, config) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if _, err := mod.ExportedFunction("_start").Call(ctx); err != nil { | ||
panic(err) | ||
} | ||
}() | ||
} | ||
wg.Wait() | ||
return nil | ||
}, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.