diff --git a/build.sh b/build.sh index 65180ab..ffc90b7 100755 --- a/build.sh +++ b/build.sh @@ -1,45 +1,71 @@ #!/usr/bin/env bash +# shellcheck disable=SC1091 source ./versions.sh ARCH=$1 REPO=$2 EXPORT_ARGS=$3 FB_ARGS=$4 -SUBJECT=${5:-"org.freedesktop.Platform.GL.nvidia `git rev-parse HEAD`"} +SUBJECT=$5 set -e set -x +EXT_PREFIX='org.freedesktop.Platform.GL.nvidia' SDK_BRANCH=1.4 -SDK_RUNTIME_VERSION=1.6 +SDK_RUNTIME_VERSION=23.08 for VER in $DRIVER_VERSIONS; do - F="data/nvidia-$VER-$ARCH.data" - if [ ! -f $F ]; then - echo WARNING, no data file for $VER $ARCH - continue - fi - NVIDIA_VERSION=$(echo $VER | sed "s/\./-/;s/\./-/") - EXTRA_DATA=$(cat $F) - NVIDIA_URL=$(cat $F | sed "s/:[^:]*:[^:]*:[^:]*://") - rm -f org.freedesktop.Platform.GL.nvidia-$NVIDIA_VERSION.json - sed -e "s/@@SDK_BRANCH@@/${SDK_BRANCH}/g" \ - -e "s/@@SDK_RUNTIME_VERSION@@/${SDK_RUNTIME_VERSION}/g" \ - -e "s/@@NVIDIA_VERSION@@/${NVIDIA_VERSION}/g" \ - -e "s=@@EXTRA_DATA@@=${EXTRA_DATA}=g" \ - -e "s=@@NVIDIA_URL@@=${NVIDIA_URL}=g" \ - -e "s=@@ARCH@@=${ARCH}=g" \ - org.freedesktop.Platform.GL.nvidia.json.in > org.freedesktop.Platform.GL.nvidia-$NVIDIA_VERSION.json - - flatpak-builder -v --force-clean --ccache --sandbox --delete-build-dirs \ - --arch=${ARCH} --repo=${REPO} \ - --subject="${SUBJECT}" \ - ${FB_ARGS} ${EXPORT_ARGS} builddir org.freedesktop.Platform.GL.nvidia-$NVIDIA_VERSION.json - - if test "${ARCH}" = "i386" ; then \ - flatpak build-commit-from ${EXPORT_ARGS} --src-ref=runtime/org.freedesktop.Platform.GL.nvidia-${NVIDIA_VERSION}/${ARCH}/${SDK_BRANCH} ${REPO} runtime/org.freedesktop.Platform.GL32.nvidia-${NVIDIA_VERSION}/x86_64/${SDK_BRANCH} ; + if test "${ARCH}" = 'x86_64'; then + # If we're building the x86_64 driver, we also build the i386 driver. + # Note: The i386 driver has to be built first, otherwise the x86_64 ostree repo gets overwritten by it. + TARGET_ARCHES="i386 ${ARCH}" + else + TARGET_ARCHES=${ARCH} fi - rm org.freedesktop.Platform.GL.nvidia-$NVIDIA_VERSION.json + for TARGET_ARCH in ${TARGET_ARCHES}; do + F="data/nvidia-${VER}-${TARGET_ARCH}.data" + if [ ! -f "${F}" ]; then + echo "WARNING: No data file for ${VER} ${TARGET_ARCH}" + continue + fi + + echo "Packaging ${TARGET_ARCH} NVIDIA driver version ${VER} on ${ARCH} host..." + + NVIDIA_VERSION=$(echo "${VER}" | tr '.' '-') + NVIDIA_SHA256=$(awk -F ':' '{print $2}' "${F}") + NVIDIA_URL=$(awk -F '::' '{print $2}' "${F}") + + if test -z "${SUBJECT}"; then + SUBJECT="${VER}" + if test -d '.git'; then + SUBJECT="${SUBJECT} ($(git rev-parse --short HEAD))" + fi + fi + + sed -e "s/@@EXT_PREFIX@@/${EXT_PREFIX}/g" \ + -e "s/@@SDK_BRANCH@@/${SDK_BRANCH}/g" \ + -e "s/@@SDK_RUNTIME_VERSION@@/${SDK_RUNTIME_VERSION}/g" \ + -e "s/@@NVIDIA_VERSION@@/${NVIDIA_VERSION}/g" \ + -e "s=@@NVIDIA_URL@@=${NVIDIA_URL}=g" \ + -e "s/@@NVIDIA_ARCH@@/${TARGET_ARCH}/g" \ + -e "s/@@NVIDIA_SHA256@@/${NVIDIA_SHA256}/g" \ + "${EXT_PREFIX}.json.in" > "${EXT_PREFIX}-${NVIDIA_VERSION}.json" + + flatpak-builder -v --force-clean --ccache --sandbox --delete-build-dirs \ + --arch="${ARCH}" \ + --repo="${REPO}" \ + --subject="${SUBJECT}" \ + ${FB_ARGS} ${EXPORT_ARGS} builddir "${EXT_PREFIX}-${NVIDIA_VERSION}.json" + + if test "${TARGET_ARCH}" = 'i386'; then + flatpak build-commit-from ${EXPORT_ARGS} \ + --src-ref="runtime/${EXT_PREFIX}-${NVIDIA_VERSION}/${ARCH}/${SDK_BRANCH}" \ + "${REPO}" \ + "runtime/org.freedesktop.Platform.GL32.nvidia-${NVIDIA_VERSION}/${ARCH}/${SDK_BRANCH}" + fi + rm "${EXT_PREFIX}-${NVIDIA_VERSION}.json" + done done diff --git a/flathub.json b/flathub.json index 93e2ca8..dc0f2d9 100644 --- a/flathub.json +++ b/flathub.json @@ -1,5 +1,5 @@ { "skip-appstream-check": true, - "only-arches": ["x86_64","i386","aarch64"], + "only-arches": ["x86_64", "aarch64"], "publish-delay-hours": 0 } diff --git a/nvidia-Makefile b/nvidia-Makefile deleted file mode 100644 index 1e8c8e0..0000000 --- a/nvidia-Makefile +++ /dev/null @@ -1,14 +0,0 @@ -all: - gcc -o apply_extra -Wall -static -DNVIDIA_VERSION='"'$(subst -,.,${NVIDIA_VERSION})'"' -DNVIDIA_BASENAME='"'$(notdir ${NVIDIA_URL})'"' -DARCH='"'${ARCH}'"' nvidia-apply-extra.c $(CFLAGS) ${LDFLAGS} -larchive -lz -llzma -lzstd - -install: - mkdir -p ${FLATPAK_DEST}/bin - install -s apply_extra ${FLATPAK_DEST}/bin/apply_extra - rm -rf ${FLATPAK_DEST}/lib - ln -s extra ${FLATPAK_DEST}/lib - ln -s extra/glvnd ${FLATPAK_DEST}/glvnd - ln -s extra/vulkan ${FLATPAK_DEST}/vulkan - ln -s extra/OpenCL ${FLATPAK_DEST}/OpenCL - ln -s extra/egl ${FLATPAK_DEST}/egl - mkdir -p ${FLATPAK_DEST}/share - ln -s ../extra/share/nvidia ${FLATPAK_DEST}/share/nvidia diff --git a/nvidia-extractor/Makefile b/nvidia-extractor/Makefile new file mode 100644 index 0000000..d7640e8 --- /dev/null +++ b/nvidia-extractor/Makefile @@ -0,0 +1,2 @@ +all: + gcc -o nvidia-extract -Wall -DNVIDIA_VERSION='"'$(subst -,.,${NVIDIA_VERSION})'"' -DNVIDIA_ARCH='"'${NVIDIA_ARCH}'"' nvidia-extract.c $(CFLAGS) ${LDFLAGS} -larchive -lz -llzma -lzstd diff --git a/nvidia-apply-extra.c b/nvidia-extractor/nvidia-extract.c similarity index 86% rename from nvidia-apply-extra.c rename to nvidia-extractor/nvidia-extract.c index ad45a45..efe3eb9 100644 --- a/nvidia-apply-extra.c +++ b/nvidia-extractor/nvidia-extract.c @@ -14,6 +14,7 @@ int nvidia_major_version = 0; int nvidia_minor_version = 0; int nvidia_patch_version = 0; +int embedded_installer = 0; void die_with_error (const char *format, ...) @@ -122,11 +123,18 @@ should_extract (struct archive_entry *entry) { const char *path = archive_entry_pathname (entry); char new_path[PATH_MAX]; - int is_compat32 = 0; if (has_prefix (path, "./")) path += 2; + /* this tar is only a container that stores the actual driver .run file */ + if (has_suffix (path, ".run")) + { + archive_entry_set_pathname (entry, "./embedded_installer.run"); + embedded_installer = 1; + return 1; + } + if (strcmp (path, "nvidia_icd.json") == 0 || strcmp (path, "nvidia_icd.json.template") == 0) { archive_entry_set_pathname (entry, "./vulkan/icd.d/nvidia_icd.json"); @@ -160,17 +168,14 @@ should_extract (struct archive_entry *entry) return 1; } -#ifdef __i386__ /* Nvidia no longer has 32bit drivers so we are getting * the 32bit compat libs from the 64bit drivers */ - if (nvidia_major_version > 390) + if (strcmp (NVIDIA_ARCH, "i386") == 0 && nvidia_major_version > 390) { if (!has_prefix (path, "32/")) return 0; - is_compat32 = 1; path += 3; } -#endif /* Skip these as we're using GLVND on majod > 367*/ if (nvidia_major_version > 367 && @@ -186,8 +191,8 @@ should_extract (struct archive_entry *entry) if (strstr (path, "egl-wayland") || strstr (path, "egl-gbm")) { - if (is_compat32) - archive_entry_set_pathname (entry, path); + snprintf (new_path, sizeof new_path, "./lib/%s", path); + archive_entry_set_pathname (entry, new_path); return 1; } @@ -195,23 +200,18 @@ should_extract (struct archive_entry *entry) has_prefix (path, "tls/lib"))&& has_suffix (path, ".so." NVIDIA_VERSION)) { - if (is_compat32) - archive_entry_set_pathname (entry, path); + snprintf (new_path, sizeof new_path, "./lib/%s", path); + archive_entry_set_pathname (entry, new_path); return 1; } if (has_suffix (path, ".dll")) { - snprintf (new_path, sizeof new_path, "./nvidia/wine/%s", path); + snprintf (new_path, sizeof new_path, "./lib/nvidia/wine/%s", path); archive_entry_set_pathname (entry, new_path); return 1; } - /* this tar is only a container that stores the actual driver .run file */ - if (strcmp (path, "builds/NVIDIA-Linux-" ARCH "-" NVIDIA_VERSION ".run") == 0) { - return 1; - } - return 0; } @@ -457,15 +457,22 @@ main (int argc, char *argv[]) int skip_lines; off_t tar_start; + if (argc < 2) + { + fprintf (stderr, "usage: ./%s \n", argv[0]); + return 1; + } + const char *nvidia_installer_path = argv[1]; + if (parse_driver_version (NVIDIA_VERSION, &nvidia_major_version, &nvidia_minor_version, &nvidia_patch_version)) die ("failed to parse driver version '%s'.", NVIDIA_VERSION); - fd = open (NVIDIA_BASENAME, O_RDONLY); + fd = open (nvidia_installer_path, O_RDONLY); if (fd == -1) - die_with_error ("open extra data"); + die_with_error ("opening installer"); skip_lines = find_skip_lines (fd); tar_start = find_line_offset (fd, skip_lines); @@ -477,40 +484,48 @@ main (int argc, char *argv[]) close (fd); - unlink (NVIDIA_BASENAME); - /* check if this container is just a wrapper over the real driver container */ - if (rename ("./builds/NVIDIA-Linux-" ARCH "-" NVIDIA_VERSION ".run", NVIDIA_BASENAME) == 0) - return main (argc, argv); - else if (errno != ENOENT) - die_with_error ("rename ./builds/NVIDIA-Linux-" ARCH "-" NVIDIA_VERSION ".run failed"); + if (access ("embedded_installer.run", F_OK) == 0) + { + if (embedded_installer) + { + /* marks it for deletion after it gets extracted */ + embedded_installer = 0; + argv[1] = "embedded_installer.run"; + return main (argc, argv); + } + else + { + unlink ("embedded_installer.run"); + } + } - char *ldconfig_argv[] = {"ldconfig", "-n", ".", NULL}; + char *ldconfig_argv[] = {"ldconfig", "-n", "lib", NULL}; if (subprocess (ldconfig_argv)) die ("running ldconfig failed"); if (((nvidia_major_version == 470 && nvidia_minor_version >= 63) || nvidia_major_version >= 495) && nvidia_major_version < 545 && - strcmp(ARCH, "i386") != 0) + strcmp(NVIDIA_ARCH, "i386") != 0) { checked_symlink ("libnvidia-vulkan-producer.so." NVIDIA_VERSION, - "libnvidia-vulkan-producer.so"); + "lib/libnvidia-vulkan-producer.so"); } if (nvidia_major_version >= 550) { - checked_symlink ("libnvidia-gpucomp.so." NVIDIA_VERSION, "libnvidia-gpucomp.so"); + checked_symlink ("libnvidia-gpucomp.so." NVIDIA_VERSION, "lib/libnvidia-gpucomp.so"); } - checked_symlink ("libcuda.so.1", "libcuda.so"); - checked_symlink ("libnvidia-ml.so.1", "libnvidia-ml.so"); - checked_symlink ("libnvidia-opencl.so.1", "libnvidia-opencl.so"); - checked_symlink ("libvdpau_nvidia.so.1", "libvdpau_nvidia.so"); + checked_symlink ("libcuda.so.1", "lib/libcuda.so"); + checked_symlink ("libnvidia-ml.so.1", "lib/libnvidia-ml.so"); + checked_symlink ("libnvidia-opencl.so.1", "lib/libnvidia-opencl.so"); + checked_symlink ("libvdpau_nvidia.so.1", "lib/libvdpau_nvidia.so"); if (nvidia_major_version >= 495) { - mkdir ("gbm", 0755); - checked_symlink ("../libnvidia-allocator.so." NVIDIA_VERSION, "gbm/nvidia-drm_gbm.so"); + mkdir ("lib/gbm", 0755); + checked_symlink ("../libnvidia-allocator.so." NVIDIA_VERSION, "lib/gbm/nvidia-drm_gbm.so"); } if (nvidia_major_version >= 319) @@ -523,9 +538,9 @@ main (int argc, char *argv[]) if (nvidia_major_version <= 390) { - unlink ("libnvidia-tls.so." NVIDIA_VERSION); + unlink ("lib/libnvidia-tls.so." NVIDIA_VERSION); checked_symlink ("tls/libnvidia-tls.so." NVIDIA_VERSION, - "libnvidia-tls.so." NVIDIA_VERSION); + "lib/libnvidia-tls.so." NVIDIA_VERSION); } mkdir ("OpenCL", 0755); diff --git a/org.freedesktop.Platform.GL.nvidia.json.in b/org.freedesktop.Platform.GL.nvidia.json.in index e13e7df..f94e62e 100644 --- a/org.freedesktop.Platform.GL.nvidia.json.in +++ b/org.freedesktop.Platform.GL.nvidia.json.in @@ -1,5 +1,5 @@ { - "id": "org.freedesktop.Platform.GL.nvidia-@@NVIDIA_VERSION@@", + "id": "@@EXT_PREFIX@@-@@NVIDIA_VERSION@@", "branch": "@@SDK_BRANCH@@", "runtime": "org.freedesktop.Platform", "build-extension": true, @@ -7,77 +7,24 @@ "runtime-version": "@@SDK_RUNTIME_VERSION@@", "sdk-extensions": [], "separate-locales": false, - "cleanup": ["/include"], - "build-options" : { - "append-ld-library-path": "/usr/lib/GL/nvidia-@@NVIDIA_VERSION@@/lib", - "cflags": "-O2 -g -I/usr/lib/GL/nvidia-@@NVIDIA_VERSION@@/include", - "cxxflags": "-O2 -g", - "prefix": "/usr/lib/GL/nvidia-@@NVIDIA_VERSION@@", - "env": { - "V": "1", - "LDFLAGS": "-L/usr/lib/GL/nvidia-@@NVIDIA_VERSION@@/lib" - } - }, - "finish-args": [ - "--extra-data=@@EXTRA_DATA@@", - "--metadata=Extra Data=NoRuntime" - ], "modules": [ { - "name": "libzstd", - "no-autogen": true, - "subdir": "lib", - "make-args": [ - "lib-mt" - ], - "make-install-args": [ - "PREFIX=${FLATPAK_DEST}", - "LIBDIR=${FLATPAK_DEST}/lib" - ], - "sources": [ - { - "type": "archive", - "url": "https://github.com/facebook/zstd/releases/download/v1.5.4/zstd-1.5.4.tar.gz", - "sha256": "0f470992aedad543126d06efab344dc5f3e171893810455787d38347343a4424" - } - ] - }, - { - "cleanup": ["/include", "/share"], - "name": "libarchive", - "config-opts": [ "--disable-shared", "--enable-static", "--disable-xattr", "--disable-acl", - "--without-bz2lib", "--without-iconv", "--without-lz4", "--without-lzo2", "--without-nettle", - "--without-openssl", "--without-xml2", "--without-expat", "--disable-bsdcat", "--disable-bsdcpio", - "--disable-bsdtar" - ], - "sources": [ - { - "type": "archive", - "url": "https://www.libarchive.de/downloads/libarchive-3.6.2.tar.xz", - "sha256": "9e2c1b80d5fbe59b61308fdfab6c79b5021d7ff4ff2489fb12daf0a96a83551d" - } - ] - }, - { - "name": "ldconfig", + "name": "nvidia", "buildsystem": "simple", "build-commands": [ - "install -Dvm755 -t ${FLATPAK_DEST}/bin/ $(which ldconfig)" - ] - }, - { - "name": "nvidia", - "make-args": [ "NVIDIA_VERSION=@@NVIDIA_VERSION@@", "NVIDIA_URL=@@NVIDIA_URL@@", "ARCH=@@ARCH@@" ], - "no-autogen": true, + "make NVIDIA_VERSION=@@NVIDIA_VERSION@@ NVIDIA_ARCH=@@NVIDIA_ARCH@@", + "cd $FLATPAK_DEST && $FLATPAK_BUILDER_BUILDDIR/nvidia-extract $FLATPAK_BUILDER_BUILDDIR/*.run" + ], "sources": [ { - "type": "file", - "path": "nvidia-Makefile", - "dest-filename": "makefile" + "type": "dir", + "path": "nvidia-extractor" }, { "type": "file", - "path": "nvidia-apply-extra.c" + "dest-filename": "installer-@@NVIDIA_VERSION@@.run", + "url": "@@NVIDIA_URL@@", + "sha256": "@@NVIDIA_SHA256@@" } ] }