Skip to content

Fix clang CI build: use clang as nvcc host compiler#6004

Merged
xwang233 merged 4 commits intomainfrom
fix-clang-ci-cuda-host-compiler
Feb 23, 2026
Merged

Fix clang CI build: use clang as nvcc host compiler#6004
xwang233 merged 4 commits intomainfrom
fix-clang-ci-cuda-host-compiler

Conversation

@xwang233
Copy link
Copy Markdown
Collaborator

@xwang233 xwang233 commented Feb 23, 2026

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

  • CI clang-build-23 job passes

🤖 Generated with Claude Code

When CC/CXX are set to clang, PyTorch's CMake config adds
-fclang-abi-compat=17 to CMAKE_CXX_FLAGS. CMake passes these to nvcc
via -Xcompiler, but nvcc defaults to gcc as host compiler which doesn't
understand clang-specific flags. Setting CUDAHOSTCXX ensures nvcc uses
clang++ as its host compiler, matching CC/CXX.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 23, 2026

Review updated until commit 3dac2c5

Description

  • Fix CI clang build failure by ensuring nvcc uses clang++ as host compiler instead of defaulting to gcc

  • Replace CC="ccache clang" pattern with CMAKE_*_COMPILER_LAUNCHER to properly handle ccache with CUDA

  • Set CUDAHOSTCXX environment variable in setup-env.sh to direct nvcc to clang++ binary

  • Add CMAKE_CUDA_HOST_COMPILER configuration in CMakeLists.txt before enable_language(CUDA)

Changes walkthrough

Relevant files
Bug fix
setup-env.sh
Configure CUDA host compiler and ccache launcher                 

