Remove Homebrew LLVM during macOS CI setup#125763
Conversation
The macos-15 runner image (20260317.0278) upgraded LLVM from 17 to 18, placing clang-18 at /usr/local/bin/clang-18. The init-compiler.sh version search loop finds this upstream LLVM before falling through to unversioned clang (AppleClang), causing three classes of build failures: - NativeAOT: invalid CFI advance_loc assembly errors (LLVM 18 stricter) - Native libs: Swift linker undefined symbols (missing Apple Swift paths) - CoreCLR: CMake LINK_GROUP RESCAN unsupported (LLVM linker vs Apple ld) On Darwin, use xcrun --find clang to resolve the Xcode toolchain clang (AppleClang) instead of searching PATH for versioned LLVM binaries. This matches the pattern Mono already uses in mono.proj. The existing CLR_CC/CLR_CXX override and explicit version requests (e.g. clang-18) are preserved as escape hatches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The previous commit used xcrun --find clang to resolve the Xcode toolchain clang directly. While this correctly avoids Homebrew LLVM, the raw Xcode clang does not inject -isysroot automatically, causing the linker to fail to find system libraries (libdl, libobjc, libswiftCore, etc.) on macOS 26 with Xcode 26. Switch to /usr/bin/clang, the Apple-provided shim that always delegates to the active Xcode's AppleClang and automatically injects -isysroot pointing to the macOS SDK. This preserves the Homebrew LLVM avoidance while ensuring native linking works correctly.
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
You can also share your feedback on Copilot code review. Take the survey.
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
|
Looks like the fix is incomplete - the tests are failing due to references to llvm@18 libraries: |
gen-buildsys.sh sources init-compiler.sh which resolves the correct compiler into CC/CXX, but only CCC_CC/CCC_CXX (scan-build variables) were exported. CMake ignores those and falls back to PATH-based detection, which can find Homebrew LLVM 18 before Apple clang on macOS CI runners. This caused native host test libraries like libmockhostpolicy.dylib to link against Homebrew's libunwind.
There was a problem hiding this comment.
Pull request overview
This PR adjusts macOS native build configuration to prefer Apple’s /usr/bin/clang shim and avoid accidentally picking up Homebrew LLVM/linker behavior, reducing recent CI failures on macOS runners.
Changes:
- Stop adding
/usr/local/includefor Apple targets to avoid pulling in Homebrew headers/libs. - Force a macOS SDK sysroot for CMake on
osxbuilds and prefer/usr/bin/clangon Darwin when using defaultclang. - Propagate compiler env vars from
gen-buildsys.shto improve consistency of compiler selection.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/native/libs/configure.cmake | Avoids injecting /usr/local/include on Apple targets to prevent Homebrew header/library conflicts. |
| src/coreclr/pal/src/CMakeLists.txt | Skips /usr/local/include for Apple targets in PAL build. |
| src/coreclr/debug/createdump/CMakeLists.txt | Skips /usr/local/include for Apple targets in createdump build. |
| eng/native/gen-buildsys.sh | Exports compiler variables for downstream CMake invocation. |
| eng/native/build-commons.sh | Forces CMAKE_OSX_SYSROOT=macosx for osx builds to stabilize header/lib resolution. |
| eng/common/native/init-compiler.sh | Prefers /usr/bin/clang shim on Darwin for default clang and clears LIBRARY_PATH to avoid Homebrew leakage. |
You can also share your feedback on Copilot code review. Take the survey.
The CI runner image may ship with a Homebrew LLVM whose libraries (e.g., an x86_64-only libunwind.dylib in /usr/local/lib) conflict with the Apple SDK and break native linking. The build uses Apple clang from /usr/bin/clang exclusively and does not need Homebrew LLVM.
b32c396 to
5c5fdb4
Compare
|
still getting " Feature 'RESCAN', specified through generator-expression '$<LINK_GROUP>' to" |
|
yeah. we'd need to |
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
You can also share your feedback on Copilot code review. Take the survey.
ok this was just due to how I tested - if you run |
|
/backport to release/9.0 |
|
/backport to release/8.0 |
|
Started backporting to |
|
Started backporting to |
|
@steveisok backporting to git am output$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Prefer AppleClang from Xcode toolchain on macOS
Applying: Use Apple toolchain shim instead of raw Xcode clang on macOS
Applying: Export CC and CXX in gen-buildsys.sh so CMake uses the resolved compiler
Applying: Remove Homebrew LLVM during macOS CI setup
error: sha1 information is lacking or useless (eng/native/gen-buildsys.sh).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0004 Remove Homebrew LLVM during macOS CI setup
Error: The process '/usr/bin/git' failed with exit code 128 |
|
@steveisok backporting to git am output$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Prefer AppleClang from Xcode toolchain on macOS
Using index info to reconstruct a base tree...
M eng/common/native/init-compiler.sh
Falling back to patching base and 3-way merge...
Auto-merging eng/common/native/init-compiler.sh
CONFLICT (content): Merge conflict in eng/common/native/init-compiler.sh
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Prefer AppleClang from Xcode toolchain on macOS
Error: The process '/usr/bin/git' failed with exit code 128 |
The CI runner image may ship with a Homebrew LLVM whose libraries (e.g., an x86_64-only libunwind.dylib in /usr/local/lib) conflict with the Apple SDK and break native linking. The build uses Apple clang from /usr/bin/clang exclusively and does not need Homebrew LLVM. Backport of dotnet#125763
The CI runner image may ship with a Homebrew LLVM whose libraries (e.g., an x86_64-only libunwind.dylib in /usr/local/lib) conflict with the Apple SDK and break native linking. The build uses Apple clang from /usr/bin/clang exclusively and does not need Homebrew LLVM. Backport of dotnet#125763
The CI runner image may ship with a Homebrew LLVM whose libraries (e.g., an x86_64-only libunwind.dylib in /usr/local/lib) conflict with the Apple SDK and break native linking. The build uses Apple clang from /usr/bin/clang exclusively and does not need Homebrew LLVM. Backport of dotnet#125763
The CI runner image may ship with a Homebrew LLVM whose libraries (e.g., an x86_64-only libunwind.dylib in /usr/local/lib) conflict with the Apple SDK and break native linking. The build uses Apple clang from /usr/bin/clang exclusively and does not need Homebrew LLVM. Backport of dotnet#125763
The CI runner image may ship with a Homebrew LLVM whose libraries (e.g., an x86_64-only libunwind.dylib in /usr/local/lib) conflict with the Apple SDK and break native linking. The build uses Apple clang from /usr/bin/clang exclusively and does not need Homebrew LLVM. Backport of #125763
The CI runner image may ship with a Homebrew LLVM whose libraries (e.g., an x86_64-only libunwind.dylib in /usr/local/lib) conflict with the Apple SDK and break native linking. The build uses Apple clang from /usr/bin/clang exclusively and does not need Homebrew LLVM. Backport of #125763
The CI runner image may ship with a Homebrew LLVM whose libraries (e.g., an x86_64-only libunwind.dylib in /usr/local/lib) conflict with the Apple SDK and break native linking. The build uses Apple clang from /usr/bin/clang exclusively and does not need Homebrew LLVM. Backport of dotnet#125763
The CI runner image may ship with a Homebrew LLVM whose libraries (e.g., an x86_64-only libunwind.dylib in /usr/local/lib) conflict with the Apple SDK and break native linking. The build uses Apple clang from /usr/bin/clang exclusively and does not need Homebrew LLVM. Backport of dotnet#125763
The CI runner image may ship with a Homebrew LLVM whose libraries (e.g., an x86_64-only libunwind.dylib in /usr/local/lib) conflict with the Apple SDK and break native linking. The build uses Apple clang from /usr/bin/clang exclusively and does not need Homebrew LLVM. Backport of dotnet#125763
The CI runner image may ship with a Homebrew LLVM whose libraries (e.g., an x86_64-only libunwind.dylib in /usr/local/lib) conflict with the Apple SDK and break native linking. The build uses Apple clang from /usr/bin/clang exclusively and does not need Homebrew LLVM. Backport of dotnet#125763
…25790) The CI runner image may ship with a Homebrew LLVM whose libraries (e.g., an x86_64-only libunwind.dylib in /usr/local/lib) conflict with the Apple SDK and break native linking. The build uses Apple clang from /usr/bin/clang exclusively and does not need Homebrew LLVM. Backport of #125763 Co-authored-by: vseanreesermsft <78103370+vseanreesermsft@users.noreply.github.com>
…25789) The CI runner image may ship with a Homebrew LLVM whose libraries (e.g., an x86_64-only libunwind.dylib in /usr/local/lib) conflict with the Apple SDK and break native linking. The build uses Apple clang from /usr/bin/clang exclusively and does not need Homebrew LLVM. Backport of #125763 Co-authored-by: vseanreesermsft <78103370+vseanreesermsft@users.noreply.github.com>
The macos-15 CI runner image ships with Homebrew LLVM 18, which installs libraries (e.g., an x86_64-only libunwind.dylib) into /usr/local/lib. The macOS linker searches /usr/local/lib by default, finds the wrong-architecture library, rejects it, and leaves symbols like _unw_step and __Unwind_Resume unresolved — breaking all native linking on macOS. In addition, it'll use default to the wrong clang during compile and that causes additional havoc.
The build uses Apple clang from /usr/bin/clang exclusively and does not need Homebrew LLVM. This PR removes it during CI setup via brew uninstall in install-dependencies.sh.
Fixes #125757