Skip to content

Commit a1c4926

Browse files
authored
[libc] Include Linux kernel headers in the full build (#97486)
When doing a full build for Linux, as of #97461 we no longer include system headers, but we need to include Linux kernel headers.
1 parent 58fd3be commit a1c4926

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

libc/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ set(LIBC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
3939

4040
set(LIBC_ENABLE_USE_BY_CLANG OFF CACHE BOOL "Whether or not to place libc in a build directory findable by a just built clang")
4141

42+
set(LIBC_KERNEL_HEADERS "/usr/include" CACHE STRING "Path to Linux kernel headers")
43+
4244
# Defining a global namespace to enclose all libc functions.
4345
set(default_namespace "__llvm_libc")
4446
if(LLVM_VERSION_MAJOR)

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,17 @@ function(_get_common_compile_options output_var flags)
5151
if(LIBC_CC_SUPPORTS_NOSTDLIBINC)
5252
list(APPEND compile_options "-nostdlibinc")
5353
elseif(COMPILER_RESOURCE_DIR)
54+
# TODO: We should require COMPILER_RESOURCE_DIR to be set.
5455
list(APPEND compile_options "-isystem${COMPILER_RESOURCE_DIR}/include")
5556
list(APPEND compile_options "-nostdinc")
5657
endif()
58+
# TODO: We should set this unconditionally on Linux.
59+
if(LIBC_TARGET_OS_IS_LINUX AND
60+
(LIBC_CC_SUPPORTS_NOSTDLIBINC OR COMPILER_RESOURCE_DIR))
61+
# We use -idirafter to avoid preempting libc's own headers in case the
62+
# directory (e.g. /usr/include) contains other headers.
63+
list(APPEND compile_options "-idirafter${LIBC_KERNEL_HEADERS}")
64+
endif()
5765
endif()
5866

5967
if(LIBC_COMPILER_HAS_FIXED_POINT)

0 commit comments

Comments
 (0)