Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from extra-data to normal package (v2) #234

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@ for VER in $DRIVER_VERSIONS; do

sed -e "s/@@SDK_BRANCH@@/${SDK_BRANCH}/g" \
-e "s/@@SDK_RUNTIME_VERSION@@/${SDK_RUNTIME_VERSION}/g" \
-e "s/@@ARCH@@/${ARCH}/g" \
-e "s/@@TARGET_ARCH@@/${TARGET_ARCH}/g" \
-e "s/@@ARCH@@/${TARGET_ARCH}/g" \
-e "s/@@NVIDIA_VERSION@@/${NVIDIA_VERSION}/g" \
-e "s=@@EXTRA_DATA@@=${EXTRA_DATA}=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"

Expand Down
14 changes: 0 additions & 14 deletions nvidia-Makefile

This file was deleted.

2 changes: 2 additions & 0 deletions nvidia-extractor/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
gcc -o nvidia-extract -Wall -DNVIDIA_VERSION='"'$(subst -,.,${NVIDIA_VERSION})'"' -DARCH='"'${ARCH}'"' nvidia-extract.c ${CFLAGS} ${LDFLAGS} -larchive -lz -llzma -lzstd
79 changes: 48 additions & 31 deletions nvidia-apply-extra.c → nvidia-extractor/nvidia-extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -181,7 +189,6 @@ should_extract (struct archive_entry *entry)
{
if (!has_prefix (path, "32/"))
return 0;
is_compat32 = 1;
path += 3;
}

Expand All @@ -202,32 +209,27 @@ should_extract (struct archive_entry *entry)
strstr (path, "egl-xlib") ||
strstr (path, "libnvidia-api"))
{
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_prefix (path, "lib") ||
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;
}

Expand Down Expand Up @@ -473,15 +475,22 @@ main (int argc, char *argv[])
int skip_lines;
off_t tar_start;

if (argc < 2)
{
fprintf (stderr, "usage: ./%s <path to NVIDIA installer>\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);
Expand All @@ -493,15 +502,23 @@ 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");

Expand All @@ -510,23 +527,23 @@ main (int argc, char *argv[])
strcmp(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)
Expand All @@ -539,9 +556,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);
Expand Down
33 changes: 9 additions & 24 deletions org.freedesktop.Platform.GL.nvidia.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,26 @@
"runtime": "org.freedesktop.Platform",
"build-extension": true,
"sdk": "org.freedesktop.Sdk",
"sdk-extensions": [
"org.freedesktop.Sdk.Extension.nvidia-base"
],
"runtime-version": "@@SDK_RUNTIME_VERSION@@",
"separate-locales": false,
"build-options": {
"prepend-ld-library-path": "/usr/lib/sdk/nvidia-base/lib",
"ldflags": "-L/usr/lib/sdk/nvidia-base/lib",
"prefix": "/usr/lib/@@ARCH@@-linux-gnu/GL/nvidia-@@NVIDIA_VERSION@@"
},
"finish-args": [
"--extra-data=@@EXTRA_DATA@@",
"--metadata=Extra Data=NoRuntime"
],
"modules": [
{
"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=@@TARGET_ARCH@@" ],
"no-autogen": true,
"make NVIDIA_VERSION=@@NVIDIA_VERSION@@ ARCH=@@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@@"
}
]
}
Expand Down