[libc-commits] [libc] [libc] Include Linux kernel headers in the full build (PR #97486)

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Tue Jul 2 14:53:00 PDT 2024


https://github.com/petrhosek created https://github.com/llvm/llvm-project/pull/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.

>From 6edadbc47ad6307ec05e7159ad33b2a3a93b2d42 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Tue, 2 Jul 2024 14:50:55 -0700
Subject: [PATCH] [libc] Include Linux kernel headers in the full build

When doing a full build for Linux, as of #97461 we no longer include
system headers, but we need to include Linux kernel headers.
---
 libc/CMakeLists.txt                                 | 2 ++
 libc/cmake/modules/LLVMLibCCompileOptionRules.cmake | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 4ffcd55ba9500..013b17b03f570 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -39,6 +39,8 @@ set(LIBC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
 
 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")
 
+set(LIBC_KERNEL_HEADERS "/usr/include" CACHE STRING "Path to Linux kernel headers")
+
 # Defining a global namespace to enclose all libc functions.
 set(default_namespace "__llvm_libc")
 if(LLVM_VERSION_MAJOR)
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 28379213029a3..d6a8764c3de16 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -54,6 +54,9 @@ function(_get_common_compile_options output_var flags)
         list(APPEND compile_options "-isystem${COMPILER_RESOURCE_DIR}/include")
         list(APPEND compile_options "-nostdinc")
       endif()
+      if(LIBC_TARGET_OS_IS_LINUX)
+        list(APPEND compile_options "-idirafter${LIBC_KERNEL_HEADERS}")
+      endif()
     endif()
 
     if(LIBC_COMPILER_HAS_FIXED_POINT)



More information about the libc-commits mailing list