1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_android_toolchain: 2*61c4878aSAndroid Build Coastguard Worker 3*61c4878aSAndroid Build Coastguard Worker-------------------- 4*61c4878aSAndroid Build Coastguard Workerpw_android_toolchain 5*61c4878aSAndroid Build Coastguard Worker-------------------- 6*61c4878aSAndroid Build Coastguard Worker.. pigweed-module:: 7*61c4878aSAndroid Build Coastguard Worker :name: pw_android_toolchain 8*61c4878aSAndroid Build Coastguard Worker 9*61c4878aSAndroid Build Coastguard WorkerAndroid toolchains differ from ``pw_toolchain`` in that the latter defines the 10*61c4878aSAndroid Build Coastguard Workertool names and paths at the lowest level, with customisation added at higher 11*61c4878aSAndroid Build Coastguard Workerlevels, while in ``pw_android_toolchain`` the tool names and paths are derived 12*61c4878aSAndroid Build Coastguard Workerfrom build args and defaults so are defined last by calling 13*61c4878aSAndroid Build Coastguard Worker``pw_generate_android_toolchain``. 14*61c4878aSAndroid Build Coastguard Worker 15*61c4878aSAndroid Build Coastguard WorkerSetup 16*61c4878aSAndroid Build Coastguard Worker===== 17*61c4878aSAndroid Build Coastguard WorkerYou must first download and unpack a copy of the `Android NDK`_ and let Pigweed 18*61c4878aSAndroid Build Coastguard Workerknow where that is located using the ``pw_android_toolchain_NDK_PATH`` build 19*61c4878aSAndroid Build Coastguard Workerarg. 20*61c4878aSAndroid Build Coastguard Worker 21*61c4878aSAndroid Build Coastguard Worker.. _Android NDK: https://developer.android.com/ndk 22*61c4878aSAndroid Build Coastguard Worker 23*61c4878aSAndroid Build Coastguard WorkerYou can set Pigweed build options using ``gn args out``. 24*61c4878aSAndroid Build Coastguard Worker 25*61c4878aSAndroid Build Coastguard WorkerToolchains 26*61c4878aSAndroid Build Coastguard Worker========== 27*61c4878aSAndroid Build Coastguard Worker``pw_android_toolchain`` provides GN toolchains that may be used to build 28*61c4878aSAndroid Build Coastguard WorkerPigweed against an Android NDK. The following toolchains are defined: 29*61c4878aSAndroid Build Coastguard Worker 30*61c4878aSAndroid Build Coastguard Worker- arm_android_debug 31*61c4878aSAndroid Build Coastguard Worker- arm_android_size_optimized 32*61c4878aSAndroid Build Coastguard Worker- arm_android_speed_optimized 33*61c4878aSAndroid Build Coastguard Worker- arm64_android_debug 34*61c4878aSAndroid Build Coastguard Worker- arm64_android_size_optimized 35*61c4878aSAndroid Build Coastguard Worker- arm64_android_speed_optimized 36*61c4878aSAndroid Build Coastguard Worker- x64_android_debug 37*61c4878aSAndroid Build Coastguard Worker- x64_android_size_optimized 38*61c4878aSAndroid Build Coastguard Worker- x64_android_speed_optimized 39*61c4878aSAndroid Build Coastguard Worker- x86_android_debug 40*61c4878aSAndroid Build Coastguard Worker- x86_android_size_optimized 41*61c4878aSAndroid Build Coastguard Worker- x86_android_speed_optimized 42*61c4878aSAndroid Build Coastguard Worker 43*61c4878aSAndroid Build Coastguard Worker.. note:: 44*61c4878aSAndroid Build Coastguard Worker 45*61c4878aSAndroid Build Coastguard Worker The documentation for this module is currently incomplete. 46*61c4878aSAndroid Build Coastguard Worker 47*61c4878aSAndroid Build Coastguard WorkerDefining Toolchains 48*61c4878aSAndroid Build Coastguard Worker=================== 49*61c4878aSAndroid Build Coastguard WorkerDefining Android NDK toolchains is similar to ``pw_toolchain`` except that 50*61c4878aSAndroid Build Coastguard Workerinstead of using ``generate_toolchain`` use ``pw_generate_android_toolchain``, 51*61c4878aSAndroid Build Coastguard Workerand ensure that ``current_cpu`` is set in the toolchain ``defaults``. 52*61c4878aSAndroid Build Coastguard Worker 53*61c4878aSAndroid Build Coastguard WorkerFor example: 54*61c4878aSAndroid Build Coastguard Worker 55*61c4878aSAndroid Build Coastguard Worker.. code-block:: 56*61c4878aSAndroid Build Coastguard Worker 57*61c4878aSAndroid Build Coastguard Worker import("//build_overrides/pigweed.gni") 58*61c4878aSAndroid Build Coastguard Worker 59*61c4878aSAndroid Build Coastguard Worker import("$dir_pw_android_toolchain/toolchains.gni") 60*61c4878aSAndroid Build Coastguard Worker import("$dir_pw_android_toolchain/generate_toolchain.gni") 61*61c4878aSAndroid Build Coastguard Worker 62*61c4878aSAndroid Build Coastguard Worker my_target_scope = { 63*61c4878aSAndroid Build Coastguard Worker # Use Pigweed's Android toolchain as a base. 64*61c4878aSAndroid Build Coastguard Worker _toolchain_base = pw_toolchain_android.debug 65*61c4878aSAndroid Build Coastguard Worker 66*61c4878aSAndroid Build Coastguard Worker # Forward everything except the defaults scope from that toolchain. 67*61c4878aSAndroid Build Coastguard Worker forward_variables_from(_toolchain_base, "*", [ "defaults" ]) 68*61c4878aSAndroid Build Coastguard Worker 69*61c4878aSAndroid Build Coastguard Worker defaults = { 70*61c4878aSAndroid Build Coastguard Worker # Forward everything from the base toolchain's defaults. 71*61c4878aSAndroid Build Coastguard Worker forward_variables_from(_toolchain_base.defaults, "*") 72*61c4878aSAndroid Build Coastguard Worker 73*61c4878aSAndroid Build Coastguard Worker # Build for 64-bit AArch64 Android devices. 74*61c4878aSAndroid Build Coastguard Worker current_cpu = "arm64" 75*61c4878aSAndroid Build Coastguard Worker 76*61c4878aSAndroid Build Coastguard Worker # Extend with custom build arguments for the target. 77*61c4878aSAndroid Build Coastguard Worker pw_log_BACKEND = dir_pw_log_tokenized 78*61c4878aSAndroid Build Coastguard Worker } 79*61c4878aSAndroid Build Coastguard Worker } 80*61c4878aSAndroid Build Coastguard Worker 81*61c4878aSAndroid Build Coastguard Worker # Create the actual GN toolchain from the scope. 82*61c4878aSAndroid Build Coastguard Worker pw_generate_android_toolchain("my_target") { 83*61c4878aSAndroid Build Coastguard Worker forward_variables_from(my_target_scope, "*") 84*61c4878aSAndroid Build Coastguard Worker } 85*61c4878aSAndroid Build Coastguard Worker 86*61c4878aSAndroid Build Coastguard WorkerSince Android NDKs contain toolchains for all supported targets, as a 87*61c4878aSAndroid Build Coastguard Workerconvenience, ``pw_generate_android_toolchains`` does not require that 88*61c4878aSAndroid Build Coastguard Worker``current_cpu`` is set. If any toolchain scope in the list does not set it, a 89*61c4878aSAndroid Build Coastguard Workertoolchain for each supported target will be generated. 90*61c4878aSAndroid Build Coastguard Worker 91*61c4878aSAndroid Build Coastguard Worker.. code-block:: 92*61c4878aSAndroid Build Coastguard Worker 93*61c4878aSAndroid Build Coastguard Worker # Generate arm_*, arm64_*, x64_*, and x86_* for each scope in the list. 94*61c4878aSAndroid Build Coastguard Worker pw_generate_android_toolchains("target_toolchains) { 95*61c4878aSAndroid Build Coastguard Worker toolchains = pw_toolchain_android_list 96*61c4878aSAndroid Build Coastguard Worker } 97*61c4878aSAndroid Build Coastguard Worker 98*61c4878aSAndroid Build Coastguard WorkerCustomization 99*61c4878aSAndroid Build Coastguard Worker------------- 100*61c4878aSAndroid Build Coastguard WorkerThe Android SDK target version defaults to the value of the 101*61c4878aSAndroid Build Coastguard Worker``pw_android_toolchain_API_LEVEL`` build arg. You can override this on global 102*61c4878aSAndroid Build Coastguard Workerlevel, or on a per-toolchain level by setting ``api_level`` in the toolchain 103*61c4878aSAndroid Build Coastguard Workerdefaults. 104