rules_go: Bazel 0.26.0 fixed the autoconfigured C++ toolchains and now break cross-compilation of Go
Hello 😃
With the fix for https://github.com/bazelbuild/bazel/issues/8330 we discovered one flaw in our design of Go cross compilation. Currently rules_go depend on C++ toolchain in //go/private:context.bzl (toolchains = ["@bazel_tools//tools/cpp:toolchain_type"]
). This dependency exists no matter if we actually have C++ dependencies or not.
The problem is that with https://github.com/bazelbuild/bazel/issues/8330 C++ autoconfigured toolchains properly report their constraints, and now Bazel detects that we don’t actually have a C++ cross-compilation toolchain available. As a result the cross-compilation build of go fails:
ERROR: While resolving toolchains for target @io_bazel_rules_go//:go_context_data: no matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type
ERROR: Analysis of target '//:main' failed; build aborted: no matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type
To reproduce, create a hello world go_binary, and build it with bazel build //:hello_world --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64
on linux, (or if you’re on mac, use a different platform).
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 7
- Comments: 52 (42 by maintainers)
Commits related to this issue
- go_proto_compiler: remove dependence on C/C++ toolchain The C compiler was used to set PATH. No idea why that was useful though. Fixes #2089 — committed to jayconrod/rules_go by deleted user 5 years ago
- go_proto_compiler: remove dependence on C/C++ toolchain (#2101) The C compiler was used to set PATH. PATH is needed on Windows to locate DLL files. Instead of requiring the C compiler, just use the ... — committed to bazelbuild/rules_go by jayconrod 5 years ago
- toolchains: remove default value from cgo and darwin constraints Previously, //go/toolchains:cgo_constraint and darwin_constraint had default values cgo_on and is_darwin (on macOS only). This enabled... — committed to jayconrod/rules_go by deleted user 5 years ago
- toolchains: remove default value from cgo and darwin constraints (#2118) Previously, //go/toolchains:cgo_constraint and darwin_constraint had default values cgo_on and is_darwin (on macOS only). Thi... — committed to bazelbuild/rules_go by deleted user 5 years ago
- go_proto_compiler: remove dependence on C/C++ toolchain (#2101) The C compiler was used to set PATH. PATH is needed on Windows to locate DLL files. Instead of requiring the C compiler, just use the s... — committed to bazelbuild/rules_go by jayconrod 5 years ago
- go_proto_compiler: remove dependence on C/C++ toolchain (#2101) The C compiler was used to set PATH. PATH is needed on Windows to locate DLL files. Instead of requiring the C compiler, just use the s... — committed to bazelbuild/rules_go by jayconrod 5 years ago
- go_proto_compiler: remove dependence on C/C++ toolchain (#2101) The C compiler was used to set PATH. PATH is needed on Windows to locate DLL files. Instead of requiring the C compiler, just use the s... — committed to bazelbuild/rules_go by jayconrod 5 years ago
- Fail earlier with a message when C/C++ toolchain is needed but not configured Updates #2089 — committed to jayconrod/rules_go by deleted user 5 years ago
- Fail earlier with a message when C/C++ toolchain is needed but not configured Updates #2089 — committed to jayconrod/rules_go by deleted user 5 years ago
- Fail earlier with a message when C/C++ toolchain is needed but not configured (#2140) Updates #2089 — committed to bazelbuild/rules_go by deleted user 5 years ago
- Remove warning about go_image on Mac It was fixed over a year ago according to https://github.com/bazelbuild/rules_go/issues/2089 I've had some users confused by this message since we tell them to u... — committed to alexeagle/rules_docker by deleted user 3 years ago
- Remove warning about go_image on Mac (#1755) It was fixed over a year ago according to https://github.com/bazelbuild/rules_go/issues/2089 I've had some users confused by this message since we tell... — committed to bazelbuild/rules_docker by alexeagle 3 years ago
Just to recap where we are with this issue:
@io_bazel_rules_go//:cgo_context_data
, which is a dependency of@io_bazel_rules_go//:go_context_data
, hidden behind aselect
expression which only picks it on platforms where cgo is enabled.go_context_data
is a common dependency of all Go rules.cgo_context_data
even though it isn’t required.bazel cquery --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 'somepath(@io_bazel_rules_go//tests/core/go_binary:hello, @io_bazel_rules_go//:cgo_context_data)'
shows that there’s no path through the configured target graph from an example binary rule tocgo_context_data
. It’s possible there’s some dependency sneaking through the toolchains, or there might be a bug in Bazel.I’ve spent several weeks analyzing this issue, and I’ve basically timeboxed it at this point. It should be fixed eventually but probably won’t be any time soon. I’d recommend folks work around this by installing a C/C++ toolchain or configuring a dummy
cc_toolchain
.@hlopko the problem though is that it seems if we put a
--platform
, then thecrosstool_top
is ignored (and I guess the transition fromandroid_crosstool_top
as well)@strican I will gracefully bow out of that decision, no idea with we have more toolchain work to accomplish. I opened a separate for the rules_docker issues.
Probably more @hlopko or @jayconrod’s call I think.
I can confirm I have the same issues as @chrislovecnm above when building with the
--platforms
flag set and the above WORKSPACE rule (8ea79bbd5e6ea09dc611c245d1dc09ef7ab7118a).If
CGO_ENABLED
is how people configure cgo outside of Bazel, then let’s do this!