Skip to content

Fix CUDA build with MSVC by enabling /Zc:preprocessor for nvcc host compilation on VS 16.5 or greater - #2054

Merged
kunal-vaishnavi merged 5 commits into
microsoft:mainfrom
nsubaru:fix/msvc-build-failure-on-version-greter-then-16.5-due-missing-flag
May 18, 2026
Merged

Fix CUDA build with MSVC by enabling /Zc:preprocessor for nvcc host compilation on VS 16.5 or greater#2054
kunal-vaishnavi merged 5 commits into
microsoft:mainfrom
nsubaru:fix/msvc-build-failure-on-version-greter-then-16.5-due-missing-flag

Conversation

@nsubaru

@nsubaru nsubaru commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes CUDA builds on Windows when nvcc uses MSVC as the host compiler on Visual Studio 16.5 or greater

Problem

Recent CUDA/CCCL headers require MSVC's conforming preprocessor. Without passing
/Zc:preprocessor to the host compiler, CUDA compilation can fail with an error
from cuda/std/__cccl/preprocessor.h.

Solution

Pass /Zc:preprocessor to MSVC version check through nvcc for CUDA source compilation on
Windows/MSVC builds.

Testing

  • Reproduced failure with CUDA + MSVC host compiler on Windows
  • Verified build succeeds after adding -Xcompiler=/Zc:preprocessor

…ompilation on MSVC version greter then 1925 (VS 16.5)
Copilot AI review requested due to automatic review settings April 1, 2026 11:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the build configuration to fix Windows CUDA builds when nvcc uses MSVC (cl.exe) as its host compiler on Visual Studio 16.5+ by enabling MSVC’s conforming preprocessor (/Zc:preprocessor) for CUDA compilation.

Changes:

  • Adds an MSVC version gate (MSVC_VERSION >= 1925) to pass -Xcompiler=/Zc:preprocessor during CUDA compilation.

Comment thread CMakeLists.txt Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@kunal-vaishnavi

Copy link
Copy Markdown
Contributor

Thanks for your contribution! Can you sync with the main branch to get the latest CI fixes?

Natsuki Subaru added 2 commits May 12, 2026 20:11
@kunal-vaishnavi

Copy link
Copy Markdown
Contributor

PRs have been recently made to improve the Windows CUDA CI pipeline. Can you sync with main to receive those fixes?

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