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

Add target libraries/executables to executable's RPATH #29

Merged
merged 4 commits into from
Nov 8, 2024
Merged
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
17 changes: 0 additions & 17 deletions .github/workflows/automerge.yml

This file was deleted.

13 changes: 0 additions & 13 deletions .github/workflows/webservices.yml

This file was deleted.

6 changes: 2 additions & 4 deletions .scripts/run_win_build.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion azure-pipelines.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
23 changes: 23 additions & 0 deletions recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ for i in `ls`; do
mkdir -p ${PREFIX}/${targetsDir}
mkdir -p ${PREFIX}/$i
if [[ $i == "bin" ]]; then
for j in `ls "${i}"`; do
[[ -f "bin/${j}" ]] || continue

if grep -qx "${j}" ${RECIPE_DIR}/patchelf_exclude.txt; then
echo "Skipping bin/${j} as it is in the patchelf exclusion list."
continue
fi

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

mkdir -p ${PREFIX}/${targetsDir}/bin
cp -rv $i ${PREFIX}
ln -sv ${PREFIX}/bin/nvcc ${PREFIX}/${targetsDir}/bin/nvcc
Expand All @@ -29,6 +41,17 @@ for i in `ls`; do
elif [[ $i == "include" ]]; then
cp -rv $i ${PREFIX}/${targetsDir}
elif [[ $i == "nvvm" ]]; then
for j in `find "${i}"`; do
if [[ "${j}" =~ /bin/.*$ ]]; then
# Adds the following paths relative to `$PREFIX` to the `RPATH`: `nvvm/lib64`, `lib`, `${targetsDir}/lib`
echo patchelf --force-rpath --set-rpath "\$ORIGIN/../lib64:\$ORIGIN/../../lib:\$ORIGIN/../../${targetsDir}/lib" "${j}" ...
billysuh7 marked this conversation as resolved.
Show resolved Hide resolved
patchelf --force-rpath --set-rpath "\$ORIGIN/../lib64:\$ORIGIN/../../lib:\$ORIGIN/../../${targetsDir}/lib" "${j}"
elif [[ "${j}" =~ /lib.*/.*\.so($|\.) && ! -L "${j}" ]]; then
echo patchelf --force-rpath --set-rpath "\$ORIGIN" "${j}" ...
patchelf --force-rpath --set-rpath "\$ORIGIN" "${j}"
fi
done

cp -rv $i ${PREFIX}
ln -sv ${PREFIX}/nvvm ${PREFIX}/${targetsDir}/nvvm
fi
Expand Down
19 changes: 18 additions & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ source:
- nvcc.profile.patch.win # [win]

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

outputs:
Expand All @@ -56,9 +57,15 @@ outputs:
- gcc_impl_{{ target_platform }} {{ gcc_constraint }} # [linux]
- arm-variant * {{ arm_variant_type }} # [aarch64]
test:
requires:
- patchelf # [linux]
files:
- patchelf_exclude.txt # [linux]
- test-rpath-nvcc.sh # [linux]
commands:
- test -f $PREFIX/bin/nvcc # [linux]
- test -f $PREFIX/bin/ptxas # [linux]
- bash test-rpath-nvcc.sh # [linux]
about:
home: https://developer.nvidia.com/cuda-toolkit
license_file: LICENSE
Expand Down Expand Up @@ -259,9 +266,14 @@ outputs:
run_constrained:
- arm-variant * {{ arm_variant_type }} # [aarch64]
test:
requires:
- patchelf # [linux]
files:
- test-rpath-nvvm.sh # [linux]
commands:
- test -d $PREFIX/nvvm # [linux]
- test -f $PREFIX/nvvm/bin/cicc # [linux]
- bash test-rpath-nvvm.sh # [linux]
- if not exist %LIBRARY_PREFIX%\nvvm\bin\cicc.exe exit 1 # [win]
- if not exist %LIBRARY_PREFIX%\nvvm\libdevice exit 1 # [win]
about:
Expand Down Expand Up @@ -322,9 +334,14 @@ outputs:
run_constrained:
- arm-variant * {{ arm_variant_type }} # [aarch64]
test:
requires:
- patchelf # [linux]
files:
- test-rpath-nvvm.sh # [linux]
commands:
- test -d $PREFIX/nvvm/include # [linux]
- test -d $PREFIX/nvvm/lib64 # [linux]
- bash test-rpath-nvvm.sh # [linux]
- if not exist %LIBRARY_PREFIX%\nvvm\include exit 1 # [win]
- if not exist %LIBRARY_PREFIX%\nvvm\lib exit 1 # [win]
about:
Expand Down
4 changes: 4 additions & 0 deletions recipe/patchelf_exclude.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
crt/link.stub
crt/prelink.stub
nvcc.profile
patchelf
43 changes: 43 additions & 0 deletions recipe/test-rpath-nvcc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/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 item in `find ${PREFIX}/bin -type f`; do
filename=$(basename "${item}")
echo "Artifact to test: ${filename}"

if grep -qx "${filename}" patchelf_exclude.txt; then
echo Skipping ${filename} as it is not subject to testing
continue
fi

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

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

echo "Match found, testing ${item}"

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

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

if [[ $errors ]]; then
echo "The following items were found with an unexpected RPATH:"
echo -e "${errors}"
exit 1
fi
51 changes: 51 additions & 0 deletions recipe/test-rpath-nvvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/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=""

dirs=()
[[ -d ${PREFIX}/nvvm/bin ]] && dirs+=(${PREFIX}/nvvm/bin)
[[ -d ${PREFIX}/nvvm/lib64 ]] && dirs+=(${PREFIX}/nvvm/lib64)

if [[ ${#dirs[@]} == 0 ]]; then
echo "There is nothing to test. Returning."
exit
fi

for item in `find ${dirs[@]} -type f`; do
[[ -L $item ]] && continue

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

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

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

echo "Match found, testing ${item}"

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

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

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