This is an archive of the discontinued LLVM Phabricator instance.

[clang][darwin] Fix search path logic for C_INCLUDE_DIRS
ClosedPublic

Authored by mhinz on Oct 19 2019, 5:29 PM.

Details

Summary

For each absolute path given to C_INCLUDE_DIRS, we want it to be added as-is to
the include search path. Relative paths should be prefixed with the sysroot.

Diff Detail

Event Timeline

mhinz created this revision.Oct 19 2019, 5:29 PM
ldionne requested changes to this revision.Oct 22 2019, 3:38 PM

Good find! The following drivers (at least) appear to have the same problem:

clang/lib/Driver/ToolChains/WebAssembly.cpp:236
clang/lib/Driver/ToolChains/Solaris.cpp:247
clang/lib/Driver/ToolChains/Linux.cpp:677
clang/lib/Driver/ToolChains/Hurd.cpp:148
clang/lib/Driver/ToolChains/Fuchsia.cpp:289
clang/lib/Driver/ToolChains/Darwin.cpp:1862

This makes me wonder whether C_INCLUDE_DIRS is useful at all. Does anybody use it? Also, if we keep C_INCLUDE_DIRS, it would be nice to add a test for this.

This revision now requires changes to proceed.Oct 22 2019, 3:38 PM
mhinz updated this revision to Diff 231266.Nov 27 2019, 8:14 AM

Apply fix to all toolchains.

mhinz added a comment.Nov 27 2019, 8:22 AM

I applied the fix to all toolchains now, but I'm unsure how to write a test for it. Neither could I find tests for similar options like -DDEFAULT_SYSROOT.

My use case: I want to build a clang that has the same search path as the clang shipped with macOS.

$ /usr/bin/clang -E -xc -v /dev/null
[snip]
#include <...> search starts here:
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
[snip]

For this, I need to pass this to cmake:

-DC_INCLUDE_DIRS="/usr/local/include:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include"
-DDEFAULT_SYSROOT="$(xcrun --show-sdk-path)"
ldionne accepted this revision.Jan 29 2020, 5:00 PM

Do you have commit access?

This revision is now accepted and ready to land.Jan 29 2020, 5:00 PM
mhinz added a comment.Jan 30 2020, 4:22 AM

Do you have commit access?

No. :)

This revision was automatically updated to reflect the committed changes.