Skip to content
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

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

Closed
xytan0056 opened this issue Mar 26, 2024 · 6 comments · Fixed by #1895
Closed
Labels
gazelle Gazelle plugin related issues help wanted

Comments

@xytan0056
Copy link

🐞 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?

@aignas aignas added the gazelle Gazelle plugin related issues label Apr 9, 2024
@aignas
Copy link
Collaborator

aignas commented Apr 9, 2024

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.

@xytan0056
Copy link
Author

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

@aignas
Copy link
Collaborator

aignas commented Apr 17, 2024

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:

@alexeagle has mentioned in a94deb8 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 #1485 we discussed about the effect of that change breaking cross-compilation, but I am not sure if it is documented in README.

@linzhp
Copy link
Contributor

linzhp commented Apr 17, 2024

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

@aignas
Copy link
Collaborator

aignas commented May 13, 2024

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

@aignas aignas closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
@aignas aignas reopened this May 15, 2024
@aignas
Copy link
Collaborator

aignas commented May 15, 2024

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

github-merge-queue bot pushed a commit that referenced this issue May 20, 2024
Remove gazelle plugin's python deps and make it hermetic. No more
relying on the system interpreter.

Use TreeSitter to parse Python code and use
https://github.com/pypi/stdlib-list to determine whether a module is in
std lib.

Fixes #1825
Fixes #1599
Related #1315
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gazelle Gazelle plugin related issues help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants