README.md
1# The Bazel APEX ruleset
2
3**Example**
4
5```
6$ b build //path/to/module:com.android.module.apex --config=android
7```
8
9**Code locations**
10
11The main entry point is the `apex` macro in [//build/bazel/rules/apex/apex.bzl](https://cs.android.com/android/platform/superproject/+/master:build/bazel/rules/apex/apex.bzl?q=f:apex.bzl), which expands to the `_apex` rule implementation.
12
13Related files in this directory include:
14
15* `cc.bzl` for the C/C++ specific aspect that traverses into native dependencies
16* `toolchain.bzl` for the host toolchain
17* `transition.bzl` for the configuration transition to add APEX-specific configuration to dependencies, like the APEX name and min sdk version.
18* `apex_aab.bzl` to repackage APEXes into multi-architecture Android app bundles and APK sets.
19* `apex_info.bzl` contains ApexInfo and ApexMkInfo providers. These form the main interface of an APEX target.
20* `apex_key.bzl` for the `apex_key()` rule
21* `apex_test.bzl` for Starlark analysis tests
22
23The bp2build converter (`ConvertWithBp2build`) is located [here](https://cs.android.com/android/platform/superproject/+/master:build/soong/apex/apex.go;l=3469;drc=4d247e6f21004d3998bf32d46c22111a380b81af).
24
25The mixed build handler (`ProcessBazelQueryResponse`) is located [here](https://cs.android.com/android/platform/superproject/+/master:build/soong/apex/apex.go;l=1888;drc=4d247e6f21004d3998bf32d46c22111a380b81af).
26
27**Major features**
28
29* Build, compress, and sign APEX `ext4` images and containers for all architectures/bitness
30* Supports outputs: `.apex`, `.capex` (compressed apex), `.aab` (Android app bundle), `.apks` (APK set)
31* Supports packaging prebuilts (e.g. tzdata), native shared libs, native binaries, `sh_binary`
32* Works with `apex`, `override_apex` and `apex_test` Soong module types
33* Supports AOSP and Google/Go APEX variants
34* Supports standalone/unbundled APEX builds (fast for development) with `b` and full platform build with `m` (preloaded on system)
35* Supports generating Mainline quality signals metadata files: required/provided libs, `installed_files.txt`
36* Internal mainline build scripts is capable of building multi-arch AABs/APKs in a single Bazel invocation
37
38**Detailed features**
39
40* Bazel build settings/flags in `//build/bazel/rules/apex/BUILD`, like `unsafe_disable_apex_allowed_deps_check`
41* ABI stability for native deps
42 * ABI stable stubs are marked as required, and not included within the APEX
43 * non-ABI stable transitive deps are copied into the APEX
44* Supports testonly APEXes (converted from `apex_test`)
45* Supports default certificates with product config
46* Supports default `file_contexts`
47* Supports `allowed_deps.txt` validation
48* Supports `apex_available` validation
49* Supports `min_sdk_version` validation
50* Supports `logging_parent`, `package_name`, `android_manifest`, `key`.
51* Supports `apex_manifest.pb` conversion
52* Supports `canned_fs_config` generation
53* Supports `file_contexts` generation
54* Licensing: `NOTICE.html.gz` embedded in the APEX
55* All host tools are built from source by Bazel, or vendored prebuilts
56* All actions are fully sandboxed
57* Ability to build metadata files on the command line with `--output_groups=<coverage_files,backing_libs,...>`
58
59**Guardrails / others**
60
61* `--config=android` is needed to build for the device. All APEX targets set `target_compatible_with` to android only - no host APEXes.
62* Comprehensive set of rule analysis tests for in `apex_test.bzl`
63* Example APEX in `//build/bazel/examples/apex/...`
64* Unit and integration tests in `//build/bazel/{examples,tests,rules}/apex/...` and `//build/soong/tests/...`
65
66**Known issues / gap analysis (non-exhaustive)**
67
68Upcoming features are based on Roboleaf module conversion priorities, like Java, Rust, DCLA and API fingerprinting support.
69
70* `override_apex` modules are converted to a regular apex with duplicated attributes. These are hidden by bp2build currently and will be cleaned up with macros in the future.
71* Correct product platform transitions for `apex_aab` to `mainline_modules_*` products
72* Java support
73* Rust support
74