Skip to content

Commit

Permalink
removed old invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
anthdm committed Jan 9, 2024
1 parent 2e15ac8 commit 5c59920
Showing 1 changed file with 0 additions and 52 deletions.
52 changes: 0 additions & 52 deletions internal/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"context"
"fmt"
"io"
"log/slog"
"os"
"time"

"github.com/anthdm/raptor/internal/spidermonkey"
"github.com/google/uuid"
Expand Down Expand Up @@ -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
}

0 comments on commit 5c59920

Please sign in to comment.