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
Copy Markdown

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)
@trybka
Copy link
Copy Markdown
Collaborator

trybka commented Mar 6, 2026

Can you rebase and merge your PR? I think the LLD changes have already been addressed in #516 but the clang-scan-deps fixes might still be valuable.

cc: @PikachuHyA @fmeum

path_arr = cc_str.split("/")[:-1]
path_arr.append("clang-scan-deps")
deps_scanner = "/".join(path_arr)
# Find clang-scan-deps via PATH lookup instead of assuming it's in the
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d prefer to look for clang-scan-deps in the same directory first, and only fall back to searching in PATH if it isn’t found. The reason is that I want to ensure, as much as possible, that clang and clang-scan-deps are from the same version.

Would this change break your workflow?

@armandomontanez armandomontanez added type: bug Something that should be working isn't working P3 We're not considering working on this, but happy to review a PR. (No assignee) platform: darwin category: toolchains labels Mar 26, 2026
@hvadehra hvadehra removed their request for review April 21, 2026 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: toolchains P3 We're not considering working on this, but happy to review a PR. (No assignee) platform: darwin type: bug Something that should be working isn't working

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

4 participants