Skip to content
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

[libc][CMake] Fix build issues of libc on Windows #102499

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

Lancern
Copy link
Member

@Lancern Lancern commented Aug 8, 2024

Due to an issue mentioned in llvm/projects/CMakeLists.txt, libc build is disabled by default when building with clang-cl on Windows. This PR sets LLVM_FORCE_BUILD_RUNTIME to ON to bypass this limit for libc and make libc build with clang-cl on Windows.

Due to an issue mentioned in llvm/projects/CMakeLists.txt, libc build is
disabled by default when building with clang-cl on Windows. This patch sets
LLVM_FORCE_BUILD_RUNTIME to ON to bypass this limit for libc and make libc build
with clang-cl on Windows.
@llvmbot llvmbot added the cmake Build system in general and CMake in particular label Aug 8, 2024
@Lancern Lancern changed the title [libc] Fix build issues of libc on Windows [libc][CMake] Fix build issues of libc on Windows Aug 8, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 8, 2024

@llvm/pr-subscribers-libc

Author: Sirui Mu (Lancern)

Changes

Due to an issue mentioned in llvm/projects/CMakeLists.txt, libc build is disabled by default when building with clang-cl on Windows. This PR sets LLVM_FORCE_BUILD_RUNTIME to ON to bypass this limit for libc and make libc build with clang-cl on Windows.


Full diff: https://github.com/llvm/llvm-project/pull/102499.diff

1 Files Affected:

  • (modified) llvm/cmake/modules/CrossCompile.cmake (+6)
diff --git a/llvm/cmake/modules/CrossCompile.cmake b/llvm/cmake/modules/CrossCompile.cmake
index 39b4abaa0d9313..e36a71f522d82c 100644
--- a/llvm/cmake/modules/CrossCompile.cmake
+++ b/llvm/cmake/modules/CrossCompile.cmake
@@ -71,6 +71,12 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype)
 
   if("libc" IN_LIST LLVM_ENABLE_PROJECTS AND NOT LIBC_HDRGEN_EXE)
     set(libc_flags -DLLVM_LIBC_FULL_BUILD=ON -DLIBC_HDRGEN_ONLY=ON)
+    if(MSVC)
+      # Due to some issues mentioned in llvm/projects/CMakeLists.txt, libc build is disabled by
+      # default in the cross target when building with MSVC compatible compilers on Windows. Add
+      # LLVM_FORCE_BUILD_RUNTIME to bypass this issue and force its building on Windows.
+      list(APPEND libc_flags -DLLVM_FORCE_BUILD_RUNTIME=ON)
+    endif()
   endif()
 
   add_custom_command(OUTPUT ${${project_name}_${target_name}_BUILD}/CMakeCache.txt

Copy link
Contributor

@SchrodingerZhu SchrodingerZhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way as we tested is to add libc to LLVM_ENABLE_RUNTIMES and use runtimes as the source directory instead of llvm.

@SchrodingerZhu SchrodingerZhu merged commit 6b78e94 into llvm:main Aug 8, 2024
8 of 10 checks passed
@Lancern Lancern deleted the fix-libc-build-with-msvc branch August 9, 2024 01:05
kstoimenov pushed a commit to kstoimenov/llvm-project that referenced this pull request Aug 15, 2024
Due to an issue mentioned in `llvm/projects/CMakeLists.txt`, libc build
is disabled by default when building with `clang-cl` on Windows. This PR
sets `LLVM_FORCE_BUILD_RUNTIME` to `ON` to bypass this limit for libc
and make libc build with `clang-cl` on Windows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular libc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants