Skip to content

go/build import fmt got unknown compiler "llgo" #1346

@luoliwoshang

Description

@luoliwoshang

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

  1. 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)
}
  1. Run with standard Go compiler (works):
$ go run main.go
Package: fmt
  1. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions