Skip to content

cudaPackages: wrapCCWith without overrideCC results in linking the wrong libstdc++ #225493

@SomeoneSerge

Description

@SomeoneSerge

Describe the bug

The context, copied pretty much as is from matrix: cudaPackages.cuda_nvcc builds cuda programs, and behind the scenes it uses gcc for that. This is controlled by the CMAKE_CUDA_HOST_COMPILER variable.

If we just set CMAKE_CUDA_HOST_COMPILER to cudaPackages.cudatoolkit.cc (which currently equals wrapCCWith { cc = gcc11Stdenv.cc.cc; libcxx = gcc12Stdenv.cc.cc.lib; }), the build ends up still linking gcc11's libstdc++, which is explicitly not what we're trying to do, and results in broken builds

If we make a customStdenv = overrideCC stdenv (wrapCCWith ( ... }) (currently, cudaPackages.backendStdenv, to be renamed into cudaStdenv) and use its mkDerivation to build the cuda program, it correctly links gcc12's libstdc++.

This is unexpected, because the actual host compiler (e.g. used for .cc and .cpp files) in the derivation is still gcc12. Gcc11 is only visible to the build through the aforementioned CMAKE_CUDA_HOST_COMPILER and it is wrapped anyway

Steps To Reproduce

Another version of the same example: https://gist.github.com/SomeoneSerge/cc47a75885f8b9ea267456675e115cfe#file-vanilla-log-L59

Expected behavior

Both builds link gcc12's libstdc++ and succeed

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

wrapCCWith practically just adds the chosen libstdc++ into propagatedBuildInput, and we maybe abuse the function

Notify maintainers

@NixOS/cuda-maintainers

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bugSomething is broken2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: cudaParallel computing platform and API6.topic: stdenvStandard environment
    No fields configured for issues without a type.

    Projects

    Status

    🔮 Roadmap

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions