diff options
author | Yifan Hong <elsk@google.com> | 2023-02-13 23:57:34 -0800 |
---|---|---|
committer | Yifan Hong <elsk@google.com> | 2023-03-02 23:19:00 -0800 |
commit | faeeed0ddc0eb19e205f7cae0f3b041056a4c40b (patch) | |
tree | 7a453cbf35aa2b1db0995053b2f61e83eee3a3d6 /kleaf/clang_config.bzl | |
parent | 8c227ab59b49addcc9aef943948bff976c4cbf04 (diff) | |
download | linux-x86-faeeed0ddc0eb19e205f7cae0f3b041056a4c40b.tar.gz |
kleaf: hermetic cc toolchain for android binaries.
Add support for cross-compiling Android libraries
and binaries.
cc_binary / cc_library are built with the target platform.
By default, the target platform is not set to Android. The target
platform may be set to Android using --config=android_arm64,
--config=android_x86_64, or --config=android_riscv64.
When one of these --config=android_* are set, --config=hermetic_cc
is implied so that only the hermetic CC toolchain is used. Host
CC toolchain is not considered.
One may use target_compatible_with to restrict whether a cc_binary
or cc_library works with the host or the device.
Test: bazel build //build/kernel/kleaf/tests/cc_testing:android_tests --config=android_arm64
Test: bazel build //build/kernel/kleaf/tests/cc_testing:android_tests --config=android_x86_64
Test: bazel build //build/kernel/kleaf/tests/cc_testing:android_tests --config=android_riscv64
Note: riscv64 does not work yet due to the lack of NDK_TRIPLE. This
will be fixed in follow up CLs.
Bug: 228238975
Include-Buildifier-Warnings: enabled
Change-Id: If15614ec5ffb21799f23315c586b62bf33d1fc7f
Diffstat (limited to 'kleaf/clang_config.bzl')
-rw-r--r-- | kleaf/clang_config.bzl | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/kleaf/clang_config.bzl b/kleaf/clang_config.bzl index 8457dcf18..b5a393296 100644 --- a/kleaf/clang_config.bzl +++ b/kleaf/clang_config.bzl @@ -14,12 +14,15 @@ """Configure CC toolchain for Android kernel.""" +load(":android.bzl", "android") load(":common.bzl", "common") load(":linux.bzl", "linux") def _impl(ctx): if ctx.attr.target_os == "linux": features = linux.features(ctx) + elif ctx.attr.target_os == "android": + features = android.features(ctx) else: fail("target_os == {} is not supported yet".format(ctx.attr.target_os)) @@ -47,12 +50,16 @@ clang_config = rule( implementation = _impl, attrs = { "target_cpu": attr.string(mandatory = True, values = [ + "arm64", + "riscv64", "x86_64", ]), "target_os": attr.string(mandatory = True, values = [ + "android", "linux", ]), "sysroot": attr.string(mandatory = True), + "ndk_triple": attr.string(), "toolchain_identifier": attr.string(), "clang_version": attr.string(), }, |