-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bazel: Add androidndk fetching workaround
This works around https://github.com/bazelbuild/bazel/issues/14260 This is based on tensorflow's implementation https://github.com/tensorflow/tensorflow/tree/34c03ed67692eb76cb3399cebca50ea8bcde064c/third_party/android Signed-off-by: Keith Smiley <[email protected]>
- Loading branch information
Showing
2 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""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 _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) | ||
|
||
sdk_rule = "" | ||
if sdk_home: | ||
sdk_rule = """ | ||
native.android_sdk_repository( | ||
name="androidsdk", | ||
path="{}", | ||
api_level=30, | ||
build_tools_version="30.0.2", | ||
) | ||
""".format(sdk_home) | ||
|
||
ndk_rule = "" | ||
if ndk_home: | ||
ndk_rule = """ | ||
native.android_ndk_repository( | ||
name="androidndk", | ||
path="{}", | ||
api_level=21, | ||
) | ||
""".format(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, | ||
], | ||
) |