Skip to content

Fix CUDA toolchain detection for Arch builds#406

Open
IldarMinaev wants to merge 1 commit into
mkiol:mainfrom
IldarMinaev:fix-arch-cuda-build-env
Open

Fix CUDA toolchain detection for Arch builds#406
IldarMinaev wants to merge 1 commit into
mkiol:mainfrom
IldarMinaev:fix-arch-cuda-build-env

Conversation

@IldarMinaev

@IldarMinaev IldarMinaev commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix CUDA-enabled Arch builds by making the CUDA toolkit/compiler discovery explicit and by
propagating CUDA toolchain settings into the nested whisper.cpp CMake build.

This changes:

  • arch/git/PKGBUILD and arch/release/PKGBUILD
    • discover nvcc from CUDACXX, CUDAToolkit_ROOT, CUDA_PATH, CUDA_HOME, PATH, and finally the Arch
      package fallback /opt/cuda/bin/nvcc;
    • export CUDA_PATH, CUDAToolkit_ROOT, and the directory containing nvcc before enabling
      BUILD_WHISPERCPP_CUBLAS;
    • pass CUDAToolkit_ROOT, CMAKE_CUDA_COMPILER, and, when available,
      CMAKE_CUDA_HOST_COMPILER;
    • honor user-provided CUDAHOSTCXX / NVCC_CCBIN before falling back to Arch's g++-15.
  • cmake/whispercpp.cmake
    • forwards CUDA toolkit/compiler settings to the whispercppcublas ExternalProject;
    • sets CMAKE_CUDA_STANDARD=17 for the nested CUDA build.

Problem

AUR package dsnote-git currently enables BUILD_WHISPERCPP_CUBLAS on Arch when the cuda package is installed:

pacman -Qi cuda &> /dev/null && HAS_CUDA=true || HAS_CUDA=false

That check is not sufficient for a non-interactive package build. Arch installs CUDA under /opt/cuda, and the
CUDA package's profile script adds /opt/cuda/bin to PATH and sets NVCC_CCBIN=/usr/bin/g++-15. Package build
environments are not guaranteed to have that profile state loaded.

The result is that BUILD_WHISPERCPP_CUBLAS=ON can be enabled while the nested whisper.cpp CMake configure step
cannot find nvcc:

CUDAToolkit_NVCC_EXECUTABLE:FILEPATH=CUDAToolkit_NVCC_EXECUTABLE-NOTFOUND

On systems where nvcc is found, CUDA 13.x / CCCL also requires C++17 for CUDA sources. The top-level project uses
C++17, but the nested whisper.cpp ExternalProject did not receive an explicit CUDA standard. This can fail later
during CUDA compilation with:

CUB requires at least C++17
libcu++ requires at least C++ 17
Thrust requires at least C++17

Why this follows upstream/toolchain behavior

CMake documents CUDA toolkit discovery in this order: the enabled CUDA compiler, CMAKE_CUDA_COMPILER / CUDACXX,
CUDAToolkit_ROOT, CUDA_PATH, then PATH, with platform defaults only after that. See:

CMake also documents CUDAHOSTCXX as the preferred host compiler input for CUDA compilation, which is cached as
CMAKE_CUDA_HOST_COMPILER:

NVIDIA's Linux installation guide says CUDA post-install setup must put the toolkit bin directory in PATH, and its
FAQ explicitly points to missing PATH setup when nvcc is not found:

The Arch cuda package matches that model: it installs the toolkit under /opt/cuda, ships /etc/profile.d/cuda.sh
with CUDA_PATH=/opt/cuda, adds /opt/cuda/bin to PATH, and sets NVCC_CCBIN=/usr/bin/g++-15.

Why this is not only a local setup issue

The current package logic enables CUDA based only on package presence. That works only if the build environment already
has the CUDA profile loaded. A clean AUR helper / makepkg environment can have cuda installed but still not expose
nvcc through PATH.

This fix keeps user-configured CUDA locations working (CUDACXX, CUDAToolkit_ROOT, CUDA_PATH, CUDA_HOME, PATH)
and uses /opt/cuda only as the Arch-package fallback. It does not require all systems to install CUDA in /opt/cuda.

Verification

On Arch/CachyOS with:

  • cuda 13.3.1
  • gcc15
  • cmake 4.3.4

I verified a clean CMake build of the CUDA ExternalProject path:

cmake -S <source-dir> -B <build-dir> \
  -DWITH_DESKTOP=ON \
  -DWITH_SFOS=OFF \
  -DWITH_PY=OFF \
  -DWITH_TESTS=OFF \
  -DDOWNLOAD_LIBSTT=OFF \
  -DBUILD_OPENBLAS=OFF \
  -DBUILD_VOSK=OFF \
  -DBUILD_BERGAMOT=OFF \
  -DBUILD_RHVOICE=OFF \
  -DBUILD_RHVOICE_MODULE=OFF \
  -DBUILD_WHISPERCPP_VULKAN=OFF \
  -DBUILD_WHISPERCPP_CUBLAS=ON \
  -DCUDAToolkit_ROOT=/opt/cuda \
  -DCMAKE_CUDA_COMPILER=/opt/cuda/bin/nvcc \
  -DCMAKE_CUDA_HOST_COMPILER=/usr/bin/g++-15 \
  -DCMAKE_CUDA_ARCHITECTURES=native

cmake --build <build-dir> --target whispercppcublas -- -j2

The generated nested configure command includes:

-DCUDAToolkit_ROOT=/opt/cuda
-DCMAKE_CUDA_COMPILER=/opt/cuda/bin/nvcc
-DCMAKE_CUDA_HOST_COMPILER=/usr/bin/g++-15
-DCMAKE_CUDA_STANDARD=17
-DCMAKE_CUDA_STANDARD_REQUIRED=ON

The build completed successfully:

[100%] Built target whispercppcublas

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.

1 participant