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

WIP: cudaPackages.cudatoolkit: split outputs #178439

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
#!/usr/bin/env bash

# Run autoOpenGLRunpath on all files
echo "Sourcing auto-add-opengl-runpath-hook"

autoAddOpenGLRunpathPhase () {
# TODO: support multiple outputs
for file in $(find ${out,lib,bin} -type f); do
autoAddOpenGLRunpathPhase() {
# shellcheck disable=SC2154 # ignore undeclared "outputs"
# shellcheck disable=SC2068 # ignore "double quote array expansions" for ${outputs[@]}
# FIXME: SC2044 (warning): For loops over find output are fragile. Use find -exec or a while read loop
for file in $(
find $(
for output in ${outputs[@]} ; do
[ -e ${!output} ] || continue
echo ${!output}
done
) -type f
); do
addOpenGLRunpath $file
done
}
Expand Down
124 changes: 83 additions & 41 deletions pkgs/development/compilers/cudatoolkit/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ args@
, name ? ""
, developerProgram ? false
, runPatches ? []
, autoPatchelfHook
, autoAddOpenGLRunpathHook
, addOpenGLRunpath
, alsa-lib
, expat
Expand All @@ -17,13 +19,20 @@ args@
, glibc
, gtk2
, lib
, libxkbcommon
, libkrb5
, krb5
, makeWrapper
, ncurses5
, numactl
, nss
, perl
, python27
, pulseaudio
, requireFile
, stdenv
, unixODBC
, wayland
, xorg
, zlib
}:
Expand Down Expand Up @@ -53,12 +62,76 @@ stdenv.mkDerivation rec {

outputs = [ "out" "lib" "doc" ];

nativeBuildInputs = [ perl makeWrapper addOpenGLRunpath ];
buildInputs = [ gdk-pixbuf ]; # To get $GDK_PIXBUF_MODULE_FILE via setup-hook
nativeBuildInputs = [
perl
makeWrapper
addOpenGLRunpath
autoPatchelfHook
autoAddOpenGLRunpathHook
];
buildInputs = [
# To get $GDK_PIXBUF_MODULE_FILE via setup-hook
gdk-pixbuf

# For autoPatchelf
ncurses5
expat
python27
zlib
glibc
xorg.libX11
xorg.libXext
xorg.libXrender
xorg.libXt
xorg.libXtst
xorg.libXi
xorg.libXext
xorg.libXdamage
xorg.libxcb
xorg.xcbutilimage
xorg.xcbutilrenderutil
xorg.xcbutilwm
xorg.xcbutilkeysyms
pulseaudio
libxkbcommon
libkrb5
krb5
gtk2
glib
fontconfig
freetype
numactl
nss
unixODBC
alsa-lib
wayland
];

# Prepended to runpaths by autoPatchelf.
# The order inherited from older rpath preFixup code
runtimeDependencies = [
ncurses5 expat python27 zlib glibc
xorg.libX11 xorg.libXext xorg.libXrender xorg.libXt xorg.libXtst xorg.libXi xorg.libXext
gtk2 glib fontconfig freetype unixODBC alsa-lib
(placeholder "lib")
(placeholder "out")
"${placeholder "out"}/nvvm"
# Is it not handled by autoPatchelf automatically?
"${lib.getLib stdenv.cc.cc}/lib64"
"${placeholder "out"}/jre/lib/amd64/jli"
"${placeholder "out"}/lib64"
"${placeholder "out"}/nvvm/lib64"
];

autoPatchelfIgnoreMissingDeps = [
# This is the hardware-dependent userspace driver that comes from
# nvidia_x11 package. It must be deployed at runtime in
# /run/opengl-driver/lib or pointed at by LD_LIBRARY_PATH variable, rather
# than pinned in runpath
"libcuda.so.1"

# The krb5 expression ships libcom_err.so.3 but cudatoolkit asks for the
# older
# This dependency is asked for by target-linux-x64/CollectX/RedHat/x86_64/libssl.so.10
# - do we even want to use nvidia-shipped libssl?
"libcom_err.so.2"
];

unpackPhase = ''
Expand Down Expand Up @@ -189,47 +262,16 @@ stdenv.mkDerivation rec {
'';

preFixup =
let rpath = lib.concatStringsSep ":" [
(lib.makeLibraryPath (runtimeDependencies ++ [ "$lib" "$out" "$out/nvvm" ]))
let rpath = lib.makeLibraryPath [
"$lib"
"$out"
"$out/nvvm"
"${stdenv.cc.cc.lib}/lib64"
"$out/jre/lib/amd64/jli"
"$out/lib64"
"$out/nvvm/lib64"
];
in
''
while IFS= read -r -d $'\0' i; do
if ! isELF "$i"; then continue; fi
echo "patching $i..."
if [[ ! $i =~ \.so ]]; then
patchelf \
--set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $i
fi
if [[ $i =~ libcudart ]]; then
patchelf --remove-rpath $i
else
patchelf --set-rpath "${rpath}" --force-rpath $i
fi
done < <(find $out $lib $doc -type f -print0)
'' + lib.optionalString (lib.versionAtLeast version "11") ''
for file in $out/target-linux-x64/*.so; do
echo "patching $file..."
patchelf --set-rpath "${rpath}:\$ORIGIN" $file
done
'';

# Set RPATH so that libcuda and other libraries in
# /run/opengl-driver(-32)/lib can be found. See the explanation in
# addOpenGLRunpath. Don't try to figure out which libraries really need
# it, just patch all (but not the stubs libraries). Note that
# --force-rpath prevents changing RPATH (set above) to RUNPATH.
postFixup = ''
addOpenGLRunpath --force-rpath {$out,$lib}/lib/lib*.so
'' + lib.optionalString (lib.versionAtLeast version "11") ''
addOpenGLRunpath $out/cuda_sanitizer_api/compute-sanitizer/*
addOpenGLRunpath $out/cuda_sanitizer_api/compute-sanitizer/x86/*
addOpenGLRunpath $out/target-linux-x64/*
'';
in "";

# cuda-gdb doesn't run correctly when not using sandboxing, so
# temporarily disabling the install check. This should be set to true
Expand Down