blob: 2bd7e08e1500c98c6e1fece5394516377612ee5e [file] [log] [blame] [view]
Dan Albertab5740b2016-11-03 16:02:16 -07001Unified Headers
2===============
3
4[Issue #120](https://github.com/android-ndk/ndk/issues/120)
5
6Currently, we have a set of libc headers for each API version. In many cases
7these headers are incorrect. Many expose APIs that didn't exist, and others
8don't expose APIs that did.
9
10Over the last few months we've done unified these into a single set of headers.
11This single header path will be used for *every* platform level. API level
12guards are handled with `#ifdef`. These headers can be found in
13[prebuilts/ndk/headers].
14
15Unified headers are built directly from the Android platform, so they will no
16longer be out of date or incorrect (or at the very least, any bugs in the NDK
17headers will also be a bug in the platform headers, which means we're much more
18likely to find them).
19
20[prebuilts/ndk/headers]: https://android.googlesource.com/platform/prebuilts/ndk/+/master/headers/
21
22
23Known Issues
24------------
25
Dan Albertab5740b2016-11-03 16:02:16 -070026 * Standalone toolchains using GCC are not supported out of the box. To use GCC,
27 pass `-D__ANDROID_API__=$API` when compiling.
28
Dan Albertab5740b2016-11-03 16:02:16 -070029
30Using Unified Headers
31---------------------
32
33Enabling unified headers will depend on your build system.
34
35### ndk-build
36
37Add the following to your Android.mk:
38
39```makefile
40APP_UNIFIED_HEADERS := true
41```
42
43### CMake
44
Dan Albertab5740b2016-11-03 16:02:16 -070045```bash
46cmake -DANDROID_UNIFIED_HEADERS=ON ...
47```
48
49### Standalone Toolchains
50
51```bash
52$NDK/build/tools/make_standalone_toolchain.py --unified-headers ...
53```
54
55### Gradle
56
57TBD
58
59
60Supporting Unified Headers in Your Build System
61-----------------------------------------------
62
63App developers can stop reading here. The following information is only
64relevant to build system engineers.
65
66Unified headers require only a few changes compared to using the legacy NDK
67headers. For reference, this patch added support to ndk-build:
68https://android-review.googlesource.com/c/239934/
69
701. The compile time sysroot is now `$NDK/sysroot`. Previously this was
71 `$NDK/platforms/android-$API/arch-$ARCH`.
72
732. Pass `-isystem $NDK/sysroot/usr/include/$TRIPLE` when compiling. The triple
74 has the following mapping:
75
76 Arch | Triple
77 --------|-------------------------
78 ARM | `arm-linux-androideabi`
79 ARM64 | `aarch64-linux-android`
80 MIPS | `mipsel-linux-android`
81 MIPS64 | `mips64el-linux-android`
82 x86 | `i386-linux-android`
83 x86\_64 | `x86_64-linux-android`
84
85 This is needed for architecture specific headers such as those in `asm/` and
86 `machine/`. We plan to teach Clang's driver to automatically search the
87 architecture specific include directory, but that has yet to be done.
88
893. Pass `-D__ANDROID_API__=$API` when compiling. This define used to be provided
90 by `<android/api-level.h>`, but with only one set of headers this is no
91 longer possible. In the future we will look in to adding `-mandroid-version`
92 or similar to Clang so this is automatic.
93
944. At link time, change nothing. All link time build behavior should match the
95 legacy headers behavior. `--sysroot` should still point to
96 `$NDK/platforms/android-$API/arch-$ARCH/`.