release/22.x: [libc] Tweak the runtimes cross-build for GPU (#178548)#179496
Merged
c-rhodes merged 1 commit intollvm:release/22.xfrom Feb 4, 2026
Merged
release/22.x: [libc] Tweak the runtimes cross-build for GPU (#178548)#179496c-rhodes merged 1 commit intollvm:release/22.xfrom
c-rhodes merged 1 commit intollvm:release/22.xfrom
Conversation
Member
Author
|
@lntue What do you think about merging this PR to the release branch? |
Member
Author
|
@llvm/pr-subscribers-libc Author: None (llvmbot) ChangesBackport e07a118 Requested by: @jhuber6 3 Files Affected:
diff --git a/libc/cmake/modules/prepare_libc_gpu_build.cmake b/libc/cmake/modules/prepare_libc_gpu_build.cmake
index 4d12a5917a56f..55cd0242eedeb 100644
--- a/libc/cmake/modules/prepare_libc_gpu_build.cmake
+++ b/libc/cmake/modules/prepare_libc_gpu_build.cmake
@@ -17,8 +17,8 @@ if(NOT LLVM_LIBC_FULL_BUILD)
endif()
# Set the required flags globally so standard CMake utilities can compile.
-if(LIBC_TARGET_TRIPLE)
- set(CMAKE_REQUIRED_FLAGS "--target=${LIBC_TARGET_TRIPLE}")
+if(NOT CMAKE_CXX_COMPILER_TARGET)
+ set(CMAKE_REQUIRED_FLAGS "${LIBC_COMPILE_OPTIONS_DEFAULT}")
endif()
# Optionally set up a job pool to limit the number of GPU tests run in parallel.
diff --git a/libc/docs/gpu/building.rst b/libc/docs/gpu/building.rst
index 9f9528b30d9bf..a7791331423dc 100644
--- a/libc/docs/gpu/building.rst
+++ b/libc/docs/gpu/building.rst
@@ -100,12 +100,12 @@ targeting a GPU architecture.
$> TARGET_C_COMPILER=</path/to/clang>
$> TARGET_CXX_COMPILER=</path/to/clang++>
$> cmake ../runtimes \ # Point to the runtimes build
- -G Ninja \
- -DLLVM_ENABLE_RUNTIMES=libc \
- -DCMAKE_C_COMPILER=$TARGET_C_COMPILER \
- -DCMAKE_CXX_COMPILER=$TARGET_CXX_COMPILER \
- -DLLVM_LIBC_FULL_BUILD=ON \
- -DLLVM_RUNTIMES_TARGET=$TARGET_TRIPLE \
+ -G Ninja \
+ -DLLVM_ENABLE_RUNTIMES=libc \
+ -DCMAKE_C_COMPILER=$TARGET_C_COMPILER \
+ -DCMAKE_CXX_COMPILER=$TARGET_CXX_COMPILER \
+ -DLLVM_LIBC_FULL_BUILD=ON \
+ -DLLVM_DEFAULT_TARGET_TRIPLE=$TARGET_TRIPLE \
-DCMAKE_BUILD_TYPE=Release
$> ninja install
@@ -113,34 +113,6 @@ The above steps will result in a build targeting one of the supported GPU
architectures. Building for multiple targets requires separate CMake
invocations.
-Standalone cross build
-----------------------
-
-The GPU build can also be targeted directly as long as the compiler used is a
-supported ``clang`` compiler. This method is generally not recommended as it can
-only target a single GPU architecture.
-
-.. code-block:: sh
-
- $> cd llvm-project # The llvm-project checkout
- $> mkdir build # A different build directory for the build tools
- $> cd build
- $> CLANG_C_COMPILER=</path/to/clang> # Must be a trunk build
- $> CLANG_CXX_COMPILER=</path/to/clang++> # Must be a trunk build
- $> TARGET_TRIPLE=<amdgcn-amd-amdhsa or nvptx64-nvidia-cuda>
- $> cmake ../llvm \ # Point to the llvm directory
- -G Ninja \
- -DLLVM_ENABLE_PROJECTS=libc \
- -DCMAKE_C_COMPILER=$CLANG_C_COMPILER \
- -DCMAKE_CXX_COMPILER=$CLANG_CXX_COMPILER \
- -DLLVM_LIBC_FULL_BUILD=ON \
- -DLIBC_TARGET_TRIPLE=$TARGET_TRIPLE \
- -DCMAKE_BUILD_TYPE=Release
- $> ninja install
-
-This will build and install the GPU C library along with all the other LLVM
-libraries.
-
Build overview
==============
diff --git a/libc/startup/gpu/CMakeLists.txt b/libc/startup/gpu/CMakeLists.txt
index fa326ef46a9d1..63e2a6c5dee1a 100644
--- a/libc/startup/gpu/CMakeLists.txt
+++ b/libc/startup/gpu/CMakeLists.txt
@@ -34,6 +34,7 @@ function(add_startup_object name)
RUNTIME_OUTPUT_DIRECTORY ${LIBC_LIBRARY_DIR}
RUNTIME_OUTPUT_NAME ${name}.o)
target_link_options(${fq_target_name}.exe PRIVATE
+ ${LIBC_COMPILE_OPTIONS_DEFAULT}
"-r" "-nostdlib" "-flto" "-Wl,--lto-emit-llvm")
endif()
endfunction()
|
lntue
approved these changes
Feb 3, 2026
Summary: We should likely use `-DLLVM_DEFAULT_TARGET_TRIPLE` as the general source of truth, make the handling work with that since we use it for the output directories. Fix the creation of startup files in this mode and make sure it can detect the GPU properly. Fixes: llvm#179375 (cherry picked from commit e07a118)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport e07a118
Requested by: @jhuber6