···493 echo "-arch ${targetPlatform.darwinArch}" >> $out/nix-support/cc-cflags
494 ''
4950000496 # There are a few tools (to name one libstdcxx5) which do not work
497 # well with multi line flags, so make the flags single line again
498 + ''
···493 echo "-arch ${targetPlatform.darwinArch}" >> $out/nix-support/cc-cflags
494 ''
495496+ + optionalString targetPlatform.isAndroid ''
497+ echo "-D__ANDROID_API__=${targetPlatform.sdkVer}" >> $out/nix-support/cc-cflags
498+ ''
499+500 # There are a few tools (to name one libstdcxx5) which do not work
501 # well with multi line flags, so make the flags single line again
502 + ''
···1+--- a/libc/include/android/ndk-version.h 2021-04-01 16:08:03.109183965 +0300
2++++ b/libc/include/android/ndk-version.h 2021-04-01 16:07:19.811424641 +0300
3+@@ -0,0 +1,39 @@
4++#pragma once
5++
6++/**
7++ * Set to 1 if this is an NDK, unset otherwise. See
8++ * https://android.googlesource.com/platform/bionic/+/master/docs/defines.md.
9++ */
10++#define __ANDROID_NDK__ 1
11++
12++/**
13++ * Major version of this NDK.
14++ *
15++ * For example: 16 for r16.
16++ */
17++#define __NDK_MAJOR__ 22
18++
19++/**
20++ * Minor version of this NDK.
21++ *
22++ * For example: 0 for r16 and 1 for r16b.
23++ */
24++#define __NDK_MINOR__ 0
25++
26++/**
27++ * Set to 0 if this is a release build, or 1 for beta 1,
28++ * 2 for beta 2, and so on.
29++ */
30++#define __NDK_BETA__ 0
31++
32++/**
33++ * Build number for this NDK.
34++ *
35++ * For a local development build of the NDK, this is -1.
36++ */
37++#define __NDK_BUILD__ 7026061
38++
39++/**
40++ * Set to 1 if this is a canary build, 0 if not.
41++ */
42++#define __NDK_CANARY__ 0
+18-4
pkgs/os-specific/linux/kernel-headers/default.nix
···1-{ stdenvNoCC, lib, buildPackages, fetchurl, perl, elf-header }:
0000023let
4 makeLinuxHeaders = { src, version, patches ? [] }: stdenvNoCC.mkDerivation {
···13 # We do this so we have a build->build, not build->host, C compiler.
14 depsBuildBuild = [ buildPackages.stdenv.cc ];
15 # `elf-header` is null when libc provides `elf.h`.
16- nativeBuildInputs = [ perl elf-header ];
00001718 extraIncludeDirs = lib.optional stdenvNoCC.hostPlatform.isPowerPC ["ppc"];
1920 inherit patches;
2122 hardeningDisable = lib.optional stdenvNoCC.buildPlatform.isDarwin "format";
002324 makeFlags = [
25 "SHELL=bash"
···36 # Skip clean on darwin, case-sensitivity issues.
37 buildPhase = lib.optionalString (!stdenvNoCC.buildPlatform.isDarwin) ''
38 make mrproper $makeFlags
39- '' + ''
00040 make headers $makeFlags
41- '';
4243 checkPhase = ''
44 make headers_check $makeFlags
···1+{ stdenvNoCC, lib, buildPackages, fetchurl, perl, elf-header
2+, bison ? null, flex ? null, python ? null, rsync ? null
3+}:
4+5+assert stdenvNoCC.hostPlatform.isAndroid ->
6+ (flex != null && bison != null && python != null && rsync != null);
78let
9 makeLinuxHeaders = { src, version, patches ? [] }: stdenvNoCC.mkDerivation {
···18 # We do this so we have a build->build, not build->host, C compiler.
19 depsBuildBuild = [ buildPackages.stdenv.cc ];
20 # `elf-header` is null when libc provides `elf.h`.
21+ nativeBuildInputs = [
22+ perl elf-header
23+ ] ++ lib.optionals stdenvNoCC.hostPlatform.isAndroid [
24+ flex bison python rsync
25+ ];
2627 extraIncludeDirs = lib.optional stdenvNoCC.hostPlatform.isPowerPC ["ppc"];
2829 inherit patches;
3031 hardeningDisable = lib.optional stdenvNoCC.buildPlatform.isDarwin "format";
32+33+ sourceRoot = lib.optionalString stdenvNoCC.hostPlatform.isAndroid ".";
3435 makeFlags = [
36 "SHELL=bash"
···47 # Skip clean on darwin, case-sensitivity issues.
48 buildPhase = lib.optionalString (!stdenvNoCC.buildPlatform.isDarwin) ''
49 make mrproper $makeFlags
50+ '' + (if stdenvNoCC.hostPlatform.isAndroid then ''
51+ make defconfig
52+ make headers_install
53+ '' else ''
54 make headers $makeFlags
55+ '');
5657 checkPhase = ''
58 make headers_check $makeFlags
+7-3
pkgs/top-level/all-packages.nix
···11176 llvmPackages_7
11177 else if isFreeBSD then
11178 llvmPackages_7
0011179 else if isLinux then
11180 llvmPackages_7
11181 else if isWasm then
···14046 bicgl = callPackage ../development/libraries/science/biology/bicgl { };
1404714048 # TODO(@Ericson2314): Build bionic libc from source
14049- bionic = assert stdenv.hostPlatform.useAndroidPrebuilt;
14050- pkgs."androidndkPkgs_${stdenv.hostPlatform.ndkVer}".libraries;
001405114052 bobcat = callPackage ../development/libraries/bobcat { };
14053···20049 lkl = callPackage ../applications/virtualization/lkl { };
2005020051 inherit (callPackages ../os-specific/linux/kernel-headers { })
20052- linuxHeaders;
2005320054 kernelPatches = callPackage ../os-specific/linux/kernel/patches.nix { };
20055
···11176 llvmPackages_7
11177 else if isFreeBSD then
11178 llvmPackages_7
11179+ else if isAndroid then
11180+ llvmPackages_12
11181 else if isLinux then
11182 llvmPackages_7
11183 else if isWasm then
···14048 bicgl = callPackage ../development/libraries/science/biology/bicgl { };
1404914050 # TODO(@Ericson2314): Build bionic libc from source
14051+ bionic = if stdenv.hostPlatform.useAndroidPrebuilt
14052+ then pkgs."androidndkPkgs_${stdenv.hostPlatform.ndkVer}".libraries
14053+ else callPackage ../os-specific/linux/bionic-prebuilt { };
14054+1405514056 bobcat = callPackage ../development/libraries/bobcat { };
14057···20053 lkl = callPackage ../applications/virtualization/lkl { };
2005420055 inherit (callPackages ../os-specific/linux/kernel-headers { })
20056+ linuxHeaders makeLinuxHeaders;
2005720058 kernelPatches = callPackage ../os-specific/linux/kernel/patches.nix { };
20059