{"record":{"id":"879dbf650c6899ca","repo":"apache/beam","slug":"failed-to-cross-compile-v-see-https-beam-apache-org","errorCode":null,"errorMessage":"failed to cross-compile %v, see https://beam.apache.org/documentation/sdks/go-cross-compilation/ for details: %v\n%v","messagePattern":"failed to cross-compile (.+?), see https://beam\\.apache\\.org/documentation/sdks/go-cross-compilation/ for details: (.+?)\n(.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/runners/universal/runnerlib/compile.go","lineNumber":113,"sourceCode":"\n\tcgo := \"0\"\n\n\tlog.Infof(ctx, \"Cross-compiling %v with GOOS=%s GOARCH=%s CGO_ENABLED=%s as %v\", program, goos, goarch, cgo, filename)\n\n\t// Cross-compile given go program. Not awesome.\n\tprogram = program[:strings.LastIndex(program, \"/\")+1]\n\tprogram = program + \".\"\n\tvar build []string\n\tif isTest {\n\t\tbuild = []string{\"go\", \"test\", \"-trimpath\", \"-c\", \"-o\", filename, program}\n\t} else {\n\t\tbuild = []string{\"go\", \"build\", \"-trimpath\", \"-o\", filename, program}\n\t}\n\n\tcmd := exec.Command(build[0], build[1:]...)\n\tcmd.Env = append(os.Environ(), \"GOOS=\"+goos, \"GOARCH=\"+goarch, \"CGO_ENABLED=\"+cgo)\n\tif out, err := cmd.CombinedOutput(); err != nil {\n\t\treturn errors.Errorf(\"failed to cross-compile %v, see https://beam.apache.org/documentation/sdks/go-cross-compilation/ for details: %v\\n%v\", program, err, string(out))\n\t}\n\treturn nil\n}\n","sourceCodeStart":95,"sourceCodeEnd":117,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/runners/universal/runnerlib/compile.go#L95-L117","documentation":"The universal runner builds (cross-compiles) a Go worker binary on the fly when submitting a pipeline to a remote runner. If the `go build` command fails — for the target GOOS/GOARCH or with the container environment settings — the runner wraps the command error and combined output in this error, pointing at the cross-compilation docs.","triggerScenarios":"buildWorkerBinary runs `go build` with GOOS/GOARCH (and optionally CGO_ENABLED / container env) set for a different platform than the local one, and the build fails; called via BuildTempWorkerBinary during job submission.","commonSituations":"Cross-compiling a pipeline that imports cgo-dependent packages; missing Go toolchain on the submission machine; worker package fails to compile due to code errors; unsupported GOOS/GOARCH combination.","solutions":["Read the trailing build output in the error message to find the actual compile failure and fix that code error.","If cgo is the issue, ensure the worker code has no cgo dependencies or adjust CGO_ENABLED in the environment.","Install/verify a matching Go toolchain version on the machine submitting the job.","Use a pre-built worker binary and submit it explicitly (process/container environment) to skip cross-compilation."],"exampleFix":"// before: cgo package breaks cross-compile\n//   CGO_ENABLED=1 with GOOS=linux while building on darwin\n// after: keep the build pure-Go\n//   set environment CGO_ENABLED=0 or remove the cgo-importing dependency","handlingStrategy":"validation","validationCode":"// shell: verify the worker compiles for the target platform before submitting\nGOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -trimpath ./my/worker/package","typeGuard":null,"tryCatchPattern":"if err := beam.Run(ctx, runner, p); err != nil && strings.Contains(err.Error(), \"failed to cross-compile\") {\n    // inspect build output appended to the error and fix the compile error\n}","preventionTips":["Test `go build` of the worker package for the target GOOS/GOARCH before remote submission.","Avoid cgo dependencies in worker code; set CGO_ENABLED=0 for cross-compiles.","Keep the local Go toolchain version compatible with the go.mod of the pipeline.","Use a pre-built worker binary for complex environments."],"tags":["go","beam","cross-compilation","build"],"backgroundTag":"command-not-found","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}