From 4e66a3ddd593027aaadbf731b6c56de154292344 Mon Sep 17 00:00:00 2001
From: Sven-Hendrik Haase <svenstaro@archlinux.org>
Date: Sun, 5 Nov 2023 17:07:32 +0100
Subject: [PATCH] upgpkg: 12.3.0-4: Apply FS#80161

This also fixes some CMake assumptions for build paths.
---
 .SRCINFO |  4 ++--
 PKGBUILD | 13 ++++++++++---
 cuda.sh  |  7 +++++--
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/.SRCINFO b/.SRCINFO
index 42a4fe1..a6a6bd6 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,7 +1,7 @@
 pkgbase = cuda
 	pkgdesc = NVIDIA's GPU programming toolkit
 	pkgver = 12.3.0
-	pkgrel = 3
+	pkgrel = 4
 	url = https://developer.nvidia.com/cuda-zone
 	install = cuda.install
 	arch = x86_64
@@ -44,7 +44,7 @@ pkgbase = cuda
 	source = nvrtc.pc
 	source = nvToolsExt.pc
 	sha512sums = b62e34ac694a2925e6c02ebb94d66c8c3f3773d04ee547284a0940c73769d52e3a2fe10cce6f0c3936a029b4c5f7ad1f6329426d54a5a8519ffd665d1fa654f6
-	sha512sums = a89d3418c3cb97793dbfc51b4c4a1e3c5be53d6bd841cf3994835aafbb5943765687d0b32ec79c48574877d03297dd30c1ebf59f20ead7fcccb4cb6ebc862f85
+	sha512sums = 2f7d939d391048a7a723afd5e1b2e57e77ced47cd02e13ec5f475a1998b7df96ecdd1f19f14e4657a234882ba2b5235b659c61e4b434fedac980630d6b9a6dd8
 	sha512sums = 714d973bc79446f73bebe85306b3566fe25b554bcbcba2fcbe76709a3eca71fb5d183ab4da2d3b5e9326cb9cd8d13a93f6d4a005ea5a41f7ef8e6c6e81e06b5e
 	sha512sums = a4b3b03682801a98a1d8c1d14c084fd35efd384d92d497e230e3a28e0bd97b1fa48a93ccb2150f892f0b4154ca4ea2d66f5484a6a59b5c9b49963de42ecf1736
 	sha512sums = d69d3ec0e270648f55d8c3e420f89d056b120eca5b25e9e7fc1cca799d1a252909ee31ff399c137223eca57cdf82b856221a251b6ff1daf5d6f75c1a582b1e32
diff --git a/PKGBUILD b/PKGBUILD
index 59cb658..e677ee3 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -4,12 +4,11 @@ pkgname=(cuda cuda-tools)
 pkgbase=cuda
 pkgver=12.3.0
 _driverver=545.23.06
-pkgrel=3
+pkgrel=4
 pkgdesc="NVIDIA's GPU programming toolkit"
 arch=('x86_64')
 url="https://developer.nvidia.com/cuda-zone"
 license=('custom:NVIDIA')
-# NOTE: When changing the gcc version, remember to also update it in profile.d/cuda.sh
 depends=('opencl-nvidia' 'nvidia-utils' 'python' 'gcc12')
 options=(!strip staticlibs)
 install=cuda.install
@@ -45,7 +44,7 @@ source=(https://developer.download.nvidia.com/compute/cuda/${pkgver}/local_insta
         nvrtc.pc
         nvToolsExt.pc)
 sha512sums=('b62e34ac694a2925e6c02ebb94d66c8c3f3773d04ee547284a0940c73769d52e3a2fe10cce6f0c3936a029b4c5f7ad1f6329426d54a5a8519ffd665d1fa654f6'
-            'a89d3418c3cb97793dbfc51b4c4a1e3c5be53d6bd841cf3994835aafbb5943765687d0b32ec79c48574877d03297dd30c1ebf59f20ead7fcccb4cb6ebc862f85'
+            '2f7d939d391048a7a723afd5e1b2e57e77ced47cd02e13ec5f475a1998b7df96ecdd1f19f14e4657a234882ba2b5235b659c61e4b434fedac980630d6b9a6dd8'
             '714d973bc79446f73bebe85306b3566fe25b554bcbcba2fcbe76709a3eca71fb5d183ab4da2d3b5e9326cb9cd8d13a93f6d4a005ea5a41f7ef8e6c6e81e06b5e'
             'a4b3b03682801a98a1d8c1d14c084fd35efd384d92d497e230e3a28e0bd97b1fa48a93ccb2150f892f0b4154ca4ea2d66f5484a6a59b5c9b49963de42ecf1736'
             'd69d3ec0e270648f55d8c3e420f89d056b120eca5b25e9e7fc1cca799d1a252909ee31ff399c137223eca57cdf82b856221a251b6ff1daf5d6f75c1a582b1e32'
@@ -101,6 +100,14 @@ build() {
   # Delete some unnecessary files
   rm -r "${_prepdir}"/opt/cuda/bin/cuda-uninstaller
 
+  # Define compilers for CUDA to use.
+  # This allows us to use older versions of GCC if we have to.
+  # NOTE: As of cuda 12.3, this appears to be broken on its own.
+  # It worked with cuda 12.2. Due to this bug. we now additionally need an
+  # entry in cuda.sh for this to be recognized.
+  ln -s /usr/bin/gcc-12 "${_prepdir}/opt/cuda/bin/gcc"
+  ln -s /usr/bin/g++-12 "${_prepdir}/opt/cuda/bin/g++"
+
   # Install profile and ld.so.config files
   install -Dm755 "${srcdir}/cuda.sh" "${_prepdir}/etc/profile.d/cuda.sh"
   install -Dm644 "${srcdir}/cuda.conf" "${_prepdir}/etc/ld.so.conf.d/cuda.conf"
diff --git a/cuda.sh b/cuda.sh
index 6a9813f..1ba3821 100644
--- a/cuda.sh
+++ b/cuda.sh
@@ -1,4 +1,7 @@
 export CUDA_PATH=/opt/cuda
 export PATH=$PATH:/opt/cuda/bin:/opt/cuda/nsight_compute:/opt/cuda/nsight_systems/bin
-# NOTE: Make sure this is updated when the gcc host compiler dependency changes.
-export NVCC_PREPEND_FLAGS='-ccbin /usr/bin/g++-12'
+
+# This line used to not be required but it somehow is with cuda 12.3.
+# We reported this as a bug to NVIDIA. For now, this seems like a viable
+# workaround.
+export NVCC_PREPEND_FLAGS='-ccbin /opt/cuda/bin'
-- 
GitLab