Skip to content

[libc] Build native libc-hdrgen when crosscompiling #77848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libc/utils/HdrGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ target_include_directories(libc-hdrgen PRIVATE ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_I
target_link_libraries(libc-hdrgen PRIVATE LibcTableGenUtil)

add_subdirectory(PrototypeTestGen)

setup_host_tool(libc-hdrgen LIBC_HDRGEN libc_hdrgen_exe libc_hdrgen_target)
8 changes: 7 additions & 1 deletion llvm/cmake/modules/CrossCompile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype)
"-DLLVM_EXTERNAL_${name}_SOURCE_DIR=${LLVM_EXTERNAL_${name}_SOURCE_DIR}")
endforeach()

if("libc" IN_LIST LLVM_ENABLE_PROJECTS)
if(LLVM_LIBC_FULL_BUILD AND NOT LIBC_HDRGEN_EXE)
set(libc_flags -DLLVM_LIBC_FULL_BUILD=ON -DLIBC_HDRGEN_ONLY=ON)
endif()
endif()

add_custom_command(OUTPUT ${${project_name}_${target_name}_BUILD}/CMakeCache.txt
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
-DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}"
Expand All @@ -86,7 +92,7 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype)
-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN="${LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN}"
-DLLVM_INCLUDE_BENCHMARKS=OFF
-DLLVM_INCLUDE_TESTS=OFF
${build_type_flags} ${linker_flag} ${external_clang_dir}
${build_type_flags} ${linker_flag} ${external_clang_dir} ${libc_flags}
${ARGN}
WORKING_DIRECTORY ${${project_name}_${target_name}_BUILD}
DEPENDS CREATE_${project_name}_${target_name}
Expand Down
18 changes: 7 additions & 11 deletions llvm/runtimes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -425,18 +425,14 @@ if(runtimes)
endif()
if("libc" IN_LIST LLVM_ENABLE_PROJECTS AND
(LLVM_LIBC_FULL_BUILD OR LIBC_GPU_BUILD OR LIBC_GPU_ARCHITECTURES))
if(TARGET libc-hdrgen)
set(libc_tools libc-hdrgen)
set(libc_cmake_args "-DLIBC_HDRGEN_EXE=$<TARGET_FILE:libc-hdrgen>"
"-DLLVM_LIBC_FULL_BUILD=ON")
list(APPEND extra_deps ${libc_tools})
else()
# We want to build the libc build tools before we can build the libc
# itself. So, the libc project should be included in LLVM_ENABLE_PROJECTS.
# This should have been done in llvm/CMakeLists.txt automatically when
# "libc" is detected in LLVM_ENABLE_RUNTIMES.
message(FATAL_ERROR "libc-hdrgen target missing unexpectedly")
get_host_tool_path(libc-hdrgen LIBC_HDRGEN libc_hdrgen_exe libc_hdrgen_target)
if(NOT libc_hdrgen_exe)
message(FATAL_ERROR "libc-hdrgen executable missing")
endif()
set(libc_cmake_args "-DLIBC_HDRGEN_EXE=${libc_hdrgen_exe}"
"-DLLVM_LIBC_FULL_BUILD=ON")
set(libc_tools libc_hdrgen_target)
list(APPEND extra_deps ${libc_hdrgen_target})
if(LIBC_GPU_BUILD OR LIBC_GPU_ARCHITECTURES)
foreach(dep clang-offload-packager nvptx-arch amdgpu-arch)
if(TARGET ${dep})
Expand Down