golang/go · error
failed to locate cmd/compile for target platform
Error message
failed to locate cmd/compile for target platform
What it means
Returned by go_android_exec when `go list -f {{.Target}} cmd/compile` resolves to a relative '.' path, meaning the cross-target compiler binary was not installed. The tool needs the platform's compile binary at pkg/tool/<goos>_<goarch>/ to push to the device; absence makes the relative path collapse to '.'.
Source
Thrown at misc/go_android_exec/main.go:454
// Copy only the relevant subdirectories from pkg: pkg/include and the
// platform-native binaries in pkg/tool.
if err := adb("exec-out", "mkdir", "-p", path.Join(deviceGoroot, "pkg", "tool")); err != nil {
return err
}
if err := adb("push", filepath.Join(goroot, "pkg", "include"), path.Join(deviceGoroot, "pkg", "include")); err != nil {
return err
}
cmd = exec.Command(goTool, "list", "-f", "{{.Target}}", "cmd/compile")
cmd.Stderr = os.Stderr
out, err = cmd.Output()
if err != nil {
return fmt.Errorf("%v: %w", cmd, err)
}
platformToolDir := filepath.Dir(string(bytes.TrimSpace(out)))
if platformToolDir == "." {
return errors.New("failed to locate cmd/compile for target platform")
}
relToolDir, err := filepath.Rel(filepath.Join(goroot), platformToolDir)
if err != nil {
return err
}
if err := adb("push", platformToolDir, path.Join(deviceGoroot, relToolDir)); err != nil {
return err
}
// Copy all other files from GOROOT.
dirents, err := os.ReadDir(goroot)
if err != nil {
return err
}
for _, de := range dirents {
switch de.Name() {
case "bin", "pkg":
// We already created GOROOT/bin and GOROOT/pkg above; skip those.View on GitHub (pinned to b6b368adc5)
Solutions
- Install the cross compiler: GOOS=android GOARCH=arm64 go install cmd/compile cmd/go.
- Verify: GOOS=android GOARCH=arm64 go list -f {{.Target}} cmd/compile must print an absolute path ending in pkg/tool/android_arm64.
- Ensure GOROOT/pkg/tool contains the android_<goarch> subdirectory; if not, run a full `go install std cmd` for the target.
- Confirm GOOS/GOARCH are exported in the shell that runs go_android_exec.
Example fix
# before GOOS=android GOARCH=arm64 go run misc/go_android_exec/main.go ... # throws # after GOOS=android GOARCH=arm64 go install cmd/compile ls "$(go env GOROOT)/pkg/tool/android_arm64/compile" # sanity check GOOS=android GOARCH=arm64 go run misc/go_android_exec/main.go ...
Defensive patterns
Strategy: validation
Validate before calling
out, err := exec.Command("go", "list", "-f", "{{.Target}}", "cmd/compile").Output()
if err != nil { log.Fatal(err) }
if dir := filepath.Dir(strings.TrimSpace(string(out))); dir == "." {
log.Fatal("run: GOOS=android GOARCH=<arch> go install cmd/compile first")
} Prevention
- Install the cross compiler: GOOS=android GOARCH=<arch> go install cmd/compile cmd/go.
- Confirm GOROOT/pkg/tool/<goos>_<goarch>/compile exists before running go_android_exec.
- Keep GOOS/GOARCH exported in the invoking shell.
When it happens
Trigger: Running go_android_exec without `go install cmd/compile` for the android target; GOROOT/pkg/tool trimmed or never populated for android; GOOS/GOARCH unset so go list resolves the host compile whose filepath.Rel yields '.'.
Common situations: Fresh CI runners that only built host toolchain; partial `go install` that built cmd/go but not cmd/compile; manually stripped GOROOT/pkg/tool; switching GOARCH mid-build.
Related errors
- failed to locate cmd/go for target platform
- GOROOT not found
- maximum supported Go version is %s
- globalThis.crypto is not available, polyfill required (crypt
- globalThis.performance is not available, polyfill required (
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/cbabc688f5d808e8.
Report an issue: GitHub.