Description
When using the go/build package to import packages, it fails with error unknown compiler "llgo" because the go/build.Context only recognizes standard Go compilers (gc, gccgo).
Steps to Reproduce
- Create a simple program using
go/build package:
package main
import (
"fmt"
"go/build"
)
func main() {
pkg, err := build.Import("fmt", "", build.FindOnly)
if err != nil {
panic(err)
}
fmt.Printf("Package: %s\n", pkg.ImportPath)
}
- Run with standard Go compiler (works):
$ go run main.go
Package: fmt
- Run with llgo compiler (fails):
$ llgo run main.go
panic: import "fmt": unknown compiler "llgo"
Root Cause
The error comes from /opt/homebrew/opt/go@1.24/libexec/src/go/build/build.go (lines 590-598):
switch ctxt.Compiler {
case "gccgo":
pkgtargetroot = "pkg/gccgo_" + ctxt.GOOS + "_" + ctxt.GOARCH + suffix
case "gc":
pkgtargetroot = "pkg/" + ctxt.GOOS + "_" + ctxt.GOARCH + suffix
default:
// Save error for end of function.
pkgerr = fmt.Errorf("import %q: unknown compiler %q", path, ctxt.Compiler)
}
The switch statement only handles "gc" and "gccgo", causing any other compiler name (including "llgo") to hit the default case and return an error.
Environment
- llgo version: devel
- Go version: 1.24.6
- OS: macOS (darwin/arm64)
Description
When using the
go/buildpackage to import packages, it fails with errorunknown compiler "llgo"because thego/build.Contextonly recognizes standard Go compilers (gc,gccgo).Steps to Reproduce
go/buildpackage:Root Cause
The error comes from
/opt/homebrew/opt/go@1.24/libexec/src/go/build/build.go(lines 590-598):The switch statement only handles
"gc"and"gccgo", causing any other compiler name (including"llgo") to hit the default case and return an error.Environment