Skip to content

Commit d689097

Browse files
xwang233claude
andauthored
Fix clang CI build: use clang as nvcc host compiler (#6004)
## Summary Fix CI `clang-build-23` job failure where nvcc used gcc as host compiler but received clang-specific flags (`-fclang-abi-compat=17`) from PyTorch's CMake config. Two issues were fixed: - **`setup-env.sh`**: Switch from `CC="ccache clang"` to `CC=clang` + `CMAKE_*_COMPILER_LAUNCHER=ccache`. The old pattern caused CMake to resolve the CUDA host compiler (`-ccbin`) to `ccache` instead of clang. Set `CUDAHOSTCXX` to tell CMake to use clang++ as nvcc's host compiler. - **`CMakeLists.txt`**: Read `CUDAHOSTCXX` into `CMAKE_CUDA_HOST_COMPILER` before `enable_language(CUDA)` to ensure it takes effect before PyTorch's TorchConfig.cmake can override it. ## Test plan - [x] CI `clang-build-23` job passes 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 20be631 commit d689097

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
cmake_minimum_required(VERSION 3.18)
55
project(nvfuser)
66

7+
# When CXX is clang, ensure nvcc also uses clang as its host compiler.
8+
# This must be set before enable_language(CUDA) so that CMake configures
9+
# nvcc with the correct -ccbin. The CUDAHOSTCXX env var should do this,
10+
# but PyTorch's TorchConfig.cmake can override it, so we also set it here.
11+
if(NOT CMAKE_CUDA_HOST_COMPILER AND DEFINED ENV{CUDAHOSTCXX})
12+
set(CMAKE_CUDA_HOST_COMPILER $ENV{CUDAHOSTCXX})
13+
endif()
14+
715
enable_language(CUDA)
816

917
cmake_policy(SET CMP0063 NEW) # make symbol visibility always apply

tools/setup-env.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,23 @@ else
2121
exit 1
2222
fi
2323

24-
# Use ccache if available and CC/CXX are not already set
24+
# Set CC/CXX to the raw compiler paths. Use CMAKE_<LANG>_COMPILER_LAUNCHER
25+
# for ccache instead of CC="ccache clang", because the "ccache clang" form
26+
# causes CMake (and PyTorch's TorchConfig.cmake) to resolve the CUDA host
27+
# compiler (-ccbin) to ccache instead of clang, breaking nvcc.
2528
if [ -z "$CC" ]; then
29+
export CC=$CLANG_PATH
30+
export CXX=$CLANGXX_PATH
2631
if command -v ccache >/dev/null 2>&1; then
27-
export CC="ccache $CLANG_PATH"
28-
export CXX="ccache $CLANGXX_PATH"
29-
else
30-
export CC=$CLANG_PATH
31-
export CXX=$CLANGXX_PATH
32+
export CMAKE_C_COMPILER_LAUNCHER=ccache
33+
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
34+
export CMAKE_CUDA_COMPILER_LAUNCHER=ccache
3235
fi
3336
fi
3437

38+
# Tell nvcc to use clang++ as its host compiler. Without this, nvcc defaults
39+
# to gcc, which fails on clang-specific flags like -fclang-abi-compat that
40+
# PyTorch adds to CMAKE_CXX_FLAGS.
41+
export CUDAHOSTCXX=$CLANGXX_PATH
42+
3543
export TORCH_CUDA_ARCH_LIST="10.0"

0 commit comments

Comments
 (0)