at 25.11-pre 162 lines 6.3 kB view raw
1{ 2 stdenv, 3 stdenvNoCC, 4 lib, 5 fetchzip, 6 pkgs, 7 enableStatic ? stdenv.hostPlatform.isStatic, 8 enableShared ? !stdenv.hostPlatform.isStatic, 9}: 10let 11 12 choosePlatform = 13 let 14 pname = stdenv.hostPlatform.parsed.cpu.name; 15 in 16 pset: pset.${pname} or (throw "bionic-prebuilt: unsupported platform ${pname}"); 17 18 prebuilt_crt = choosePlatform { 19 aarch64 = fetchzip { 20 url = "https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/+archive/98dce673ad97a9640c5d90bbb1c718e75c21e071/lib/gcc/aarch64-linux-android/4.9.x.tar.gz"; 21 sha256 = "sha256-LLD2OJi78sNN5NulOsJZl7Ei4F1EUYItGG6eUsKWULc="; 22 stripRoot = false; 23 }; 24 x86_64 = fetchzip { 25 url = "https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/+archive/7e8507d2a2d4df3bced561b894576de70f065be4/lib/gcc/x86_64-linux-android/4.9.x.tar.gz"; 26 sha256 = "sha256-y7CFLF76pTlj+oYev9taBnL2nlT3+Tx8c6wmicWmKEw="; 27 stripRoot = false; 28 }; 29 }; 30 31 prebuilt_libs = choosePlatform { 32 aarch64 = fetchzip { 33 url = "https://android.googlesource.com/platform/prebuilts/ndk/+archive/f2c77d8ba8a7f5c2d91771e31164f29be0b8ff98/platform/platforms/android-30/arch-arm64/usr/lib.tar.gz"; 34 sha256 = "sha256-TZBV7+D1QvKOCEi+VNGT5SStkgj0xRbyWoLH65zSrjw="; 35 stripRoot = false; 36 }; 37 x86_64 = fetchzip { 38 url = "https://android.googlesource.com/platform/prebuilts/ndk/+archive/f2c77d8ba8a7f5c2d91771e31164f29be0b8ff98/platform/platforms/android-30/arch-x86_64/usr/lib64.tar.gz"; 39 sha256 = "sha256-n2EuOKy3RGKmEYofNlm+vDDBuiQRuAJEJT6wq6NEJQs="; 40 stripRoot = false; 41 }; 42 }; 43 44 prebuilt_ndk_crt = choosePlatform { 45 aarch64 = fetchzip { 46 url = "https://android.googlesource.com/toolchain/prebuilts/ndk/r23/+archive/6c5fa4c0d3999b9ee932f6acbd430eb2f31f3151/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/30.tar.gz"; 47 sha256 = "sha256-KHw+cCwAwlm+5Nwp1o8WONqdi4BBDhFaVVr+7GxQ5uE="; 48 stripRoot = false; 49 }; 50 x86_64 = fetchzip { 51 url = "https://android.googlesource.com/toolchain/prebuilts/ndk/r23/+archive/6c5fa4c0d3999b9ee932f6acbd430eb2f31f3151/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/30.tar.gz"; 52 sha256 = "sha256-XEd7L3cBzn+1pKfji40V92G/uZhHSMMuZcRZaiKkLnk="; 53 stripRoot = false; 54 }; 55 }; 56 57 ndk_support_headers = fetchzip { 58 url = "https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/0e7f808fa26cce046f444c9616d9167dafbfb272/clang-r416183b/include/c++/v1/support.tar.gz"; 59 sha256 = "sha256-NBv7Pk1CEaz8ns9moleEERr3x/rFmVmG33LgFSeO6fY="; 60 stripRoot = false; 61 }; 62 63 kernelHeaders = pkgs.makeLinuxHeaders { 64 version = "android-common-11-5.4"; 65 src = fetchzip { 66 url = "https://android.googlesource.com/kernel/common/+archive/48ffcbf0b9e7f0280bfb8c32c68da0aaf0fdfef6.tar.gz"; 67 sha256 = "1y7cmlmcr5vdqydd9n785s139yc4aylc3zhqa59xsylmkaf5habk"; 68 stripRoot = false; 69 }; 70 }; 71 72in 73stdenvNoCC.mkDerivation rec { 74 pname = "bionic-prebuilt"; 75 version = "ndk-release-r23"; 76 name = "${stdenv.hostPlatform.parsed.cpu.name}-${pname}-${version}"; 77 78 src = fetchzip { 79 url = "https://android.googlesource.com/platform/bionic/+archive/00e8ce1142d8823b0d2fc8a98b40119b0f1f02cd.tar.gz"; 80 sha256 = "10z5mp4w0acvjvgxv7wlqa7m70hcyarmjdlfxbd9rwzf4mrsr8d1"; 81 stripRoot = false; 82 }; 83 84 NIX_DONT_SET_RPATH = true; 85 86 dontConfigure = true; 87 dontBuild = true; 88 89 patches = [ 90 ./ndk-version.patch 91 ]; 92 93 postPatch = '' 94 substituteInPlace libc/include/sys/cdefs.h --replace \ 95 "__has_builtin(__builtin_umul_overflow)" "1" 96 substituteInPlace libc/include/bits/ioctl.h --replace \ 97 "!defined(BIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD)" "0" 98 ''; 99 100 installPhase = 101 '' 102 # copy the bionic headers 103 mkdir -p $out/include/support $out/include/android 104 cp -vr libc/include/* $out/include 105 # copy the kernel headers 106 cp -vr ${kernelHeaders}/include/* $out/include/ 107 108 chmod -R +w $out/include/linux 109 110 # fix a bunch of kernel headers so that things can actually be found 111 sed -i 's,struct epoll_event {,#include <bits/epoll_event.h>\nstruct Xepoll_event {,' $out/include/linux/eventpoll.h 112 sed -i 's,struct in_addr {,typedef unsigned int in_addr_t;\nstruct in_addr {,' $out/include/linux/in.h 113 sed -i 's,struct udphdr {,struct Xudphdr {,' $out/include/linux/udp.h 114 sed -i 's,union semun {,union Xsemun {,' $out/include/linux/sem.h 115 sed -i 's,struct __kernel_sockaddr_storage,#define sockaddr_storage __kernel_sockaddr_storage\nstruct __kernel_sockaddr_storage,' $out/include/linux/socket.h 116 sed -i 's,#ifndef __UAPI_DEF_.*$,#if 1,' $out/include/linux/libc-compat.h 117 substituteInPlace $out/include/linux/in.h --replace "__be32 imr_" "struct in_addr imr_" 118 substituteInPlace $out/include/linux/in.h --replace "__be32 imsf_" "struct in_addr imsf_" 119 substituteInPlace $out/include/linux/sysctl.h --replace "__unused" "_unused" 120 121 # what could possibly live in <linux/compiler.h> 122 touch $out/include/linux/compiler.h 123 124 # copy the support headers 125 cp -vr ${ndk_support_headers}* $out/include/support/ 126 127 mkdir $out/lib 128 cp -v ${prebuilt_crt.out}/*.o $out/lib/ 129 cp -v ${prebuilt_crt.out}/libgcc.a $out/lib/ 130 cp -v ${prebuilt_ndk_crt.out}/*.o $out/lib/ 131 '' 132 + lib.optionalString enableShared '' 133 for i in libc.so libm.so libdl.so liblog.so; do 134 cp -v ${prebuilt_libs.out}/$i $out/lib/ 135 done 136 '' 137 + lib.optionalString enableStatic '' 138 # no liblog.a; while it's also part of the base libraries, 139 # it's only available as shared object in the prebuilts. 140 for i in libc.a libm.a libdl.a; do 141 cp -v ${prebuilt_ndk_crt.out}/$i $out/lib/ 142 done 143 '' 144 + '' 145 mkdir -p $dev/include 146 cp -v $out/include/*.h $dev/include/ 147 ''; 148 149 outputs = [ 150 "out" 151 "dev" 152 ]; 153 passthru.linuxHeaders = kernelHeaders; 154 155 meta = with lib; { 156 description = "Android libc implementation"; 157 homepage = "https://android.googlesource.com/platform/bionic/"; 158 license = licenses.mit; 159 platforms = platforms.linux; 160 maintainers = with maintainers; [ s1341 ]; 161 }; 162}