rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

gazelle extension breaks cc toolchain resolution during cross compiling on darwin arm64

Open xytan0056 opened this issue 1 year ago β€’ 6 comments

🐞 bug report

Affected Rule

gazelle extension

Is this a regression?

No, previous versions also has this issue

Description

After enabling python extension in gazelle https://github.com/xytan0056/cgo_test/blob/30a62b2654561f0d08e98dbf14c2e6a7c8d55e74/BUILD.bazel#L22

gazelle_binary(
    name = "gazelle_bin",
    languages = [
...
        "@com_github_bazelbuild_rules_python_gazelle//python",
    ]
)

We cannot cross compile gazelle on "darwin arm64" to "darwin amd64" with --incompatible_enable_cc_toolchain_resolution

πŸ”¬ Minimal Reproduction

https://github.com/xytan0056/cgo_test/tree/30a62b2654561f0d08e98dbf14c2e6a7c8d55e74

bazel build --announce_rc  //:gazelle_bin --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 --incompatible_enable_cc_toolchain_resolution

fails

πŸ”₯ Exception or Error



Traceback (most recent call last):
        File "/virtual_builtins_bzl/common/cc/cc_toolchain_alias.bzl", line 26, column 48, in _impl
        File "/virtual_builtins_bzl/common/cc/cc_helper.bzl", line 219, column 17, in _find_cpp_toolchain
Error in fail: Unable to find a CC toolchain using toolchain resolution. Target: @@bazel_tools//tools/cpp:current_cc_toolchain, Platform: @@io_bazel_rules_go//go/toolchain:darwin_amd64, Exec platform: @@local_config_platform//:host

The error is gone when either

  1. python extension is removed or
  2. CC toolchain resolution is disabled via --noincompatible_enable_cc_toolchain_resolution

🌍 Your Environment

Operating System:

  
uname -a
Darwin tanx-D5VYHJD2X7 23.4.0 Darwin Kernel Version 23.4.0: Wed Feb 21 21:44:43 PST 2024; root:xnu-10063.101.15~2/RELEASE_ARM64_T6000 arm64
  

Output of bazel version:

  
Bazelisk version: development
Build label: 7.1.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Thu Mar 21 18:08:59 2024 (1711044539)
Build timestamp: 1711044539
Build timestamp as int: 1711044539
  

Rules_python version:

  
v0.0.0-20240321125912-c5c03b2477dd
  

Anything else relevant?

xytan0056 avatar Mar 26 '24 05:03 xytan0056

From the first glance I am not sure how this is gazelle plugin's problem.

What kind of toolchains do you have cotfigured to build gazelle? I don't see anything about it in the repro.

aignas avatar Apr 09 '24 23:04 aignas

we just use normal golang toolchain https://github.com/xytan0056/cgo_test/blob/30a62b2654561f0d08e98dbf14c2e6a7c8d55e74/WORKSPACE#L193

The problem is cross-compilation of gazelle works all good before enabling the python extension

xytan0056 avatar Apr 10 '24 00:04 xytan0056

I think this is because we include a .zip file with the interpreter and the python code that parses the python files.

The code in question is here: https://github.com/bazelbuild/rules_python/blob/4be00a69ae3a0c4e7ef3a5f952254bacd16d0a2a/gazelle/python/BUILD.bazel#L70

@alexeagle has mentioned in https://github.com/bazelbuild/rules_python/commit/a94deb8373568ca5af7be6c813c81a3aa2e77d6e that they may be working on a better version for their aspect-cli, but I am not sure if that was done and if it has, I am not sure if he has any plans (if it is feasible) on upstreaming the work to this repo.

Note, that in https://github.com/bazelbuild/rules_python/pull/1485 we discussed about the effect of that change breaking cross-compilation, but I am not sure if it is documented in README.

aignas avatar Apr 17 '24 08:04 aignas

Actually, the root cause is in py_binary, not the zip file. Created a separate ticket with reproduction: #1857.

linzhp avatar Apr 17 '24 15:04 linzhp

Closing this ticket as fixing #1857 would fix this as well.

aignas avatar May 13 '24 08:05 aignas

Re-opening because there is a PR that will address the cross-building of the gazelle plugin.

aignas avatar May 15 '24 08:05 aignas