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 ] ++ lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
39 autoPatchelfIgnoreMissingDeps = [ "*" ];
40 buildInputs = lib.optionals (os == "linux") [
41 pkgs.zlib
42 pkgs.libcxx
43 (lib.getLib stdenv.cc.cc)
44 ];
45
46 patchElfBnaries = ''
47 # Patch the executables of the toolchains, but not the libraries -- they are needed for crosscompiling
48 if [ -d $out/libexec/android-sdk/ndk-bundle/toolchains/renderscript/prebuilt/linux-x86_64/lib64 ]; then
49 addAutoPatchelfSearchPath $out/libexec/android-sdk/ndk-bundle/toolchains/renderscript/prebuilt/linux-x86_64/lib64
50 fi
51
52 if [ -d $out/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib64 ]; then
53 addAutoPatchelfSearchPath $out/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib64
54 fi
55
56 if [ -d $out/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib ]; then
57 addAutoPatchelfSearchPath $out/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib
58 fi
59
60 find toolchains -type d -name bin -or -name lib64 -or -name lib | while read dir; do
61 autoPatchelf "$dir"
62 done
63
64 # Patch executables
65 if [ -d prebuilt/linux-x86_64 ]; then
66 autoPatchelf prebuilt/linux-x86_64
67 fi
68 '';
69
70 patchOsAgnostic = ''
71 patchShebangs .
72
73 # TODO: allow this stuff
74 rm -rf docs tests
75
76 # Ndk now has a prebuilt toolchains inside, the file layout has changed, we do a symlink
77 # to still support the old standalone toolchains builds.
78 if [ -d $out/libexec/android-sdk/ndk ] && [ ! -d $out/libexec/android-sdk/ndk-bundle ]; then
79 ln -sf $out/libexec/android-sdk/ndk/${package.revision} $out/libexec/android-sdk/ndk-bundle
80 elif [ ! -d $out/libexec/android-sdk/ndk-bundle ]; then
81 echo "The ndk-bundle layout has changed. The nix expressions have to be updated!"
82 exit 1
83 fi
84
85 # fix ineffective PROGDIR / MYNDKDIR determination
86 for progname in ndk-build; do
87 sed -i -e 's|^PROGDIR=`dirname $0`|PROGDIR=`dirname $(readlink -f $(which $0))`|' $progname
88 done
89
90 # wrap
91 for progname in ndk-build; do
92 wrapProgram "$(pwd)/$progname" --prefix PATH : "${runtime_paths}"
93 done
94
95 # make some executables available in PATH
96 mkdir -p $out/bin
97 for progname in ndk-build; do
98 ln -sf ../libexec/android-sdk/ndk-bundle/$progname $out/bin/$progname
99 done
100 '';
101
102 patchInstructions =
103 patchOsAgnostic + lib.optionalString stdenv.hostPlatform.isLinux patchElfBnaries;
104
105 noAuditTmpdir = true; # Audit script gets invoked by the build/ component in the path for the make standalone script
106
107 inherit meta;
108}