1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-15 11:03:37 +03:00

mkExtraUtils: use upstream's method.

This commit is contained in:
Samuel Dionne-Riel 2018-06-26 00:08:04 -04:00
parent 79bbe4e6d7
commit 8e917ff0aa
2 changed files with 50 additions and 4 deletions

View File

@ -2,6 +2,7 @@
runCommandCC
, nukeReferences
, glibc
, writeShellScriptBin
, buildPackages
}:
@ -23,10 +24,55 @@ let
${if set ? extraCommand then set.extraCommand else ""}
'';
install_packages = concat(map (install_package) packages);
# A utility for enumerating the shared-library dependencies of a program
findLibs = writeShellScriptBin "find-libs" ''
set -euo pipefail
declare -A seen
declare -a left
patchelf="${buildPackages.patchelf}/bin/patchelf"
function add_needed {
rpath="$($patchelf --print-rpath $1)"
dir="$(dirname $1)"
for lib in $($patchelf --print-needed $1); do
left+=("$lib" "$rpath" "$dir")
done
}
add_needed $1
while [ ''${#left[@]} -ne 0 ]; do
next=''${left[0]}
rpath=''${left[1]}
ORIGIN=''${left[2]}
left=("''${left[@]:3}")
if [ -z ''${seen[$next]+x} ]; then
seen[$next]=1
# Ignore the dynamic linker which for some reason appears as a DT_NEEDED of glibc but isn't in glibc's RPATH.
case "$next" in
ld*.so.?) continue;;
esac
IFS=: read -ra paths <<< $rpath
res=
for path in "''${paths[@]}"; do
path=$(eval "echo $path")
if [ -f "$path/$next" ]; then
res="$path/$next"
echo "$res"
add_needed "$res"
break
fi
done
if [ -z "$res" ]; then
echo "Couldn't satisfy dependency $next" >&2
exit 1
fi
fi
done
'';
in
runCommandCC "extra-utils-${name}"
{
nativeBuildInputs = [ nukeReferences buildPackages.glibc.bin ];
nativeBuildInputs = [ nukeReferences ];
allowedReferences = [ "out" ];
}
''
@ -41,12 +87,11 @@ runCommandCC "extra-utils-${name}"
# Copy ld manually since it isn't detected correctly
cp -pv ${glibc.out}/lib/ld*.so.? $out/lib
# Copy all of the needed libraries
find $out/bin $out/lib -type f | while read BIN; do
echo "Copying libs for executable $BIN"
LDD="$(ldd $BIN)" || continue
LIBS="$(echo "$LDD" | awk '{print $3}' | sed '/^$/d')"
for LIB in $LIBS; do
for LIB in $(${findLibs}/bin/find-libs $BIN); do
TGT="$out/lib/$(basename $LIB)"
if [ ! -f "$TGT" ]; then
SRC="$(readlink -e $LIB)"

View File

@ -19,6 +19,7 @@ in
runCommandCC
glibc
buildPackages
writeShellScriptBin
;
inherit (self.buildPackages)
nukeReferences