lol

opencv4: cuda: fix libstdc++ errors

+26 -29
+26 -29
pkgs/development/libraries/opencv/4.x.nix
··· 83 83 , Accelerate 84 84 , bzip2 85 85 , callPackage 86 - }: 86 + }@inputs: 87 87 88 88 let 89 89 version = "4.7.0"; 90 + 91 + # It's necessary to consistently use backendStdenv when building with CUDA 92 + # support, otherwise we get libstdc++ errors downstream 93 + stdenv = throw "Use effectiveStdenv instead"; 94 + effectiveStdenv = if enableCuda then cudaPackages.backendStdenv else inputs.stdenv; 90 95 91 96 src = fetchFromGitHub { 92 97 owner = "opencv"; ··· 121 126 sha256 = "1msbkc3zixx61rcg6a04i1bcfhw1phgsrh93glq1n80hgsk3nbjq"; 122 127 } + "/ippicv"; 123 128 files = let name = platform: "ippicv_2019_${platform}_general_20180723.tgz"; in 124 - if stdenv.hostPlatform.system == "x86_64-linux" then 129 + if effectiveStdenv.hostPlatform.system == "x86_64-linux" then 125 130 { ${name "lnx_intel64"} = "c0bd78adb4156bbf552c1dfe90599607"; } 126 - else if stdenv.hostPlatform.system == "i686-linux" then 131 + else if effectiveStdenv.hostPlatform.system == "i686-linux" then 127 132 { ${name "lnx_ia32"} = "4f38432c30bfd6423164b7a24bbc98a0"; } 128 - else if stdenv.hostPlatform.system == "x86_64-darwin" then 133 + else if effectiveStdenv.hostPlatform.system == "x86_64-darwin" then 129 134 { ${name "mac_intel64"} = "fe6b2bb75ae0e3f19ad3ae1a31dfa4a2"; } 130 135 else 131 136 throw "ICV is not available for this platform (or not yet supported by this package)"; ··· 232 237 #https://github.com/xianyi/OpenBLAS/wiki/Faq/4bded95e8dc8aadc70ce65267d1093ca7bdefc4c#multi-threaded 233 238 openblas_ = blas.provider.override { singleThreaded = true; }; 234 239 235 - inherit (cudaPackages) backendStdenv cudaFlags cudaVersion; 240 + inherit (cudaPackages) cudaFlags cudaVersion; 236 241 inherit (cudaFlags) cudaCapabilities; 237 242 238 243 cuda-common-redist = with cudaPackages; [ 244 + cuda_cudart 239 245 cuda_cccl # <thrust/*> 240 246 libnpp # npp.h 241 247 ] ++ lib.optionals enableCublas [ ··· 246 252 libcufft # cufft.h 247 253 ]; 248 254 249 - cuda-native-redist = symlinkJoin { 250 - name = "cuda-native-redist-${cudaVersion}"; 251 - paths = with cudaPackages; [ 252 - cuda_cudart # cuda_runtime.h 253 - cuda_nvcc 254 - ] ++ cuda-common-redist; 255 - }; 256 - 257 255 cuda-redist = symlinkJoin { 258 256 name = "cuda-redist-${cudaVersion}"; 259 257 paths = cuda-common-redist; 260 258 }; 261 259 in 262 260 263 - stdenv.mkDerivation { 261 + effectiveStdenv.mkDerivation { 264 262 pname = "opencv"; 265 263 inherit version src; 266 264 ··· 319 317 320 318 buildInputs = [ zlib pcre boost gflags protobuf3_21 ] 321 319 ++ lib.optional enablePython pythonPackages.python 322 - ++ lib.optional (stdenv.buildPlatform == stdenv.hostPlatform) hdf5 320 + ++ lib.optional (effectiveStdenv.buildPlatform == effectiveStdenv.hostPlatform) hdf5 323 321 ++ lib.optional enableGtk2 gtk2 324 322 ++ lib.optional enableGtk3 gtk3 325 323 ++ lib.optional enableVtk vtk ··· 330 328 ++ lib.optionals enableEXR [ openexr ilmbase ] 331 329 ++ lib.optional enableJPEG2000 openjpeg 332 330 ++ lib.optional enableFfmpeg ffmpeg 333 - ++ lib.optionals (enableFfmpeg && stdenv.isDarwin) 331 + ++ lib.optionals (enableFfmpeg && effectiveStdenv.isDarwin) 334 332 [ VideoDecodeAcceleration bzip2 ] 335 333 ++ lib.optionals enableGStreamer (with gst_all_1; [ gstreamer gst-plugins-base gst-plugins-good ]) 336 334 ++ lib.optional enableOvis ogre ··· 343 341 # tesseract & leptonica. 344 342 ++ lib.optionals enableTesseract [ tesseract leptonica ] 345 343 ++ lib.optional enableTbb tbb 346 - ++ lib.optionals stdenv.isDarwin [ 344 + ++ lib.optionals effectiveStdenv.isDarwin [ 347 345 bzip2 AVFoundation Cocoa VideoDecodeAcceleration CoreMedia MediaToolbox Accelerate 348 346 ] 349 347 ++ lib.optionals enableDocs [ doxygen graphviz-nox ] ··· 357 355 pythonPackages.pip 358 356 pythonPackages.wheel 359 357 pythonPackages.setuptools 360 - ] ++ lib.optionals enableCuda [ cuda-native-redist ]; 358 + ] ++ lib.optionals enableCuda [ 359 + cudaPackages.cuda_nvcc 360 + ]; 361 361 362 362 env.NIX_CFLAGS_COMPILE = lib.optionalString enableEXR "-I${ilmbase.dev}/include/OpenEXR"; 363 363 ··· 400 400 (opencvFlag "ENABLE_LTO" enableLto) 401 401 (opencvFlag "ENABLE_THIN_LTO" ( 402 402 enableLto && ( 403 - # Only clang supports thin LTO, so we must either be using clang through the stdenv, 404 - stdenv.cc.isClang || 405 - # or through the backend stdenv. 406 - (enableCuda && backendStdenv.cc.isClang) 403 + # Only clang supports thin LTO, so we must either be using clang through the effectiveStdenv, 404 + effectiveStdenv.cc.isClang || 405 + # or through the backend effectiveStdenv. 406 + (enableCuda && effectiveStdenv.cc.isClang) 407 407 ) 408 408 )) 409 409 ] ++ lib.optionals enableCuda [ 410 410 "-DCUDA_FAST_MATH=ON" 411 - # We need to set the C and C++ host compilers for CUDA to the same compiler. 412 - "-DCMAKE_C_COMPILER=${backendStdenv.cc}/bin/cc" 413 - "-DCMAKE_CXX_COMPILER=${backendStdenv.cc}/bin/c++" 414 411 "-DCUDA_NVCC_FLAGS=--expt-relaxed-constexpr" 415 412 416 413 # OpenCV respects at least three variables: ··· 421 418 "-DCUDA_ARCH_PTX=${lib.last cudaCapabilities}" 422 419 423 420 "-DNVIDIA_OPTICAL_FLOW_2_0_HEADERS_PATH=${nvidia-optical-flow-sdk}" 424 - ] ++ lib.optionals stdenv.isDarwin [ 421 + ] ++ lib.optionals effectiveStdenv.isDarwin [ 425 422 "-DWITH_OPENCL=OFF" 426 423 "-DWITH_LAPACK=OFF" 427 424 ··· 435 432 "-DBUILD_JPEG=OFF" 436 433 "-DBUILD_PNG=OFF" 437 434 "-DBUILD_WEBP=OFF" 438 - ] ++ lib.optionals (!stdenv.isDarwin) [ 435 + ] ++ lib.optionals (!effectiveStdenv.isDarwin) [ 439 436 "-DOPENCL_LIBRARY=${ocl-icd}/lib/libOpenCL.so" 440 437 ] ++ lib.optionals enablePython [ 441 438 "-DOPENCV_SKIP_PYTHON_LOADER=ON" ··· 489 486 tests = { 490 487 inherit (gst_all_1) gst-plugins-bad; 491 488 } 492 - // lib.optionalAttrs (!stdenv.isDarwin) { inherit qimgv; } 489 + // lib.optionalAttrs (!effectiveStdenv.isDarwin) { inherit qimgv; } 493 490 // lib.optionalAttrs (!enablePython) { pythonEnabled = pythonPackages.opencv4; } 494 - // lib.optionalAttrs (stdenv.buildPlatform != "x86_64-darwin") { 491 + // lib.optionalAttrs (effectiveStdenv.buildPlatform != "x86_64-darwin") { 495 492 opencv4-tests = callPackage ./tests.nix { 496 493 inherit enableGStreamer enableGtk2 enableGtk3 runAccuracyTests runPerformanceTests testDataSrc; 497 494 inherit opencv4;