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