<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/133994>133994</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang/Driver] MacOS issue with SDK include dir auto detection
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mizvekov
      </td>
    </tr>
</table>

<pre>
    Homebrew recently made llvm 20 formula available.

With the clang binary available in that formula, there is trouble when using libc++ and adding the Xcode SDK include dir in the command line.

Simple reproducer:
```C++
#include <vector>
```
Compile with `clang++ -isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -fsyntax-only test.cc`

Results in:
```
/opt/homebrew/Cellar/llvm/20.1.1/bin/../include/c++/v1/cstdlib:93:5: error: <cstdlib> tried including <stdlib.h> but didn't find libc++'s <stdlib.h> header.           This usually means that your header search paths are not configured properly.           The header search paths should contain the C++ Standard Library headers before           any C Standard Library, and you are probably using compiler flags that make that           not be the case.
   93 | #   error <cstdlib> tried including <stdlib.h> but didn't find libc++'s <stdlib.h> header. \
```

This makes it problematic to build llvm itself from that compiler.

Here is a workaround:
1) Install homebrew versions of zlib, libxml2 and libedit:
`brew install zlib libxml2 libedit`
2) Add the following variables to your cmake invocation:
```
"CMAKE_OSX_SYSROOT": "",
"Backtrace_INCLUDE_DIR": "",
"CMAKE_PREFIX_PATH": "/opt/homebrew/opt/zlib;/opt/homebrew/opt/libxml2;/opt/homebrew/opt/libedit"
```
3) If you are using LLVM_OPTIMIZED_TABLEGEN, then these flags are not automatically forwarded to the NATIVE cross compile target, you have to add the following variable as well:
```
"CROSS_TOOLCHAIN_FLAGS_NATIVE": "-DCMAKE_OSX_SYSROOT= -DBacktrace_INCLUDE_DIR= -DCMAKE_PREFIX_PATH=\"/opt/homebrew/opt/zlib;/opt/homebrew/opt/libxml2;/opt/homebrew/opt/libedit\""
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8Vk9z4j4S_TTi0hWXkSGEAwfH4Ak1SUiF7Gx2L1TbamNtZMslyWSYT78l24RMkqnfbSgfKOmp_73XLaG1cl8TLdj0mk2XI2xdqc2ikr8O9KIPo0yL4-JGV5QZegVDOdVOHaFCQaDUoQIeQqFN1SoEPKBUmCkKWBizMP63dCW4kiBXWO8hkzWa4xkFsgZXojudZzzxaEMgLTijW495LamG1sp6D0pmOePXjF8D1gJQCL_q7T_nWhBsl99B1rlqBYGQpjdPkOuq8ngl61NgW1k1isBQY7RoczIs8svsMuy_pHfjl3h0Msmi5EC504ZFq_dgFsaJrhrpg_UJs8uwy3cI9ULao3VUAeNp3DRK5uikri3jaRd2gE3DeJro2lHt_PKSDqR0Q4bx9EGh8-Xx63eYb7bPQTMsfUBul9_fgax4YTxtrd85JXBR2GPt8OeFrtURHFkX5HmfAAvjR7KtchZk_aEYXRVS3TjG03IQgg-YlEJv3quA8ZSHwTgYM55msmY8DYKzZ8bTgTjG04PH5NYJJTMWxfOIRfGURTGQMb62sS_02_4KnJEkBl493yxK-s2g9NtZ60BIUTM-c1DIjufszdvMfsSXhIJMAOffUykttLZF5XVNWNtelUfdmgEOltDkJTToSgtoCGrtINd1IfetIQGN8Syo4-926cvjttStEv60w0Gig95g67AWaATcysz4XunPW8io0IbeGcf6CMknvO8gL_WjbrsoG6MzzNRxaKC8l6mBQuF-yLLCF-r_nX8-uYz65kHbNQ0AzCNgswQYjwB6sv4OU2yafJRjGHek-dgtSNflqahCJ3NwGrJWKtFPJ-ksqQIKo6s-y1MNhklwM4wbhFdtXtDotha9_seMz2FdW4dKwUn3cCBjffeCLuCXz5snPo2fleLQD5mMhHRvLdQdkoMVf-ANfUJ2GXHvLBaiq3mhldKvvoIHNNJPSuuz6vSYd3zJ-qD7MfJVr_LkLv6-2m22z7vtf7aPm80T47xrLM67L-lh15i_OIM57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