Skip to content

Commit 3587c5e

Browse files
committed
Refactors rpath to externally set var. Adds mechanism to add metadata
1 parent 8c5072e commit 3587c5e

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

manywheel/build_common.sh

+24-4
Original file line numberDiff line numberDiff line change
@@ -357,20 +357,40 @@ for pkg in /$WHEELHOUSE_DIR/torch*linux*.whl /$LIBTORCH_HOUSE_DIR/libtorch*.zip;
357357
done
358358
fi
359359

360+
: "${C_SO_RPATH:='$ORIGIN:$ORIGIN/lib'}"
361+
: "${LIB_SO_RPATH:='$ORIGIN'}"
362+
360363
# set RPATH of _C.so and similar to $ORIGIN, $ORIGIN/lib
361364
find $PREFIX -maxdepth 1 -type f -name "*.so*" | while read sofile; do
362-
echo "Setting rpath of $sofile to " '$ORIGIN:$ORIGIN/lib'
363-
$PATCHELF_BIN --set-rpath '$ORIGIN:$ORIGIN/lib' $sofile
365+
echo "Setting rpath of $sofile to $C_SO_RPATH"
366+
$PATCHELF_BIN --set-rpath $C_SO_RPATH $sofile
364367
$PATCHELF_BIN --print-rpath $sofile
365368
done
366369

367370
# set RPATH of lib/ files to $ORIGIN
368371
find $PREFIX/lib -maxdepth 1 -type f -name "*.so*" | while read sofile; do
369-
echo "Setting rpath of $sofile to " '$ORIGIN'
370-
$PATCHELF_BIN --set-rpath '$ORIGIN' $sofile
372+
echo "Setting rpath of $sofile to $LIB_SO_RPATH"
373+
$PATCHELF_BIN --set-rpath $LIB_SO_RPATH $sofile
371374
$PATCHELF_BIN --print-rpath $sofile
372375
done
373376

377+
# add dependencies to METADATA
378+
# set WHEEL_DEPENDENCIES to be a string in your wrapper script. e.g.: set the
379+
# following in build_cuda.sh to get cuda dependencies.
380+
#
381+
# export WHEEL_DEPENDENCIES="Requires-Dist: nvidia-cublas-cu11\nRequires-Dist: nvidia-cuda-cupti-cu11"
382+
#
383+
# Notice that each dependency is prefixed 'Requires-Dist: ' and suffixed with a new line char.
384+
# The last dependency in the string doesn't have the new line char.
385+
# This formatting conforms to the METADATA file in a wheel.
386+
if [[ -n "$WHEEL_DEPENDENCIES" ]]; then
387+
metadata_file=$(echo $(basename $pkg) | sed -e 's/-cp.*$/.dist-info\/METADATA/g')
388+
if [[ -e $metadata_file ]]; then
389+
echo "Adding dependencies to metadata file $metadata_file"
390+
sed -i "/^Requires-Dist.*/a$WHEEL_DEPENDENCIES" $metadata_file
391+
fi
392+
fi
393+
374394
# regenerate the RECORD file with new hashes
375395
record_file=$(echo $(basename $pkg) | sed -e 's/-cp.*$/.dist-info\/RECORD/g')
376396
if [[ -e $record_file ]]; then

0 commit comments

Comments
 (0)