diff --git a/internal/runtime/runtime.go b/internal/runtime/runtime.go index e9b280b..da7c428 100644 --- a/internal/runtime/runtime.go +++ b/internal/runtime/runtime.go @@ -4,9 +4,7 @@ import ( "context" "fmt" "io" - "log/slog" "os" - "time" "github.com/anthdm/raptor/internal/spidermonkey" "github.com/google/uuid" @@ -79,53 +77,3 @@ func (r *Runtime) Invoke(stdin io.Reader, env map[string]string, args ...string) func (r *Runtime) Close() error { return r.runtime.Close(r.ctx) } - -type InvokeArgs struct { - Blob []byte - Cache wazero.CompilationCache - Out io.Writer - In io.Reader - Env map[string]string - Debug bool - Args []string -} - -func Invoke(ctx context.Context, args InvokeArgs) error { - start := time.Now() - // only arm64 - // config := opt.NewRuntimeConfigOptimizingCompiler().WithCompilationCache(args.Cache) - config := wazero.NewRuntimeConfigCompiler().WithCompilationCache(args.Cache) - runtime := wazero.NewRuntimeWithConfig(ctx, config) - defer runtime.Close(ctx) - - wasi_snapshot_preview1.MustInstantiate(ctx, runtime) - if args.Debug { - fmt.Println("runtime new: ", time.Since(start)) - } - - start = time.Now() - mod, err := runtime.CompileModule(ctx, args.Blob) - if err != nil { - slog.Warn("compiling module failed", "err", err) - return err - } - if args.Debug { - fmt.Println("runtime compile module: ", time.Since(start)) - } - - start = time.Now() - modConf := wazero.NewModuleConfig(). - WithStdin(args.In). - WithStdout(args.Out). - WithStderr(os.Stderr). - WithArgs(args.Args...) - for k, v := range args.Env { - modConf = modConf.WithEnv(k, v) - } - _, err = runtime.InstantiateModule(ctx, mod, modConf) - if args.Debug { - fmt.Println("runtime instantiate: ", time.Since(start)) - } - - return err -}