mirror of https://github.com/grpc/grpc.git
[Build] Migrate Android NDK, android rules and platforms (#36116)
This commit does the following 3 things for Android bazel rules, which depends on each other 1. Update NDK to 26.2.11394342 (and a few other Android things) 2. Use rules_android_ndk instead of builtin `native.android_ndk_repository` * `third_party/android/android_configure.bzl` was a workaround for users who don't set `$ANDROID_NDK_HOME` env var. Now with rules_android_ndk, we can declare repo without registering the toolchain. Instead users who need NDK toolchain should use `--extra_toolchains` to manually register the toolchain, as shown in README.md. 3. Migrate to platforms. See https://bazel.build/concepts/platforms * Currently we declares android platforms that is needed for binder transport APK. Later gRPC repo can gradually migrate to platforms for other platforms. * The value of `crosstool_top` will still be `//external:android/crosstool` (which is the default value), so existings android `config_settings` will still work. We should migrate them to match with `@platforms//os:android` constraint later. The platforms migration needs Bazel 7.0 to work so we also override bazel version in testing scripts. Closes #36116 PiperOrigin-RevId: 617244655pull/36152/head
parent
bb9f4466e1
commit
d6bb391449
13 changed files with 108 additions and 123 deletions
@ -1,3 +0,0 @@ |
|||||||
exports_files([ |
|
||||||
"android_configure.bzl", |
|
||||||
]) |
|
@ -1,62 +0,0 @@ |
|||||||
"""Repository rule for Android SDK and NDK autoconfiguration. |
|
||||||
|
|
||||||
This rule is a no-op unless the required android environment variables are set. |
|
||||||
""" |
|
||||||
|
|
||||||
# Based on https://github.com/tensorflow/tensorflow/tree/34c03ed67692eb76cb3399cebca50ea8bcde064c/third_party/android |
|
||||||
# Workaround for https://github.com/bazelbuild/bazel/issues/14260 |
|
||||||
|
|
||||||
_ANDROID_NDK_HOME = "ANDROID_NDK_HOME" |
|
||||||
_ANDROID_SDK_HOME = "ANDROID_HOME" |
|
||||||
|
|
||||||
def _escape_for_windows(path): |
|
||||||
"""Properly escape backslashes for Windows. |
|
||||||
|
|
||||||
Ideally, we would do this conditionally, but there is seemingly no way to |
|
||||||
determine whether or not this is being called from Windows. |
|
||||||
""" |
|
||||||
return path.replace("\\", "\\\\") |
|
||||||
|
|
||||||
def _android_autoconf_impl(repository_ctx): |
|
||||||
sdk_home = repository_ctx.os.environ.get(_ANDROID_SDK_HOME) |
|
||||||
ndk_home = repository_ctx.os.environ.get(_ANDROID_NDK_HOME) |
|
||||||
|
|
||||||
# version 31.0.0 won't work https://stackoverflow.com/a/68036845 |
|
||||||
sdk_rule = "" |
|
||||||
if sdk_home: |
|
||||||
sdk_rule = """ |
|
||||||
native.android_sdk_repository( |
|
||||||
name="androidsdk", |
|
||||||
path="{}", |
|
||||||
build_tools_version="30.0.3", |
|
||||||
) |
|
||||||
""".format(_escape_for_windows(sdk_home)) |
|
||||||
|
|
||||||
# Note that Bazel does not support NDK 22 yet, and Bazel 3.7.1 only |
|
||||||
# supports up to API level 29 for NDK 21 |
|
||||||
ndk_rule = "" |
|
||||||
if ndk_home: |
|
||||||
ndk_rule = """ |
|
||||||
native.android_ndk_repository( |
|
||||||
name="androidndk", |
|
||||||
path="{}", |
|
||||||
) |
|
||||||
""".format(_escape_for_windows(ndk_home)) |
|
||||||
|
|
||||||
if ndk_rule == "" and sdk_rule == "": |
|
||||||
sdk_rule = "pass" |
|
||||||
|
|
||||||
repository_ctx.file("BUILD.bazel", "") |
|
||||||
repository_ctx.file("android_configure.bzl", """ |
|
||||||
def android_workspace(): |
|
||||||
{} |
|
||||||
{} |
|
||||||
""".format(sdk_rule, ndk_rule)) |
|
||||||
|
|
||||||
android_configure = repository_rule( |
|
||||||
implementation = _android_autoconf_impl, |
|
||||||
environ = [ |
|
||||||
_ANDROID_NDK_HOME, |
|
||||||
_ANDROID_SDK_HOME, |
|
||||||
], |
|
||||||
) |
|
@ -1 +1 @@ |
|||||||
us-docker.pkg.dev/grpc-testing/testing-images-public/binder_transport_apk:fbe8a32dd2006fab456f2fa0d0e82d3979b7f30b@sha256:a680a8b7d645a2c25948ad3f82f6380c8a1e13fcfe74fc3569acb3b0b202851e |
us-docker.pkg.dev/grpc-testing/testing-images-public/binder_transport_apk:611a0d410d3032bc41175599a5f1495a07759c1f@sha256:ff64e263dfa5491ee6fddd7f0d7c1a20ba756636655849a3b923c665d78c8ef2 |
||||||
|
Loading…
Reference in new issue