about summary refs log tree commit diff
path: root/pkgs/development/mobile
diff options
context:
space:
mode:
authorSandro <sandro.jaeckel@gmail.com>2023-04-01 23:51:19 +0200
committerGitHub <noreply@github.com>2023-04-01 23:51:19 +0200
commit7ecf5641d3e8d77f971238e9ee3a58f5ea8fd6b2 (patch)
tree32f41443b0b45ab506ff6d79a0edfd3d0894ea24 /pkgs/development/mobile
parent5454044f745dec055314b5a090620fc7c8f6ac71 (diff)
parent93e9aac7dc26af7bde133dc1861bfabfd597c577 (diff)
downloadnixlib-7ecf5641d3e8d77f971238e9ee3a58f5ea8fd6b2.tar
nixlib-7ecf5641d3e8d77f971238e9ee3a58f5ea8fd6b2.tar.gz
nixlib-7ecf5641d3e8d77f971238e9ee3a58f5ea8fd6b2.tar.bz2
nixlib-7ecf5641d3e8d77f971238e9ee3a58f5ea8fd6b2.tar.lz
nixlib-7ecf5641d3e8d77f971238e9ee3a58f5ea8fd6b2.tar.xz
nixlib-7ecf5641d3e8d77f971238e9ee3a58f5ea8fd6b2.tar.zst
nixlib-7ecf5641d3e8d77f971238e9ee3a58f5ea8fd6b2.zip
Merge pull request #216142 from status-im/androidenv/fix-toolchains
Diffstat (limited to 'pkgs/development/mobile')
-rw-r--r--pkgs/development/mobile/androidenv/ndk-bundle/default.nix61
1 files changed, 33 insertions, 28 deletions
diff --git a/pkgs/development/mobile/androidenv/ndk-bundle/default.nix b/pkgs/development/mobile/androidenv/ndk-bundle/default.nix
index cc99dfb2971c..a9e1aaca5508 100644
--- a/pkgs/development/mobile/androidenv/ndk-bundle/default.nix
+++ b/pkgs/development/mobile/androidenv/ndk-bundle/default.nix
@@ -7,13 +7,34 @@ let
     coreutils file findutils gawk gnugrep gnused jdk python3 which
   ]) + ":${platform-tools}/platform-tools";
 in
-deployAndroidPackage {
+deployAndroidPackage rec {
   inherit package os;
   nativeBuildInputs = [ makeWrapper ]
     ++ lib.optionals stdenv.isLinux [ autoPatchelfHook ];
   autoPatchelfIgnoreMissingDeps = true;
   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 .
 
     # TODO: allow this stuff
@@ -22,47 +43,31 @@ deployAndroidPackage {
     # Ndk now has a prebuilt toolchains inside, the file layout has changed, we do a symlink
     # to still support the old standalone toolchains builds.
     if [ -d $out/libexec/android-sdk/ndk ] && [ ! -d $out/libexec/android-sdk/ndk-bundle ]; then
-        ln -sf $out/libexec/android-sdk/ndk/${package.revision} $out/libexec/android-sdk/ndk-bundle
+      ln -sf $out/libexec/android-sdk/ndk/${package.revision} $out/libexec/android-sdk/ndk-bundle
     elif [ ! -d $out/libexec/android-sdk/ndk-bundle ]; then
-        echo "The ndk-bundle layout has changed. The nix expressions have to be updated!"
-        exit 1
-    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
+      echo "The ndk-bundle layout has changed. The nix expressions have to be updated!"
+      exit 1
     fi
 
     # fix ineffective PROGDIR / MYNDKDIR determination
     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
 
-    # Patch executables
-    if [ -d prebuilt/linux-x86_64 ]; then
-        autoPatchelf prebuilt/linux-x86_64
-    fi
-
     # wrap
     for progname in ndk-build; do
-        wrapProgram "$(pwd)/$progname" --prefix PATH : "${runtime_paths}"
+      wrapProgram "$(pwd)/$progname" --prefix PATH : "${runtime_paths}"
     done
 
     # make some executables available in PATH
     mkdir -p $out/bin
     for progname in ndk-build; do
-        ln -sf ../libexec/android-sdk/ndk-bundle/$progname $out/bin/$progname
+      ln -sf ../libexec/android-sdk/ndk-bundle/$progname $out/bin/$progname
     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
 }