1{
2 stdenv,
3 lib,
4 pkgs,
5 pkgsHostHost,
6 makeWrapper,
7 autoPatchelfHook,
8 deployAndroidPackage,
9 package,
10 os,
11 arch,
12 platform-tools,
13 meta,
14}:
15
16let
17 runtime_paths =
18 lib.makeBinPath (
19 with pkgsHostHost;
20 [
21 coreutils
22 file
23 findutils
24 gawk
25 gnugrep
26 gnused
27 jdk
28 python3
29 which
30 ]
31 )
32 + ":${platform-tools}/platform-tools";
33in
34deployAndroidPackage rec {
35 inherit package os arch;
36 nativeBuildInputs = [
37 makeWrapper
38 ]
39 ++ lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
40 autoPatchelfIgnoreMissingDeps = [ "*" ];
41 buildInputs = lib.optionals (os == "linux") [
42 pkgs.zlib
43 pkgs.libcxx
44 (lib.getLib stdenv.cc.cc)
45 ];
46
47 patchElfBnaries = ''
48 # Patch the executables of the toolchains, but not the libraries -- they are needed for crosscompiling
49 if [ -d $out/libexec/android-sdk/ndk-bundle/toolchains/renderscript/prebuilt/linux-x86_64/lib64 ]; then
50 addAutoPatchelfSearchPath $out/libexec/android-sdk/ndk-bundle/toolchains/renderscript/prebuilt/linux-x86_64/lib64
51 fi
52
53 if [ -d $out/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib64 ]; then
54 addAutoPatchelfSearchPath $out/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib64
55 fi
56
57 if [ -d $out/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib ]; then
58 addAutoPatchelfSearchPath $out/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib
59 fi
60
61 find toolchains -type d -name bin -or -name lib64 -or -name lib | while read dir; do
62 autoPatchelf "$dir"
63 done
64
65 # Patch executables
66 if [ -d prebuilt/linux-x86_64 ]; then
67 autoPatchelf prebuilt/linux-x86_64
68 fi
69 '';
70
71 patchOsAgnostic = ''
72 patchShebangs .
73
74 # TODO: allow this stuff
75 rm -rf docs tests
76
77 # Ndk now has a prebuilt toolchains inside, the file layout has changed, we do a symlink
78 # to still support the old standalone toolchains builds.
79 if [ -d $out/libexec/android-sdk/ndk ] && [ ! -d $out/libexec/android-sdk/ndk-bundle ]; then
80 ln -sf $out/libexec/android-sdk/ndk/${package.revision} $out/libexec/android-sdk/ndk-bundle
81 elif [ ! -d $out/libexec/android-sdk/ndk-bundle ]; then
82 echo "The ndk-bundle layout has changed. The nix expressions have to be updated!"
83 exit 1
84 fi
85
86 # fix ineffective PROGDIR / MYNDKDIR determination
87 for progname in ndk-build; do
88 sed -i -e 's|^PROGDIR=`dirname $0`|PROGDIR=`dirname $(readlink -f $(which $0))`|' $progname
89 done
90
91 # wrap
92 for progname in ndk-build; do
93 wrapProgram "$(pwd)/$progname" --prefix PATH : "${runtime_paths}"
94 done
95
96 # make some executables available in PATH
97 mkdir -p $out/bin
98 for progname in ndk-build; do
99 ln -sf ../libexec/android-sdk/ndk-bundle/$progname $out/bin/$progname
100 done
101 '';
102
103 patchInstructions =
104 patchOsAgnostic + lib.optionalString stdenv.hostPlatform.isLinux patchElfBnaries;
105
106 noAuditTmpdir = true; # Audit script gets invoked by the build/ component in the path for the make standalone script
107
108 inherit meta;
109}