bazel-contrib / bazel-contrib/toolchains_llvm

toolchain: Apple CC toolchain not found when adding `toolchains_llvm`

Open
#662 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
371
Forks
283
Avg merge
1d 55m
Merged PRs (30d)
25

Description

I'm trying to update our project to start using hermetic toolchains. But **after adding the "toolchains_llvm" rule I get the following error**:

```log
ERROR: /Users/jagoba/projects/salto/saltosystems-internal/srpc/framework/ble/platform/macos/BUILD:6:13: in objc_library rule //ble/platform/macos:ble_macos:
Traceback (most recent call last):
File "/virtual_builtins_bzl/common/objc/objc_library.bzl", line 59, column 52, in _objc_library_impl
File "/virtual_builtins_bzl/common/objc/semantics.bzl", line 32, column 13, in _check_toolchain_supports_objc_compile
Error in fail: Compiling objc_library targets requires the Apple CC toolchain which can be found here: https://github.com/bazelbuild/apple_support#toolchain-setup
```

Our project contains Objective-C code that only builds on Macos. And compiles and runs fine when I use `rules_cc` with the auto detected toolchain.

```bazel
load('@rules_cc//cc:defs.bzl', 'objc_library')

objc_library(
name = 'ble_macos',
srcs = ['ble_macos.m'],
hdrs = ['ble_macos.h'],
sdk_frameworks = ['CoreBluetooth'],
target_compatible_with = ["@platforms//os:macos"],
)
```

Here's my `MODULE.bazel` file for reference:

```bazel
bazel_dep(name = "apple_support", version = "2.2.0", repo_name = "build_bazel_apple_support")
# important apple_support must come above rules_cc
bazel_dep(name = "rules_cc", version = "0.2.16")

# Adding these lines throws the error above
bazel_dep(name = "toolchains_llvm", version = "1.6.0")
# Configure and register the toolchain.
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(
llvm_version = "20.1.0", # https://releases.llvm.org/
)
use_repo(llvm, "llvm_toolchain")
register_toolchains("@llvm_toolchain//:all")
```

NOTE: I originally opened this issue in the [rules_cc repository](https://github.com/bazelbuild/rules_cc/issues/577) but this might be a problem with toolchains_llvm.

Contributor guide

Open the contributing guide

Research direction

Start by reading MODULE.bazel, especially the apple_support, rules_cc, and toolchains_llvm registration, then inspect ble/platform/macos/BUILD and its objc_library target. Reproduce the failure with the shown macOS target and determine why the registered LLVM toolchain does not provide the Apple CC toolchain; done means the target builds without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
objective-c
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.