forked from expo/expo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.nix
116 lines (105 loc) · 3.72 KB
/
shell.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
with (import ../nix {});
let
# These expressions can be deleted when react native depends on version of
# ndk present in nixpkgs.
os = if stdenv.system == "x86_64-linux" then "linux"
else if stdenv.system == "x86_64-darwin" then "macosx" else throw "unsupported system architecture: ${stdenv.system}";
ndk_17c_src = if stdenv.isDarwin then fetchurl {
url = http://dl.google.com/android/repository/android-ndk-r17c-darwin-x86_64.zip;
sha256 = "11iyxgqp017fchn54kkns9mrax73m73xm5wgis266dsq2g36dn73";
} else fetchurl {
url = https://dl.google.com/android/repository/android-ndk-r17c-linux-x86_64.zip;
sha256 = "12b5h5p8b2ia38825dnnacn7b47c0inpys8jp82r42iks3dilm1z";
};
ndk_runtime_paths = lib.makeBinPath [ coreutils file findutils gawk gnugrep gnused jdk python3 which ]; #+ ":${platform-tools}/platform-tools";
ndk = stdenv.mkDerivation {
name = "ndk-17c";
src = ndk_17c_src;
buildInputs = [ unzip autoPatchelfHook makeWrapper python2 ] ++ lib.optional (os == "linux") [ glibc stdenv.cc.cc ncurses5 zlib libcxx.out ];
unpackPhase = ''
mkdir extractedzip
cd extractedzip
unpackFile "$src"
if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ]
then
cd "$(find . -mindepth 1 -maxdepth 1 -type d)"
fi
sourceRoot="$PWD"
'';
installPhase = ''
packageBaseDir=$out/libexec/android-sdk/ndk-bundle
mkdir -p $packageBaseDir
cd $packageBaseDir
cp -av $sourceRoot/* .
'' + lib.optionalString (os == "linux") ''
patchShebangs .
wrapProgram $(pwd)/build/tools/make_standalone_toolchain.py --prefix PATH : "${ndk_runtime_paths}"
rm -rf docs tests
# Patch the executables of the toolchains, but not the libraries -- they are needed for crosscompiling
addAutoPatchelfSearchPath $out/libexec/android-sdk/ndk-bundle/toolchains/renderscript/prebuilt/linux-x86_64/lib64
find toolchains -type d -name bin | while read dir
do
autoPatchelf "$dir"
done
# fix ineffective PROGDIR / MYNDKDIR determination
for i in ndk-build
do
sed -i -e 's|^PROGDIR=`dirname $0`|PROGDIR=`dirname $(readlink -f $(which $0))`|' $i
done
# Patch executables
autoPatchelf prebuilt/linux-x86_64
# wrap
for i in ndk-build
do
wrapProgram "$(pwd)/$i" --prefix PATH : "${ndk_runtime_paths}"
done
# make some executables available in PATH
mkdir -p $out/bin
for i in ndk-build
do
ln -sf ../../libexec/android-sdk/ndk-bundle/$i $out/bin/$i
done
'';
dontStrip = true;
dontPatchELF = true;
dontAutoPatchelf = true;
noAuditTmpdir = true;
};
ndkRoot = "${ndk}/libexec/android-sdk/ndk-bundle";
sdk = androidenv.androidPkgs_9_0.androidsdk;
sdk_path = if stdenv.isDarwin
then "/Library/Android/sdk"
else "/Android/Sdk"; # intentional Capital S
in
mkShell rec {
LANG="en_US.UTF-8";
JAVA_HOME=openjdk8;
ANDROID_SDK_ROOT=builtins.getEnv("HOME") + sdk_path;
ANDROID_NDK_ROOT="${ANDROID_SDK_ROOT}/ndk-bundle";
ANDROID_HOME=ANDROID_SDK_ROOT;
ANDROID_NDK=ANDROID_NDK_ROOT;
nativeBuildInputs = [
awscli
curl
fastlane
git
nodejs
openjdk8
yarn
];
passthru = { inherit ndk ndkRoot; };
shellHook = ''
${./install-ndk-17c.sh} ${ndk} ${ndkRoot}
# grep -v = should clean up build logs, see https://stackoverflow.com/a/52464819/1123156
yes | ${sdk}/bin/sdkmanager --sdk_root="$ANDROID_SDK_ROOT" "build-tools;28.0.3" | grep -v =
'' + lib.optionalString stdenv.isLinux ''
for dep in lib lib64; do
if [ -L /$dep ] || [ ! -e /$dep ]; then
echo "Creating /$dep"
ln -s ${stdenv.cc.libc}/$dep /$dep
else
echo "Using existing /$dep"
fi
done
'';
}