bazelbuild / rules_go

Go rules for Bazel
Apache License 2.0
1.37k stars 649 forks source link

Missing CC Toolchains for macOS AMD and ARM #3997

Open YukiDayDreamer opened 1 month ago

YukiDayDreamer commented 1 month ago

What version of rules_go are you using?

0.42.0

What version of gazelle are you using?

0.33.0

What version of Bazel are you using?

6.4.0

Does this issue reproduce with the latest releases of all the above?

Yes.

What operating system and processor architecture are you using?

Linux, AMD64

Any other potentially useful information about your toolchain?

Also use 0.10.3 LLVM toolchain.

What did you do?

I ran bazel build //FOO_TARGET --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 and bazel build //FOO_TARGET --platforms=@io_bazel_rules_go//go/toolchain:darwin_arm64.

When we upgraded from bazel version from 5.4.0 to 6.4.0, we found a missing cc toolchain error: in cc_toolchain_alias rule @bazel_tools//tools/cpp:current_cc_toolchain: Unable to find a CC toolchain using toolchain resolution. Did you properly set --platforms?

But this build succeed on Windows: bazel build //FOO_TARGET --platforms=@io_bazel_rules_go//go/toolchain:windows_amd64

What did you expect to see?

It should build successfully.

What did you see instead?

The current workaround we have is to add https://github.com/uber/hermetic_cc_toolchain to make the cc toolchain to be discovered again.

load("@hermetic_cc_toolchain//toolchain:defs.bzl", zig_toolchains = "toolchains")

zig_toolchains()

register_toolchains(
    "@zig_sdk//toolchain:darwin_amd64",
    "@zig_sdk//toolchain:darwin_arm64",
)
aaomidi commented 2 weeks ago

There are some issues with hermetic_cc_toolchain and MacOS specifically: https://github.com/uber/hermetic_cc_toolchain/issues/10

I was running Bazel in a Nix shell environment, and had to setup llvm toolchains to get it working on MacOS consistently.

If I don't use a Nix shell environment though, bazel builds worked fine (TM)