-
-
Notifications
You must be signed in to change notification settings - Fork 668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pure
has no effect when goarch
and goos
are auto
#3033
Comments
Thank you for the description and reproducer! I don't have a lot of knowledge about platform handling, but I have a few questions after taking a quick look -
I suppose the goal is to have a platform declaration be agnostic of cgo? I'm not sure what that would take. I would be happy to merge a fix, if you have an idea what needs fixing. |
Per I suspect the documentation for
I don't see any C/C++ toolchain detection going on, and I don't understand why it wouldn't work when not cross-compiling either. The documentation for building pure binaries shows an example of using This behaviour can be observed by providing Bazel with an invalid ❯ bazel --noworkspace_rc build --compiler=some_invalid_compiler //:pure_auto_auto
WARNING: The following rc files are no longer being read, please transfer their contents or import their path into one of the standard rc files:
/home/thomas/code/github.com/uhthomas/rules_go-issue/.bazelrc
ERROR: /home/thomas/.cache/bazel/_bazel_thomas/a08a8b424dc00c9fd5788b8c33b3f4a4/external/local_config_cc/BUILD:47:19: in cc_toolchain_suite rule @local_config_cc//:toolchain: cc_toolchain_suite '@local_config_cc//:toolchain' does not contain a toolchain for cpu 'k8' and compiler 'some_invalid_compiler'.
ERROR: Analysis of target '//:pure_auto_auto' failed; build aborted: Analysis of target '@local_config_cc//:toolchain' failed
INFO: Elapsed time: 0.411s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
❯ bazel --noworkspace_rc build --compiler=some_invalid_compiler //:pure_linux_amd64
WARNING: The following rc files are no longer being read, please transfer their contents or import their path into one of the standard rc files:
/home/thomas/code/github.com/uhthomas/rules_go-issue/.bazelrc
INFO: Analyzed target //:pure_linux_amd64 (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:pure_linux_amd64 up-to-date:
bazel-out/k8-fastbuild-ST-05b09dfdd2e5/bin/pure_linux_amd64_/pure_linux_amd64
INFO: Elapsed time: 0.717s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action I imagine the fix would be to configure cgo independently of the platform. What are your thoughts? |
Maybe there's a misunderstanding.. I think it does work, when using the platforms that rules_go defines. It only doesn't work with the platforms you've defined. For example, this builds successfully:
|
This is likely because it's not actually building a pure binary. Providing an invalid C/C++ compiler to Bazel results in a build failure, where it shouldn't. ❯ bazel --noworkspace_rc build --compiler=some_invalid_compiler --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64_cgo //:pure_auto_auto
WARNING: The following rc files are no longer being read, please transfer their contents or import their path into one of the standard rc files:
/home/thomas/code/github.com/uhthomas/rules_go-issue/.bazelrc
INFO: Build option --platforms has changed, discarding analysis cache.
ERROR: /home/thomas/.cache/bazel/_bazel_thomas/a08a8b424dc00c9fd5788b8c33b3f4a4/external/local_config_cc/BUILD:47:19: in cc_toolchain_suite rule @local_config_cc//:toolchain: cc_toolchain_suite '@local_config_cc//:toolchain' does not contain a toolchain for cpu 'k8' and compiler 'some_invalid_compiler'.
ERROR: Analysis of target '//:pure_auto_auto' failed; build aborted: Analysis of target '@local_config_cc//:toolchain' failed
INFO: Elapsed time: 3.216s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 7738 targets configured) However, it does again work when ❯ bazel --noworkspace_rc build --compiler=some_invalid_compiler --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64_cgo //:pure_linux_amd64
WARNING: The following rc files are no longer being read, please transfer their contents or import their path into one of the standard rc files:
/home/thomas/code/github.com/uhthomas/rules_go-issue/.bazelrc
INFO: Analyzed target //:pure_linux_amd64 (0 packages loaded, 229 targets configured).
INFO: Found 1 target...
Target //:pure_linux_amd64 up-to-date:
bazel-out/k8-fastbuild-ST-05b09dfdd2e5/bin/pure_linux_amd64_/pure_linux_amd64
INFO: Elapsed time: 1.412s, Critical Path: 0.40s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action Regardless, it should not be necessary to specify a platform for the |
I don't think
^ Above, |
I see, thank you for your investigation and clarification. So it seems that pure binaries are correctly built, but the Go toolchain incorrectly depends on a CC toolchain despite being unused. This is because the rules_go transition implementation incorrectly assumes cross-compilation only occurs with It looks like there has been some discussion on C++ autodetection before in #2089. I'm not sure it's possible to remove the cc compiler from the dependency graph automatically due to this explicit reference (see Integrating with C++ Rules). Would you be happy to accept a PR which modifies the rules_go transition implementation to set The above suggestion doesn't resolve for |
Sure, that change sounds strictly positive to me. Thanks |
bazelbuild/bazel#14726 should help with this! |
Looks like optional toolchains will make it into the next LTS (bazelbuild/bazel#3601 (comment)). This will then be easy to resolve. |
Any update to this? |
What version of rules_go are you using?
v0.29.0
What version of gazelle are you using?
v0.24.0
What version of Bazel are you using?
4.2.2
Does this issue reproduce with the latest releases of all the above?
Yes.
What operating system and processor architecture are you using?
linux x86_64 and macos x86_64.
Any other potentially useful information about your toolchain?
None.
What did you do?
Configure the
pure
attribute on ago_binary
target wheregoarch
andgoos
areauto
.What did you expect to see?
It should have an effect.
What did you see instead?
It does not have an effect.
See this repository for a full reproduction and explanation.
The text was updated successfully, but these errors were encountered: