bazelbuild / bazelbuild/rules_cc
Path to lld is not detected robustly on MacOS
- Dominant language
- Starlark
- Stars
- 247
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
The path to lld is detected by invoking `clang empty.cc -v` and inspect the last line of the output: https://github.com/bazelbuild/rules_cc/blob/30977f259bef40b4b9930868ecaf84c5b8a300c6/cc/private/toolchain/unix_cc_configure.bzl#L200-L201
However lld may emit warnings (see below) building `empty.cc` and subsequently breaks the detection logic resulting in an argument of the form `-fuse-ld=ld64.lld:` (note the colon at the end) being passed to the compiler.
Here is one situation when lld emits a warning.
1. Apple Clang is detected as the compiler and `ld64.lld` is present in PATH (for example installed by homebrew).
2. Apple Clang then calls `ld64.lld` with `-L/usr/local/lib` in the flags.
3. If the directory `/usr/local/lib` does not exist, then lld emits a warning.
In this situation, the last lines of `result.stderr` is
```
... (omitted)
End of search list.
"/opt/homebrew/bin/ld64.lld" -demangle -no_deduplicate -dynamic -arch arm64 -platform_version macos 15.0.0 15.2 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mllvm -enable-linkonceodr-outlining -o /dev/null -L/usr/local/lib /var/folders/0v/nn5rkhrs3r72b72dfbrlwfbh0000gn/T/empty-da6fa5.o --start-lib --end-lib -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/16/lib/darwin/libclang_rt.osx.a
ld64.lld: warning: directory not found for option -L/usr/local/lib
```
# How to reproduce
MODULE.bazel
```
bazel_dep(name = "rules_cc", version = "0.2.10")
```
BUILD.bazel
```
load("@rules_cc//cc:defs.bzl", "cc_binary")
cc_binary(
name = "hello-world",
srcs = ["main.cc"],
)
```
main.cc
```
int main() { return 0; }
```
Command:
```
bazel build //:hello-world
```
Contributor guide
Assessment
This issue has not been assessed yet.