androidenv: fix autopatching toolchains

Use of binaries from NDK `toolchains` has been broken by following PR:

* https://github.com/NixOS/nixpkgs/pull/195752

I'm splitting the patchInstructions to run the ELF patching only on Linux.

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2023-02-13 10:50:04 +01:00
parent be0b34847b
commit 93e9aac7dc
No known key found for this signature in database
GPG key ID: FE65CD384D5BF7B4

View file

@ -7,13 +7,34 @@ let
coreutils file findutils gawk gnugrep gnused jdk python3 which coreutils file findutils gawk gnugrep gnused jdk python3 which
]) + ":${platform-tools}/platform-tools"; ]) + ":${platform-tools}/platform-tools";
in in
deployAndroidPackage { deployAndroidPackage rec {
inherit package os; inherit package os;
nativeBuildInputs = [ makeWrapper ] nativeBuildInputs = [ makeWrapper ]
++ lib.optionals stdenv.isLinux [ autoPatchelfHook ]; ++ lib.optionals stdenv.isLinux [ autoPatchelfHook ];
autoPatchelfIgnoreMissingDeps = true; autoPatchelfIgnoreMissingDeps = true;
buildInputs = lib.optionals (os == "linux") [ pkgs.zlib ]; buildInputs = lib.optionals (os == "linux") [ pkgs.zlib ];
patchInstructions = ''
patchElfBnaries = ''
# Patch the executables of the toolchains, but not the libraries -- they are needed for crosscompiling
if [ -d $out/libexec/android-sdk/ndk-bundle/toolchains/renderscript/prebuilt/linux-x86_64/lib64 ]; then
addAutoPatchelfSearchPath $out/libexec/android-sdk/ndk-bundle/toolchains/renderscript/prebuilt/linux-x86_64/lib64
fi
if [ -d $out/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib64 ]; then
addAutoPatchelfSearchPath $out/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib64
fi
find toolchains -type d -name bin -or -name lib64 | while read dir; do
autoPatchelf "$dir"
done
# Patch executables
if [ -d prebuilt/linux-x86_64 ]; then
autoPatchelf prebuilt/linux-x86_64
fi
'';
patchOsAgnostic = ''
patchShebangs . patchShebangs .
# TODO: allow this stuff # TODO: allow this stuff
@ -28,31 +49,11 @@ deployAndroidPackage {
exit 1 exit 1
fi fi
# Patch the executables of the toolchains, but not the libraries -- they are needed for crosscompiling
if [ -d $out/libexec/android-sdk/ndk-bundle/toolchains/renderscript/prebuilt/linux-x86_64/lib64 ]; then
addAutoPatchelfSearchPath $out/libexec/android-sdk/ndk-bundle/toolchains/renderscript/prebuilt/linux-x86_64/lib64
fi
if [ -d $out/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib64 ]; then
addAutoPatchelfSearchPath $out/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib64
fi
if [ -d toolchains/llvm/prebuilt/linux-x86_64 ]; then
find toolchains/llvm/prebuilt/linux-x86_64 -type d -name bin -or -name lib64 | while read dir; do
autoPatchelf "$dir"
done
fi
# fix ineffective PROGDIR / MYNDKDIR determination # fix ineffective PROGDIR / MYNDKDIR determination
for progname in ndk-build; do for progname in ndk-build; do
sed -i -e 's|^PROGDIR=`dirname $0`|PROGDIR=`dirname $(readlink -f $(which $0))`|' $progname sed -i -e 's|^PROGDIR=`dirname $0`|PROGDIR=`dirname $(readlink -f $(which $0))`|' $progname
done done
# Patch executables
if [ -d prebuilt/linux-x86_64 ]; then
autoPatchelf prebuilt/linux-x86_64
fi
# wrap # wrap
for progname in ndk-build; do for progname in ndk-build; do
wrapProgram "$(pwd)/$progname" --prefix PATH : "${runtime_paths}" wrapProgram "$(pwd)/$progname" --prefix PATH : "${runtime_paths}"
@ -64,5 +65,9 @@ deployAndroidPackage {
ln -sf ../libexec/android-sdk/ndk-bundle/$progname $out/bin/$progname ln -sf ../libexec/android-sdk/ndk-bundle/$progname $out/bin/$progname
done done
''; '';
patchInstructions = patchOsAgnostic
+ lib.optionalString stdenv.isLinux patchElfBnaries;
noAuditTmpdir = true; # Audit script gets invoked by the build/ component in the path for the make standalone script noAuditTmpdir = true; # Audit script gets invoked by the build/ component in the path for the make standalone script
} }