tools/setup-env.sh

  • Change CC/CXX to use raw compiler paths instead of "ccache clang"
    pattern
  • Use CMAKE_C_COMPILER_LAUNCHER, CMAKE_CXX_COMPILER_LAUNCHER,
    CMAKE_CUDA_COMPILER_LAUNCHER for ccache
  • Set CUDAHOSTCXX=$CLANGXX_PATH to ensure nvcc uses clang++ as host
    compiler
  • +14/-6   
    CMakeLists.txt
    Set CUDA host compiler in CMake configuration                       

    CMakeLists.txt

  • Add CMAKE_CUDA_HOST_COMPILER configuration before
    enable_language(CUDA)
  • Set CMAKE_CUDA_HOST_COMPILER from CUDAHOSTCXX environment variable if
    not already set
  • Ensure nvcc uses clang++ as host compiler when CXX is clang
  • +8/-0     

    PR Reviewer Guide

    Here are some key observations to aid the review process:

    🧪 PR contains tests
    ⚡ Recommended focus areas for review
    CUDAHOSTCXX path correctness

    Verify that CLANGXX_PATH is correctly set and points to a valid clang++ compiler before exporting CUDAHOSTCXX. The script checks for clang-19 existence earlier, but ensure the path variables are properly initialized.

    export CUDAHOSTCXX=$CLANGXX_PATH
    CMake configuration timing

    The CUDA host compiler setting is placed before enable_language(CUDA), which is correct. However, verify that this placement works correctly with PyTorch's TorchConfig.cmake that may be included later in the build process. The conditional check ensures we don't override an explicitly set compiler, which is good.

    if(NOT CMAKE_CUDA_HOST_COMPILER AND DEFINED ENV{CUDAHOSTCXX})
      set(CMAKE_CUDA_HOST_COMPILER $ENV{CUDAHOSTCXX})
    endif()
    

    @greptile-apps
    Copy link
    Copy Markdown
    Contributor

    greptile-apps bot commented Feb 23, 2026

    Greptile Summary

    Fixed the CI clang-build-23 job where nvcc was incorrectly dispatching to gcc instead of clang as its host compiler.

    Changes:

    • tools/setup-env.sh: Exports CUDAHOSTCXX to explicitly tell nvcc to use clang++ as the host compiler, and refactors ccache setup to use CMAKE_*_COMPILER_LAUNCHER variables instead of wrapping CC/CXX with ccache directly
    • CMakeLists.txt: Adds CMake logic to set CMAKE_CUDA_HOST_COMPILER from the CUDAHOSTCXX environment variable before enable_language(CUDA) is called, working around PyTorch's TorchConfig.cmake potentially overriding the environment variable

    This fix addresses the root cause where gcc doesn't understand clang-specific compiler flags like -fclang-abi-compat=17 that PyTorch adds to CMAKE_CXX_FLAGS.

    Confidence Score: 5/5

    • This PR is safe to merge with minimal risk
    • The changes are well-targeted fixes that address a specific CI failure by ensuring nvcc uses the correct host compiler. The implementation follows best practices: setting environment variables in the shell script and using CMake's proper mechanisms before enable_language(CUDA). The refactoring to use CMAKE_*_COMPILER_LAUNCHER for ccache is also a cleaner approach that avoids the original issue where ccache was being incorrectly identified as the compiler.
    • No files require special attention

    Important Files Changed

    Filename Overview
    CMakeLists.txt Added logic to set CMAKE_CUDA_HOST_COMPILER from CUDAHOSTCXX env var before enable_language(CUDA) to ensure nvcc uses the correct host compiler
    tools/setup-env.sh Reorganized environment setup to export CUDAHOSTCXX and changed ccache configuration to use CMAKE_*_COMPILER_LAUNCHER instead of wrapping CC/CXX

    Last reviewed commit: 3dac2c5

    Copy link
    Copy Markdown
    Contributor

    @greptile-apps greptile-apps bot left a comment

    Choose a reason for hiding this comment

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

    1 file reviewed, no comments

    Edit Code Review Agent Settings | Greptile

    CUDAHOSTCXX alone is insufficient because CMake derives
    CMAKE_CUDA_HOST_COMPILER from CMAKE_CXX_COMPILER, which resolves to
    "ccache" when CC="ccache clang++". Pass -DCMAKE_CUDA_HOST_COMPILER
    explicitly in the cmake command to ensure nvcc gets the actual clang++
    binary path.
    
    Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
    Copy link
    Copy Markdown
    Contributor

    @greptile-apps greptile-apps bot left a comment

    Choose a reason for hiding this comment

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

    2 files reviewed, no comments

    Edit Code Review Agent Settings | Greptile

    @wujingyue wujingyue requested a review from mdavis36 February 23, 2026 20:03
    The CC="ccache clang" pattern causes CMake (and PyTorch's TorchConfig)
    to resolve the CUDA host compiler to ccache itself, resulting in
    `nvcc -ccbin=/usr/bin/ccache` which fails. Instead, set CC/CXX to the
    raw clang paths and use CMAKE_{C,CXX,CUDA}_COMPILER_LAUNCHER=ccache,
    which is the proper CMake mechanism for compiler launchers and keeps
    nvcc's -ccbin pointing to the actual compiler.
    
    Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
    Copy link
    Copy Markdown
    Contributor

    @greptile-apps greptile-apps bot left a comment

    Choose a reason for hiding this comment

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

    1 file reviewed, no comments

    Edit Code Review Agent Settings | Greptile

    The compiler launcher fix resolved the ccache-as-ccbin issue, but nvcc
    still defaulted to gcc as host compiler. Set CUDAHOSTCXX in setup-env.sh
    and also set CMAKE_CUDA_HOST_COMPILER in CMakeLists.txt before
    enable_language(CUDA) to ensure nvcc uses clang++ as its host compiler.
    
    Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
    Copy link
    Copy Markdown
    Contributor

    @greptile-apps greptile-apps bot left a comment

    Choose a reason for hiding this comment

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

    2 files reviewed, no comments

    Edit Code Review Agent Settings | Greptile

    @xwang233
    Copy link
    Copy Markdown
    Collaborator Author

    !build

    @xwang233 xwang233 changed the title Set CUDAHOSTCXX to clang for CI clang build Fix clang CI build: use clang as nvcc host compiler Feb 23, 2026
    @xwang233 xwang233 merged commit d689097 into main Feb 23, 2026
    20 checks passed
    @xwang233 xwang233 deleted the fix-clang-ci-cuda-host-compiler branch February 23, 2026 23:48
    # Tell nvcc to use clang++ as its host compiler. Without this, nvcc defaults
    # to gcc, which fails on clang-specific flags like -fclang-abi-compat that
    # PyTorch adds to CMAKE_CXX_FLAGS.
    export CUDAHOSTCXX=$CLANGXX_PATH
    Copy link
    Copy Markdown
    Collaborator

    Choose a reason for hiding this comment

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

    Why not export CMAKE_CUDA_HOST_COMPILER=$CLANGXX_PATH? cc @xwang233

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    None yet

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    3 participants