Hello, I’m trying to build a go binary for a speci...
# general
p
Hello, I’m trying to build a go binary for a specific platform so i can build a docker image locally, how can I pass
GOOS
and
GOARCH
? I’ve seen a few people ask before but can’t see any working suggestions
f
Cross-compilation for Go is not currently supported. (This is a general Pants problem and not only affects the Go backend.) You could try building the go binary inside a Docker container using the
docker_environment
environment target and specifying that environment on the
go_binary
target via the
environment
field. See https://www.pantsbuild.org/v2.16/docs/environments and https://www.pantsbuild.org/v2.16/docs/reference-go_binary#codeenvironmentcode for more information on environments.
It is a general Pants problem because we do not currently model the execution platform in targets.
So Pants assumes execution platform == host platform.
p
Copy code
[ERROR] Completed: Compile with Go - (environment:linux_docker, <http://google.golang.org/grpc/internal/syscall|google.golang.org/grpc/internal/syscall>) - <http://google.golang.org/grpc/internal/syscall|google.golang.org/grpc/internal/syscall> failed (exit code 1).
gopath/pkg/mod/google.golang.org/grpc@v1.55.0/internal/syscall/syscall_linux.go:29:2: could not import <http://golang.org/x/sys/unix|golang.org/x/sys/unix> (open : no such file or directory)
Thanks i’ve made some progress now getting this error when building in docker enviornment but the go.mod has that package
This works in CI but not locally on my local machine which is a mac
Is this because the platform is still mac but the compilation is done on the docker environment?
f
It could be a bug in how package analysis and/or dependency inference is done in this case. The file missing is likely the package archive for the dependency in question.
p
Is there a way I can work around this for now?
f
No because the Go compiler expects to be supplied with the built package archives of all dependent packages.
and Pants is failing to do that
p
Should i raise this as an issue in github?
f
yes please
l
@polite-nail-30687 did you ever get around to opening an issue for this?