nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 203 lines 7.3 kB view raw
1{ 2 backendStdenv, 3 cmake, 4 cuda_cudart, 5 cuda_nvcc, 6 cudaNamePrefix, 7 fetchpatch2, 8 flags, 9 lib, 10 srcOnly, 11 stdenv, 12 stdenvNoCC, 13}: 14let 15 inherit (backendStdenv) cc; 16 inherit (lib.attrsets) mapAttrs optionalAttrs recurseIntoAttrs; 17 inherit (lib.fixedPoints) composeExtensions toExtension; 18 inherit (lib.lists) optionals; 19 inherit (lib.strings) 20 cmakeBool 21 cmakeFeature 22 optionalString 23 versionAtLeast 24 ; 25 26 cmake' = cmake.overrideAttrs (prevAttrs: { 27 patches = prevAttrs.patches or [ ] ++ [ 28 # Fix errors during configuration when C/CXX is not loaded 29 # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/10354 30 (fetchpatch2 { 31 name = "find-cuda-toolkit-check-for-language-enablement.patch"; 32 url = "https://gitlab.kitware.com/cmake/cmake/-/commit/c5d81a246852e1ad81a3d55fcaff7e6feb779db7.patch"; 33 hash = "sha256-oGxzbp+x88+79V+Cyx0l7+nMxX+n3ixzAFKPK26NMI8="; 34 }) 35 # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/10289 36 (fetchpatch2 { 37 name = "update-arch-supported-by-cuda-12_8.patch"; 38 url = "https://gitlab.kitware.com/cmake/cmake/-/commit/a745b6869ee3681e39544d96d936c95c196c7398.patch"; 39 hash = "sha256-B6ny6AZFIcyFhsEnzNk7+vJTb36HeguM53sk/LCnjS4="; 40 }) 41 ]; 42 }); 43 44 isBroken = _: prevAttrs: { 45 meta = prevAttrs.meta or { } // { 46 broken = true; 47 }; 48 }; 49 50 cmakeSrc = srcOnly { 51 name = "cmake-unpacked"; 52 inherit (cmake) src version; 53 stdenv = stdenvNoCC; 54 }; 55 56 mkTest = 57 let 58 generic = stdenv.mkDerivation (finalAttrs: { 59 __structuredAttrs = true; 60 strictDeps = true; 61 62 testSuiteName = builtins.throw "testSuiteName must be set"; 63 testName = builtins.throw "testName must be set"; 64 65 name = "${cudaNamePrefix}-${finalAttrs.pname}-${finalAttrs.version}"; 66 pname = "tests-cmake-${finalAttrs.testSuiteName}-${finalAttrs.testName}"; 67 inherit (cmakeSrc) version; 68 69 src = cmakeSrc; 70 71 setSourceRoot = '' 72 sourceRoot="$(echo */Tests/${finalAttrs.testSuiteName}/${finalAttrs.testName})" 73 ''; 74 75 nativeBuildInputs = [ 76 cmake' 77 cuda_nvcc 78 ]; 79 80 # If our compiler uses C++14, we must modify the CMake files so they don't hardcode C++11. 81 # This behavior has only been seen with GCC 14, but it's possible Clang would also require this. 82 requireCxxStandard14 = cc.isGNU && versionAtLeast cc.version "14"; 83 84 cmakeListsReplacements = optionalAttrs finalAttrs.requireCxxStandard14 { 85 "cuda_std_11" = "cuda_std_14"; 86 "cxx_std_11" = "cxx_std_14"; 87 "set(CMAKE_CUDA_STANDARD 11)" = "set(CMAKE_CUDA_STANDARD 14)"; 88 "set(CMAKE_CXX_STANDARD 11)" = "set(CMAKE_CXX_STANDARD 14)"; 89 }; 90 91 prePatch = optionalString finalAttrs.requireCxxStandard14 '' 92 for key in "''${!cmakeListsReplacements[@]}"; do 93 if grep -q "$key" CMakeLists.txt; then 94 nixLog "replacing occurrences of \"$key\" with \"''${cmakeListsReplacements[$key]}\" in $PWD/CMakeLists.txt" 95 substituteInPlace CMakeLists.txt --replace-fail "$key" "''${cmakeListsReplacements[$key]}" 96 fi 97 done 98 ''; 99 100 buildInputs = [ 101 cuda_cudart 102 ]; 103 104 cmakeFlags = [ 105 (cmakeBool "CMAKE_VERBOSE_MAKEFILE" true) 106 (cmakeFeature "CMAKE_CUDA_ARCHITECTURES" flags.cmakeCudaArchitecturesString) 107 ] 108 ++ optionals finalAttrs.requireCxxStandard14 [ 109 (cmakeFeature "CMAKE_CXX_STANDARD" "14") 110 (cmakeFeature "CMAKE_CUDA_STANDARD" "14") 111 ]; 112 113 # The build *is* the check. 114 doCheck = false; 115 116 installPhase = '' 117 runHook preInstall 118 touch "$out" 119 runHook postInstall 120 ''; 121 122 # Don't try to run stuff in the patch phase as the setup hooks will error on empty output. 123 dontFixup = true; 124 125 meta = { 126 description = "Generic builder for running CMake tests"; 127 license = lib.licenses.mit; 128 maintainers = lib.teams.cuda.members; 129 platforms = [ 130 "aarch64-linux" 131 "x86_64-linux" 132 ]; 133 }; 134 }); 135 in 136 testSuiteName: testName: overrideAttrsArg: 137 generic.overrideAttrs ( 138 composeExtensions (toExtension { inherit testSuiteName testName; }) (toExtension overrideAttrsArg) 139 ); 140in 141recurseIntoAttrs ( 142 mapAttrs (testSuiteName: testSuite: recurseIntoAttrs (mapAttrs (mkTest testSuiteName) testSuite)) { 143 # TODO: Handle set(Cuda.Toolkit_BUILD_OPTIONS -DHAS_CUPTI:BOOL=${CMake_TEST_CUDA_CUPTI}) 144 # from Tests/Cuda/CMakeLists.txt 145 Cuda = { 146 Complex = { }; 147 CXXStandardSetTwice = { }; 148 IncludePathNoToolkit = { }; 149 MixedStandardLevels1 = { }; 150 MixedStandardLevels2 = { }; 151 MixedStandardLevels3 = { }; 152 MixedStandardLevels4 = if cc.isClang then isBroken else { }; 153 MixedStandardLevels5 = if cc.isClang then isBroken else { }; 154 NotEnabled = { }; 155 ObjectLibrary = { }; 156 ProperDeviceLibraries = 157 if cc.isClang then 158 isBroken # Clang lacks __CUDACC_VER*__ defines. 159 else 160 isBroken; # TODO: Fix 161 ProperLinkFlags = { }; 162 SeparableCompCXXOnly = { }; 163 SharedRuntimePlusToolkit = isBroken; # TODO: Fix 164 StaticRuntimePlusToolkit = isBroken; # TODO: Fix 165 StubRPATH = { }; 166 Toolkit = isBroken; # TODO: Fix 167 ToolkitBeforeLang = if cc.isClang then isBroken else { }; # Clang lacks __CUDACC_VER*__ defines. 168 WithC = { }; 169 }; 170 # TODO: Handle set(CudaOnly.Toolkit_BUILD_OPTIONS -DHAS_CUPTI:BOOL=${CMake_TEST_CUDA_CUPTI}) 171 # from Tests/CudaOnly/CMakeLists.txt 172 CudaOnly = { 173 Architecture = { }; 174 ArchSpecial = isBroken; # Tries to detect the native architecture, which is impure. 175 CircularLinkLine = { }; 176 CompileFlags = { }; 177 CUBIN = if cc.isClang then isBroken else { }; # Only NVCC defines __CUDACC_DEBUG__ when compiling in debug mode. 178 DeviceLTO = isBroken; # TODO: Fix 179 DontResolveDeviceSymbols = { }; 180 EnableStandard = { }; 181 ExportPTX = { }; 182 Fatbin = if cc.isClang then isBroken else { }; # Only NVCC defines __CUDACC_DEBUG__ when compiling in debug mode. 183 GPUDebugFlag = if cc.isClang then isBroken else { }; # Only NVCC defines __CUDACC_DEBUG__ when compiling in debug mode. 184 OptixIR = if cc.isClang then isBroken else { }; # Only NVCC defines __CUDACC_DEBUG__ when compiling in debug mode. 185 PDB = isBroken; # Tests for features that only work with MSVC 186 ResolveDeviceSymbols = { }; 187 RuntimeControls = { }; 188 SeparateCompilation = { }; 189 SeparateCompilationPTX = isBroken; # TODO: Fix 190 SeparateCompilationTargetObjects = { }; 191 SharedRuntimePlusToolkit = isBroken; # TODO: Fix 192 SharedRuntimeViaCUDAFlags = if cc.isClang then isBroken else { }; # Clang doesn't have flags for selecting the runtime. 193 Standard98 = if cc.isClang then isBroken else { }; 194 StaticRuntimePlusToolkit = isBroken; # TODO: Fix 195 Toolkit = isBroken; # TODO: Fix 196 ToolkitBeforeLang = { }; 197 ToolkitMultipleDirs = { }; 198 TryCompileTargetStatic = { }; 199 Unity = { }; 200 WithDefs = { }; 201 }; 202 } 203)