Skip to content

Commit

Permalink
Add target libraries/executables to executable's RPATH
Browse files Browse the repository at this point in the history
  • Loading branch information
billysuh7 committed Oct 31, 2024
1 parent ea29b62 commit 20ca038
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion conda-forge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ build_platform:
linux_aarch64: linux_64
linux_ppc64le: linux_64
conda_build:
error_overlinking: true
error_overlinking: false
conda_forge_output_validation: true
github:
branch_name: main
Expand Down
9 changes: 9 additions & 0 deletions recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ for i in `ls`; do
[[ $i == "conda_build.sh" ]] && continue
[[ $i == "metadata_conda_debug.yaml" ]] && continue

if [[ $i == "bin" ]]; then
for j in `ls "${i}"`; do
[[ -f "bin/${j}" ]] || continue

echo patchelf --force-rpath --set-rpath "\$ORIGIN/../lib:\$ORIGIN/../${targetsDir}/lib" "${i}/${j}" ...
patchelf --force-rpath --set-rpath "\$ORIGIN/../lib:\$ORIGIN/../${targetsDir}/lib" "${i}/${j}"
done
fi

# bin installed in PREFIX
cp -rv $i ${PREFIX}
done
8 changes: 7 additions & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ source:
sha256: b586c315e32731794f8bc7b3cbccbeb7f535d361f0191b456f730c70ad74612e # [win]

build:
number: 0
number: 1
binary_relocation: false
skip: true # [osx or ppc64le]

requirements:
Expand All @@ -33,9 +34,14 @@ requirements:
- {{ pin_compatible("cuda-version", max_pin="x.x") }}

test:
requires:
- patchelf # [linux]
files:
- test-rpath.sh # [linux]
commands:
- test -f $PREFIX/bin/nvprune # [unix]
- if not exist %LIBRARY_BIN%\\nvprune.exe exit 1 # [win]
- bash test-rpath.sh # [linux]

about:
home: https://developer.nvidia.com/cuda-toolkit
Expand Down
40 changes: 40 additions & 0 deletions recipe/test-rpath.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

[[ ${target_platform} == "linux-64" ]] && targetsDir="targets/x86_64-linux"
[[ ${target_platform} == "linux-ppc64le" ]] && targetsDir="targets/ppc64le-linux"
[[ ${target_platform} == "linux-aarch64" ]] && targetsDir="targets/sbsa-linux"

errors=""

for bin in `find ${PREFIX}/bin -type f`; do
[[ "${bin}" =~ "patchelf" ]] && continue

filename=$(basename "${bin}")
echo "Artifact to test: ${filename}"

pkg_info=$(conda package -w "${bin}")
echo "\$PKG_NAME: ${PKG_NAME}"
echo "\$pkg_info: ${pkg_info}"

if [[ ! "$pkg_info" == *"$PKG_NAME"* ]]; then
echo "Not a match, skipping ${bin}"
continue
fi

echo "Match found, testing ${bin}"

rpath=$(patchelf --print-rpath "${bin}")
echo "${bin} rpath: ${rpath}"

if [[ $rpath != "\$ORIGIN/../lib:\$ORIGIN/../${targetsDir}/lib" ]]; then
errors+="${bin}\n"
elif [[ $(objdump -x ${bin} | grep "PATH") == *"RUNPATH"* ]]; then
errors+="${bin}\n"
fi
done

if [[ $errors ]]; then
echo "The following binaries were found with an unexpected RPATH:"
echo -e "${errors}"
exit 1
fi

0 comments on commit 20ca038

Please sign in to comment.