Skip to content

Fix clang-scan-deps PATH lookup and lld detection on macOS#563

Open
srikantharun wants to merge 1 commit intobazelbuild:mainfrom
srikantharun:fix/clang-scan-deps-and-lld-detection
Open

Fix clang-scan-deps PATH lookup and lld detection on macOS#563
srikantharun wants to merge 1 commit intobazelbuild:mainfrom
srikantharun:fix/clang-scan-deps-and-lld-detection

Conversation

@srikantharun
Copy link

Summary

This PR fixes two related toolchain configuration issues:

1. clang-scan-deps PATH lookup (fixes #553)

Problem: clang-scan-deps path was hardcoded by assuming it's in the same directory as the compiler:

cc_str = str(cc)
path_arr = cc_str.split("/")[:-1]
path_arr.append("clang-scan-deps")
deps_scanner = "/".join(path_arr)

Solution: Use PATH lookup via which() first, with fallback to the compiler directory for backward compatibility.

2. lld path detection on macOS (fixes #499)

Problem: _find_linker_path() used the last quoted path line from stderr:

invocations = [line for line in result.stderr.splitlines() if line.startswith(" \"")]
linker_command = invocations[-1]  # This picks up warning lines!

When lld emits warnings (e.g., ld64.lld: warning: directory not found for option -L/usr/local/lib), the warning appears after the linker invocation, causing the detection to fail.

Solution: Look for the specific linker invocation line by matching linker patterns (ld.lld, ld64.lld, ld.gold, gold) instead of blindly using the last line.

Test plan

  • Verify clang-scan-deps is found via PATH when available
  • Verify lld detection works on macOS with Homebrew lld that emits warnings
  • Verify backward compatibility when clang-scan-deps is only in compiler directory

This commit fixes two issues:

1. clang-scan-deps PATH lookup (fixes bazelbuild#553)
   - Previously, clang-scan-deps path was hardcoded by assuming it's in
     the same directory as the compiler
   - Now uses PATH lookup via `which()` first, with fallback to the
     compiler directory for backward compatibility

2. lld path detection on macOS (fixes bazelbuild#499)
   - Previously, _find_linker_path() used the last quoted path line from
     stderr, which breaks when lld emits warnings after the invocation
   - Now looks for the specific linker invocation line by matching
     linker patterns (ld.lld, ld64.lld, ld.gold, gold)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong path for clang-scan-deps Path to lld is not detected robustly on MacOS

1 participant