Skip to content

[libc] Fix builds on Windows #102162

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
Aug 6, 2024
Merged

Conversation

Lancern
Copy link
Member

@Lancern Lancern commented Aug 6, 2024

This PR changes several places in the CMake scripts to make libc build on Windows. It adds the errno entrypoint to the Windows target.

A mistake in the overlay build doc is also fixed.

Tests still cannot be built on Windows because of the lack of osutils.

This patch changes several places in the CMake scripts to make libc build on
Windows. It adds the `errno` entrypoint to the Windows target.

A mistake in the overlay build doc is also fixed.

Tests still cannot be built on Windows because of the lack of osutils.
@llvmbot llvmbot added the libc label Aug 6, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 6, 2024

@llvm/pr-subscribers-libc

Author: Sirui Mu (Lancern)

Changes

This PR changes several places in the CMake scripts to make libc build on Windows. It adds the errno entrypoint to the Windows target.

A mistake in the overlay build doc is also fixed.

Tests still cannot be built on Windows because of the lack of osutils.


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

3 Files Affected:

  • (modified) libc/cmake/modules/LLVMLibCTestRules.cmake (+1-1)
  • (modified) libc/config/windows/entrypoints.txt (+3)
  • (modified) libc/docs/overlay_mode.rst (+1-1)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 539ed0429549f..d8097855d1637 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -348,7 +348,7 @@ function(add_libc_fuzzer target_name)
 endfunction(add_libc_fuzzer)
 
 # Get libgcc_s to be used in hermetic and integration tests.
-if(NOT LIBC_CC_SUPPORTS_NOSTDLIBPP)
+if(NOT MSVC AND NOT LIBC_CC_SUPPORTS_NOSTDLIBPP)
   execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=libgcc_s.so.1
                   OUTPUT_VARIABLE LIBGCC_S_LOCATION)
   string(STRIP ${LIBGCC_S_LOCATION} LIBGCC_S_LOCATION)
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index d66e7f1fed81f..f66438061ef4b 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -92,6 +92,9 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.stdlib.realloc
     libc.src.stdlib.aligned_alloc
     libc.src.stdlib.free
+
+    # errno.h entrypoints
+    libc.src.errno.errno
 )
 
 set(TARGET_LIBM_ENTRYPOINTS
diff --git a/libc/docs/overlay_mode.rst b/libc/docs/overlay_mode.rst
index f9b566658bb49..37368ffc1fea1 100644
--- a/libc/docs/overlay_mode.rst
+++ b/libc/docs/overlay_mode.rst
@@ -39,7 +39,7 @@ the CMake configure step as follows:
   $> cd llvm-project  # The llvm-project checkout
   $> mkdir build
   $> cd build
-  $> cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS="libc"  \
+  $> cmake ../llvm -G Ninja -DLLVM_ENABLE_RUNTIMES="libc"  \
      -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
      -DCMAKE_BUILD_TYPE=<Debug|Release>                    \  # Select build type
      -DCMAKE_INSTALL_PREFIX=<Your prefix of choice>           # Optional

@@ -39,7 +39,7 @@ the CMake configure step as follows:
$> cd llvm-project # The llvm-project checkout
$> mkdir build
$> cd build
$> cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS="libc" \
$> cmake ../llvm -G Ninja -DLLVM_ENABLE_RUNTIMES="libc" \
Copy link
Contributor

@SchrodingerZhu SchrodingerZhu Aug 6, 2024

Choose a reason for hiding this comment

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

As a side note, LLVM_ENABLE_PROJECTS should work but the cmake is unhappy about it, generating no targets of libc for some reasons. I think it is generally better to use LLVM_ENABLE_RUNTIMES after all.

@SchrodingerZhu
Copy link
Contributor

LGTM

@SchrodingerZhu
Copy link
Contributor

Confirmed locally on my machine. Thank you for the patch!

@SchrodingerZhu SchrodingerZhu merged commit 2f28378 into llvm:main Aug 6, 2024
7 of 8 checks passed
@Lancern Lancern deleted the win-build-fix branch August 6, 2024 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants