Skip to content

Commit

Permalink
clarify args
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Oct 2, 2024
1 parent 799658a commit 41705f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
18 changes: 10 additions & 8 deletions private/pkg/wasm/compiled_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,24 @@ type compiledModule struct {
}

func (p *compiledModule) Run(ctx context.Context, env pluginrpc.Env) error {
// Create a new module moduleConfig with the given environment.
moduleConfig := wazero.NewModuleConfig().
// Create a new module wazeroModuleConfig with the given environment.
wazeroModuleConfig := wazero.NewModuleConfig().
WithStdin(env.Stdin).
WithStdout(env.Stdout).
WithStderr(env.Stderr)
WithStderr(env.Stderr).
// Use an empty name to allow for multiple instances of the same module.
// See wazero.ModuleConfig.WithName.
WithName("").
// Use the program name as the first argument to replicate the
// behavior of os.Exec. See wazero.ModuleConfig.WithArgs.
WithArgs(append([]string{p.moduleName}, env.Args...)...)

// Instantiate the guest wasm module into the same runtime.
// See: https://github.com/tetratelabs/wazero/issues/985
wazeroModule, err := p.runtime.InstantiateModule(
ctx,
p.compiledModule,
// Use an empty name to allow for multiple instances of the same module.
// See wazero.ModuleConfig.WithName.
moduleConfig.WithName("").WithArgs(
append([]string{p.moduleName}, env.Args...)...,
),
wazeroModuleConfig,
)
if err != nil {
return fmt.Errorf("failed to instantiate module: %w", err)
Expand Down
12 changes: 6 additions & 6 deletions private/pkg/wasm/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ func newRuntime(ctx context.Context, options ...RuntimeOption) (*runtime, error)
option(runtimeOptions)
}
// Create the runtime config with enforceable limits.
runtimeConfig := wazero.NewRuntimeConfig().
wazeroRuntimeConfig := wazero.NewRuntimeConfig().
WithCoreFeatures(api.CoreFeaturesV2).
WithCloseOnContextDone(true).
WithMemoryLimitPages(runtimeOptions.getMaxMemoryBytes() / wasmPageSize)
var compilationCache wazero.CompilationCache
var wazeroCompilationCache wazero.CompilationCache
if runtimeOptions.cacheDir != "" {
var err error
compilationCache, err = wazero.NewCompilationCacheWithDir(runtimeOptions.cacheDir)
wazeroCompilationCache, err = wazero.NewCompilationCacheWithDir(runtimeOptions.cacheDir)
if err != nil {
return nil, fmt.Errorf("failed to create compilation cache: %w", err)
}
runtimeConfig = runtimeConfig.WithCompilationCache(compilationCache)
wazeroRuntimeConfig = wazeroRuntimeConfig.WithCompilationCache(wazeroCompilationCache)
}
wazeroRuntime := wazero.NewRuntimeWithConfig(ctx, runtimeConfig)
wazeroRuntime := wazero.NewRuntimeWithConfig(ctx, wazeroRuntimeConfig)

// Init WASI preview1 APIs. This is required to support the pluginrpc
// protocol. The returned closer method is discarded as the
Expand All @@ -66,7 +66,7 @@ func newRuntime(ctx context.Context, options ...RuntimeOption) (*runtime, error)
}
return &runtime{
runtime: wazeroRuntime,
compilationCache: compilationCache,
compilationCache: wazeroCompilationCache,
}, nil
}

Expand Down

0 comments on commit 41705f9

Please sign in to comment.