rules_go: Cross compilation is broken with golang.org/x/sys/unix

I am trying to cross compile to linux binary on darwin_amd64 machine. Compiling to darwin_amd64 target works file, cross compiling to linux_amd64 produces the following error:

bash-3.2$ bazel build //:doit_cross
INFO: Analysed target //:doit_cross (0 packages loaded).
INFO: Found 1 target...
ERROR: /Users/pesterni/go/src/github.com/apesternikov/bazel_go_repr/vendor/golang.org/x/sys/unix/BUILD.bazel:3:1: GoCompile vendor/golang.org/x/sys/unix/linux_amd64_pure_stripped/go_default_library~/partial.a failed (Exit 1)
vendor/golang.org/x/sys/unix/flock.go:16:42: undefined: Flock_t
vendor/golang.org/x/sys/unix/sockcmsg_unix.go:37:18: undefined: Cmsghdr
vendor/golang.org/x/sys/unix/sockcmsg_unix.go:43:9: undefined: Cmsghdr
2018/01/04 13:56:51 error running compiler: exit status 1
Target //:doit_cross failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.878s, Critical Path: 0.16s

This problem makes it impossible to build a linux binary (and, consequentially, docker image) referring golang.org/x/sys/unix or any of 2244 packages dependent on it https://godoc.org/golang.org/x/sys/unix?importers. We got this while trying to use github.com/fsnotify/fsnotify.

How to reproduce: clone github.com/apesternikov/bazel_go_repr bazel build //:doit works fine, bazel build //:doit_cross fails. https://github.com/apesternikov/bazel_go_repr/blob/master/BUILD

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 25 (11 by maintainers)

Most upvoted comments

The import errors you mentioned sound like #1304, which was fixed in #1310. Do you still see that error on master? I’m planning to tag a new release tomorrow that will include that fix if you want to wait for that.

I forgot to mention that GOOS=linux GOARCH=amd64 go install github.com/apesternikov/bazel_go_repr works fine of course.