Repository navigation
v2.0.0
Yaegi v2 is a new engine, written from scratch. It uses the official Go tools (go/parser, go/types, x/tools/go/ssa) to parse and type check the code, and runs the result on a bytecode VM. The README explains why.
Status: experimental. The API is not stable yet. Traefik v3.8 can run its Yaegi plugins with yaegi v2, as an experimental option (experimental.defaultRuntimeVersion: v2, or runtimeVersion: v2 in the plugin manifest). The default is still yaegi v0. Yaegi v0 (module github.com/traefik/yaegi, releases v0.x) stays on branch master.
Breaking changes
Module path
The module is now github.com/traefik/yaegi/v2.
go install github.com/traefik/yaegi/v2/cmd/yaegi@v2.0.0Command line
| yaegi v0 | yaegi v2 |
|---|---|
echo 'println(3 + 1)' | yaegi (no argument reads stdin) |
echo '3 + 1' | yaegi -i. With no argument, yaegi v2 prints the usage and exits with code 2. |
yaegi run prog.go |
yaegi prog.go |
yaegi test, yaegi extract |
Removed. |
-syscall, -unsafe, -unrestricted |
-restricted applies the import restrictions of Traefik plugins. -unsafe (with -restricted) allows unsafe and syscall. With no flag, there is no restriction. |
-noautoimport |
Removed. |
print and println write to stdout |
They write to stderr, as with the gc compiler. -print-stdout keeps the v0 behavior. |
yaegi -e '<source>' runs Go source and prints the value of a last expression. Exit codes: 0 success, 2 unrecovered panic, 3 construct not supported by the VM, 4 load or type error. yaegi -h lists all the flags.
Go API
The interp package is removed. A plugin is loaded with vm.Load (or host.Load for code you do not trust), and its functions are called by name:
| yaegi v0 | yaegi v2 |
|---|---|
interp.New(interp.Options{GoPath: goPath}), then Eval("import \"" + importPath + "\"") |
vm.Load(vm.Options{Dir: moduleDir, Root: goPath + "/src"}, importPath) |
Eval(pkg + ".F"), then reflect.Value.Call |
p.Call(ctx, "F", args...) |
i.Eval(src) in a REPL |
vm.NewSession(opts), then s.Eval(ctx, src) |
unsafe.Symbols and syscall.Symbols |
Options.UseUnsafe |
By default, yaegi v2 accepts a program only when go build builds it, with the same files. Options such as IgnoreSoftErrors and YaegiTags accept what yaegi v0 accepts. The full table is in Coming from yaegi v0.
Go releases
Yaegi v2.0.0 supports Go 1.26 and Go 1.27. A host built with another Go release fails at build time.