From 151b91932cb04aabc839df9565e7f54f7f712517 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Fri, 27 Feb 2026 17:38:40 -0800 Subject: [PATCH 1/6] Add cross-platform NDK repository support --- BUILD | 8 +- BUILD.ndk_clang.tpl | 3 +- BUILD.ndk_root.tpl | 1 + README.md | 6 +- examples/basic/WORKSPACE | 4 +- examples/cpu_features/WORKSPACE | 4 +- extension.bzl | 19 +++-- rules.bzl | 142 ++++++++++++++++++++++++++------ 8 files changed, 145 insertions(+), 42 deletions(-) diff --git a/BUILD b/BUILD index a871abe..cdba95f 100644 --- a/BUILD +++ b/BUILD @@ -1 +1,7 @@ -# Do not remove, this empty BUILD file is necessary for _android_ndk_repository_impl in rules.bzl. +# Note that this BUILD file is necessary for `android_ndk_repository` in `rules.bzl`. + +exports_files([ + "LICENSE", +] + glob([ + "*.tpl", +])) diff --git a/BUILD.ndk_clang.tpl b/BUILD.ndk_clang.tpl index 9fa3cab..5c7cdf6 100644 --- a/BUILD.ndk_clang.tpl +++ b/BUILD.ndk_clang.tpl @@ -1,5 +1,6 @@ """Declarations for the NDK's Clang directory.""" +load("@rules_cc//cc/toolchains:cc_toolchain_suite.bzl", "cc_toolchain_suite") load("@rules_cc//cc/toolchains:cc_toolchain.bzl", "cc_toolchain") load("@@{repository_name}//:ndk_cc_toolchain_config.bzl", "ndk_cc_toolchain_config_rule") load("//:target_systems.bzl", "TARGET_SYSTEM_NAMES") @@ -52,7 +53,7 @@ filegroup( "lib64/**/*", "lib/**/*", ], - # Need to allow_empty here because previous NDK versions had + # Need to allow_empty here because previous NDK versions had # "lib" & "lib64" directories but recent ones only have "lib". allow_empty = True, ), diff --git a/BUILD.ndk_root.tpl b/BUILD.ndk_root.tpl index f944cb1..3e9370a 100644 --- a/BUILD.ndk_root.tpl +++ b/BUILD.ndk_root.tpl @@ -19,6 +19,7 @@ alias( "@platforms//os:android", CPU_CONSTRAINT[target_system_name], ], + exec_compatible_with = {exec_compatible_with}, toolchain = "//{clang_directory}:cc_toolchain_%s" % target_system_name, toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", ) for target_system_name in TARGET_SYSTEM_NAMES] diff --git a/README.md b/README.md index fe80903..c63886c 100644 --- a/README.md +++ b/README.md @@ -102,15 +102,15 @@ http_archive( urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.17/rules_cc-0.0.17.tar.gz"], ) -load("@rules_android_ndk//:rules.bzl", "android_ndk_repository") +load("@rules_android_ndk//:rules.bzl", "local_android_ndk_repository") -android_ndk_repository(name = "androidndk") +local_android_ndk_repository(name = "androidndk") register_toolchains("@androidndk//:all") ``` Then, set the `ANDROID_NDK_HOME` environment variable or the `path` attribute of -`android_ndk_repository` to the path of the local Android NDK installation +`local_android_ndk_repository` to the path of the local Android NDK installation directory. If the path starts with `$WORKSPACE_ROOT`, then this string is replaced with the root path of the Bazel workspace. diff --git a/examples/basic/WORKSPACE b/examples/basic/WORKSPACE index d263611..18644a1 100644 --- a/examples/basic/WORKSPACE +++ b/examples/basic/WORKSPACE @@ -72,8 +72,8 @@ http_archive( ) # --SNIP--: Everything below this lines goes into the example WORKSPACE snippet in the release notes. -load("@rules_android_ndk//:rules.bzl", "android_ndk_repository") +load("@rules_android_ndk//:rules.bzl", "local_android_ndk_repository") -android_ndk_repository(name = "androidndk") +local_android_ndk_repository(name = "androidndk") register_toolchains("@androidndk//:all") diff --git a/examples/cpu_features/WORKSPACE b/examples/cpu_features/WORKSPACE index df78f7c..46b0e48 100644 --- a/examples/cpu_features/WORKSPACE +++ b/examples/cpu_features/WORKSPACE @@ -74,8 +74,8 @@ http_archive( ) # --SNIP--: Everything below this lines goes into the example WORKSPACE snippet in the release notes. -load("@rules_android_ndk//:rules.bzl", "android_ndk_repository") +load("@rules_android_ndk//:rules.bzl", "local_android_ndk_repository") -android_ndk_repository(name = "androidndk") +local_android_ndk_repository(name = "androidndk") register_toolchains("@androidndk//:all") diff --git a/extension.bzl b/extension.bzl index 22c8076..c3035d1 100644 --- a/extension.bzl +++ b/extension.bzl @@ -14,7 +14,7 @@ """A bzlmod extension for loading the NDK.""" -load(":rules.bzl", "android_ndk_repository") +load(":rules.bzl", "DEFAULT_API_LEVEL", "local_android_ndk_repository") def _android_ndk_repository_extension_impl(module_ctx): root_modules = [m for m in module_ctx.modules if m.is_root and m.tags.configure] @@ -31,17 +31,24 @@ def _android_ndk_repository_extension_impl(module_ctx): kwargs["api_level"] = module.tags.configure[0].api_level kwargs["path"] = module.tags.configure[0].path - android_ndk_repository( + local_android_ndk_repository( name = "androidndk", **kwargs ) +_CONFIGURE_TAG_CLASS = tag_class(attrs = { + "api_level": attr.int( + doc = "The minimum Android API level to target.", + default = DEFAULT_API_LEVEL, + ), + "path": attr.string( + doc = "The path to the local Android NDK installation. If not set, ANDROID_NDK_HOME environment variable is used.", + ), +}) + android_ndk_repository_extension = module_extension( implementation = _android_ndk_repository_extension_impl, tag_classes = { - "configure": tag_class(attrs = { - "path": attr.string(), - "api_level": attr.int(), - }), + "configure": _CONFIGURE_TAG_CLASS, }, ) diff --git a/rules.bzl b/rules.bzl index 53b9f7c..5813e22 100644 --- a/rules.bzl +++ b/rules.bzl @@ -14,30 +14,70 @@ """A repository rule for integrating the Android NDK.""" -def _android_ndk_repository_impl(ctx): +DEFAULT_API_LEVEL = 31 + +_EXEC_CONSTRAINTS = { + "darwin-arm64": [ + "@platforms//os:macos", + "@platforms//cpu:aarch64", + ], + "darwin-x86_64": [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], + "linux-x86_64": [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], + "windows-x86_64": [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], +} + +def _get_clang_resource_dir(ctx, clang_directory, is_windows): + clang_resource_dir = getattr(ctx.attr, "clang_resource_dir", None) + if clang_resource_dir: + return clang_resource_dir + + result = ctx.execute([clang_directory + "/bin/clang", "--print-resource-dir"]) + if result.return_code != 0: + fail("Failed to execute clang: %s" % result.stderr) + stdout = result.stdout.strip() + if is_windows: + stdout = stdout.replace("\\", "/") + return stdout.split(clang_directory)[1].strip("/") + +def _android_ndk_repository_impl(ctx, ndk_path = None): """Install the Android NDK files. Args: ctx: An implementation context. + ndk_path: The path to the ndk Returns: A final dict of configuration attributes and values. """ - ndk_path = ctx.attr.path or ctx.getenv("ANDROID_NDK_HOME", None) - if not ndk_path: - fail("Either the ANDROID_NDK_HOME environment variable or the " + - "path attribute of android_ndk_repository must be set.") + if ndk_path == None: + ndk_path = ctx.path(Label(ctx.attr.anchor)).dirname + if ndk_path.startswith("$WORKSPACE_ROOT"): ndk_path = str(ctx.workspace_root) + ndk_path.removeprefix("$WORKSPACE_ROOT") is_windows = False executable_extension = "" - if ctx.os.name == "linux": + exec_compatible_with = None + platform = ctx.os.name + if hasattr(ctx.attr, "platform"): + platform = ctx.attr.platform + exec_compatible_with = _EXEC_CONSTRAINTS[platform] + + if platform.startswith("linux"): clang_directory = "toolchains/llvm/prebuilt/linux-x86_64" - elif ctx.os.name == "mac os x": + elif platform.startswith(("mac", "darwin")): # Note: darwin-x86_64 does indeed contain fat binaries with arm64 slices, too. clang_directory = "toolchains/llvm/prebuilt/darwin-x86_64" - elif ctx.os.name.startswith("windows"): + elif platform.startswith("windows"): clang_directory = "toolchains/llvm/prebuilt/windows-x86_64" is_windows = True executable_extension = ".exe" @@ -48,15 +88,9 @@ def _android_ndk_repository_impl(ctx): _create_symlinks(ctx, ndk_path, clang_directory, sysroot_directory) - api_level = ctx.attr.api_level or 31 + api_level = ctx.attr.api_level or DEFAULT_API_LEVEL - result = ctx.execute([clang_directory + "/bin/clang", "--print-resource-dir"]) - if result.return_code != 0: - fail("Failed to execute clang: %s" % result.stderr) - stdout = result.stdout.strip() - if is_windows: - stdout = stdout.replace("\\", "/") - clang_resource_directory = stdout.split(clang_directory)[1].strip("/") + clang_resource_directory = _get_clang_resource_dir(ctx, clang_directory, is_windows) # Use a label relative to the workspace from which this repository rule came # to get the workspace name. @@ -67,6 +101,7 @@ def _android_ndk_repository_impl(ctx): ctx.attr._template_ndk_root, { "{clang_directory}": clang_directory, + "{exec_compatible_with}": repr(exec_compatible_with), }, executable = False, ) @@ -83,11 +118,11 @@ def _android_ndk_repository_impl(ctx): "%s/BUILD.bazel" % clang_directory, ctx.attr._template_ndk_clang, { - "{repository_name}": repository_name, "{api_level}": str(api_level), "{clang_resource_directory}": clang_resource_directory, - "{sysroot_directory}": sysroot_directory, "{executable_extension}": executable_extension, + "{repository_name}": repository_name, + "{sysroot_directory}": sysroot_directory, }, executable = False, ) @@ -124,16 +159,69 @@ def _create_symlinks(ctx, ndk_path, clang_directory, sysroot_directory): # TODO(#32): Remove this hack ctx.symlink(ndk_path + "sources", "ndk/sources") +_COMMON_ATTR = { + "api_level": attr.int( + doc = "The minimum Android API level to target.", + default = DEFAULT_API_LEVEL, + ), + "_build": attr.label( + default = Label("//:BUILD"), + allow_single_file = True, + ), + "_template_ndk_clang": attr.label( + default = Label("//:BUILD.ndk_clang.tpl"), + allow_single_file = True, + ), + "_template_ndk_root": attr.label( + default = Label("//:BUILD.ndk_root.tpl"), + allow_single_file = True, + ), + "_template_ndk_sysroot": attr.label( + default = Label(":BUILD.ndk_sysroot.tpl"), + allow_single_file = True, + ), + "_template_target_systems": attr.label( + default = Label("//:target_systems.bzl.tpl"), + allow_single_file = True, + ), +} + android_ndk_repository = repository_rule( - attrs = { - "path": attr.string(), - "api_level": attr.int(), - "_build": attr.label(default = ":BUILD", allow_single_file = True), - "_template_ndk_root": attr.label(default = ":BUILD.ndk_root.tpl", allow_single_file = True), - "_template_target_systems": attr.label(default = ":target_systems.bzl.tpl", allow_single_file = True), - "_template_ndk_clang": attr.label(default = ":BUILD.ndk_clang.tpl", allow_single_file = True), - "_template_ndk_sysroot": attr.label(default = ":BUILD.ndk_sysroot.tpl", allow_single_file = True), + doc = "A repository rule that integrates the Android NDK from a workspace. Uses an anchor label to locate the NDK and requires the host platform and Clang resource directory to be specified. For local NDK installations, use local_android_ndk_repository instead.", + implementation = _android_ndk_repository_impl, + attrs = _COMMON_ATTR | { + "anchor": attr.string( + doc = "A label to a file in the NDK directory. The directory containing this file is used as the NDK root path.", + mandatory = True, + ), + "clang_resource_dir": attr.string( + doc = "The Clang resource directory path. Pass an empty string to auto-detect by running clang --print-resource-dir.", + mandatory = True, + ), + "platform": attr.string( + doc = "The execution platform for the NDK toolchain (e.g., 'linux-x86_64', 'darwin-arm64', 'windows-x86_64'). Determines which prebuilt toolchain directory is used.", + values = _EXEC_CONSTRAINTS.keys(), + mandatory = True, + ), + }, +) + +def _local_android_ndk_repository_impl(ctx): + ndk_path = ctx.attr.path or ctx.getenv("ANDROID_NDK_HOME", None) + if not ndk_path: + fail("Either the ANDROID_NDK_HOME environment variable or the " + + "path attribute of android_ndk_repository must be set.") + + return _android_ndk_repository_impl(ctx, ndk_path) + +local_android_ndk_repository = repository_rule( + doc = "A repository rule that integrates the Android NDK from a local path. Uses ANDROID_NDK_HOME environment variable or the path attribute. This is the rule used by the bzlmod extension.", + implementation = _local_android_ndk_repository_impl, + attrs = _COMMON_ATTR | { + "path": attr.string( + doc = "The path to the local Android NDK installation. If not set, ANDROID_NDK_HOME environment variable is used. May start with $WORKSPACE_ROOT to reference the workspace root.", + ), }, + environ = ["ANDROID_NDK_HOME"], local = True, - implementation = _android_ndk_repository_impl, ) From 57c6f67910bba53b4f99ebd53e7ab6e0b35a8713 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Tue, 7 Apr 2026 08:14:27 -0700 Subject: [PATCH 2/6] Restored compatibility --- rules.bzl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rules.bzl b/rules.bzl index 5813e22..4f78b01 100644 --- a/rules.bzl +++ b/rules.bzl @@ -186,9 +186,12 @@ _COMMON_ATTR = { ), } -android_ndk_repository = repository_rule( +def _remote_android_ndk_repository_impl(ctx): + return _android_ndk_repository_impl(ctx, None) + +remote_android_ndk_repository = repository_rule( doc = "A repository rule that integrates the Android NDK from a workspace. Uses an anchor label to locate the NDK and requires the host platform and Clang resource directory to be specified. For local NDK installations, use local_android_ndk_repository instead.", - implementation = _android_ndk_repository_impl, + implementation = _remote_android_ndk_repository_impl, attrs = _COMMON_ATTR | { "anchor": attr.string( doc = "A label to a file in the NDK directory. The directory containing this file is used as the NDK root path.", @@ -225,3 +228,6 @@ local_android_ndk_repository = repository_rule( environ = ["ANDROID_NDK_HOME"], local = True, ) + +# For backward compatibility +android_ndk_repository = local_android_ndk_repository From 4e14f587a49d0d94be9b6c20754bbfa6bcd7d9ef Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Tue, 7 Apr 2026 08:25:33 -0700 Subject: [PATCH 3/6] Minor cleanup --- rules.bzl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/rules.bzl b/rules.bzl index 4f78b01..375d3c2 100644 --- a/rules.bzl +++ b/rules.bzl @@ -48,7 +48,7 @@ def _get_clang_resource_dir(ctx, clang_directory, is_windows): stdout = stdout.replace("\\", "/") return stdout.split(clang_directory)[1].strip("/") -def _android_ndk_repository_impl(ctx, ndk_path = None): +def _android_ndk_repository_impl(ctx, ndk_path): """Install the Android NDK files. Args: @@ -58,12 +58,6 @@ def _android_ndk_repository_impl(ctx, ndk_path = None): Returns: A final dict of configuration attributes and values. """ - if ndk_path == None: - ndk_path = ctx.path(Label(ctx.attr.anchor)).dirname - - if ndk_path.startswith("$WORKSPACE_ROOT"): - ndk_path = str(ctx.workspace_root) + ndk_path.removeprefix("$WORKSPACE_ROOT") - is_windows = False executable_extension = "" exec_compatible_with = None @@ -187,7 +181,9 @@ _COMMON_ATTR = { } def _remote_android_ndk_repository_impl(ctx): - return _android_ndk_repository_impl(ctx, None) + ndk_path = ctx.path(Label(ctx.attr.anchor)).dirname + + return _android_ndk_repository_impl(ctx, ndk_path) remote_android_ndk_repository = repository_rule( doc = "A repository rule that integrates the Android NDK from a workspace. Uses an anchor label to locate the NDK and requires the host platform and Clang resource directory to be specified. For local NDK installations, use local_android_ndk_repository instead.", @@ -215,6 +211,9 @@ def _local_android_ndk_repository_impl(ctx): fail("Either the ANDROID_NDK_HOME environment variable or the " + "path attribute of android_ndk_repository must be set.") + if ndk_path.startswith("$WORKSPACE_ROOT"): + ndk_path = str(ctx.workspace_root) + ndk_path.removeprefix("$WORKSPACE_ROOT") + return _android_ndk_repository_impl(ctx, ndk_path) local_android_ndk_repository = repository_rule( From 8d5e43fa5fe2c1a0d4cf9c672ab65bdb3f40b7be Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Tue, 7 Apr 2026 11:18:52 -0700 Subject: [PATCH 4/6] PR feedback --- README.md | 6 +++--- examples/basic/WORKSPACE | 4 ++-- examples/cpu_features/WORKSPACE | 4 ++-- extension.bzl | 4 ++-- rules.bzl | 17 +++++++---------- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index c63886c..fe80903 100644 --- a/README.md +++ b/README.md @@ -102,15 +102,15 @@ http_archive( urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.17/rules_cc-0.0.17.tar.gz"], ) -load("@rules_android_ndk//:rules.bzl", "local_android_ndk_repository") +load("@rules_android_ndk//:rules.bzl", "android_ndk_repository") -local_android_ndk_repository(name = "androidndk") +android_ndk_repository(name = "androidndk") register_toolchains("@androidndk//:all") ``` Then, set the `ANDROID_NDK_HOME` environment variable or the `path` attribute of -`local_android_ndk_repository` to the path of the local Android NDK installation +`android_ndk_repository` to the path of the local Android NDK installation directory. If the path starts with `$WORKSPACE_ROOT`, then this string is replaced with the root path of the Bazel workspace. diff --git a/examples/basic/WORKSPACE b/examples/basic/WORKSPACE index 18644a1..d263611 100644 --- a/examples/basic/WORKSPACE +++ b/examples/basic/WORKSPACE @@ -72,8 +72,8 @@ http_archive( ) # --SNIP--: Everything below this lines goes into the example WORKSPACE snippet in the release notes. -load("@rules_android_ndk//:rules.bzl", "local_android_ndk_repository") +load("@rules_android_ndk//:rules.bzl", "android_ndk_repository") -local_android_ndk_repository(name = "androidndk") +android_ndk_repository(name = "androidndk") register_toolchains("@androidndk//:all") diff --git a/examples/cpu_features/WORKSPACE b/examples/cpu_features/WORKSPACE index 46b0e48..df78f7c 100644 --- a/examples/cpu_features/WORKSPACE +++ b/examples/cpu_features/WORKSPACE @@ -74,8 +74,8 @@ http_archive( ) # --SNIP--: Everything below this lines goes into the example WORKSPACE snippet in the release notes. -load("@rules_android_ndk//:rules.bzl", "local_android_ndk_repository") +load("@rules_android_ndk//:rules.bzl", "android_ndk_repository") -local_android_ndk_repository(name = "androidndk") +android_ndk_repository(name = "androidndk") register_toolchains("@androidndk//:all") diff --git a/extension.bzl b/extension.bzl index c3035d1..b1d7295 100644 --- a/extension.bzl +++ b/extension.bzl @@ -14,7 +14,7 @@ """A bzlmod extension for loading the NDK.""" -load(":rules.bzl", "DEFAULT_API_LEVEL", "local_android_ndk_repository") +load(":rules.bzl", "DEFAULT_API_LEVEL", "android_ndk_repository") def _android_ndk_repository_extension_impl(module_ctx): root_modules = [m for m in module_ctx.modules if m.is_root and m.tags.configure] @@ -31,7 +31,7 @@ def _android_ndk_repository_extension_impl(module_ctx): kwargs["api_level"] = module.tags.configure[0].api_level kwargs["path"] = module.tags.configure[0].path - local_android_ndk_repository( + android_ndk_repository( name = "androidndk", **kwargs ) diff --git a/rules.bzl b/rules.bzl index 375d3c2..b533c00 100644 --- a/rules.bzl +++ b/rules.bzl @@ -180,14 +180,14 @@ _COMMON_ATTR = { ), } -def _remote_android_ndk_repository_impl(ctx): +def _exec_android_ndk_repository_impl(ctx): ndk_path = ctx.path(Label(ctx.attr.anchor)).dirname return _android_ndk_repository_impl(ctx, ndk_path) -remote_android_ndk_repository = repository_rule( - doc = "A repository rule that integrates the Android NDK from a workspace. Uses an anchor label to locate the NDK and requires the host platform and Clang resource directory to be specified. For local NDK installations, use local_android_ndk_repository instead.", - implementation = _remote_android_ndk_repository_impl, +exec_android_ndk_repository = repository_rule( + doc = "A repository rule that integrates the Android NDK from a workspace. Uses an anchor label to locate the NDK and requires the host platform and Clang resource directory to be specified. For local NDK installations, use android_ndk_repository instead.", + implementation = _exec_android_ndk_repository_impl, attrs = _COMMON_ATTR | { "anchor": attr.string( doc = "A label to a file in the NDK directory. The directory containing this file is used as the NDK root path.", @@ -205,7 +205,7 @@ remote_android_ndk_repository = repository_rule( }, ) -def _local_android_ndk_repository_impl(ctx): +def _android_ndk_repository_impl(ctx): ndk_path = ctx.attr.path or ctx.getenv("ANDROID_NDK_HOME", None) if not ndk_path: fail("Either the ANDROID_NDK_HOME environment variable or the " + @@ -216,9 +216,9 @@ def _local_android_ndk_repository_impl(ctx): return _android_ndk_repository_impl(ctx, ndk_path) -local_android_ndk_repository = repository_rule( +android_ndk_repository = repository_rule( doc = "A repository rule that integrates the Android NDK from a local path. Uses ANDROID_NDK_HOME environment variable or the path attribute. This is the rule used by the bzlmod extension.", - implementation = _local_android_ndk_repository_impl, + implementation = _android_ndk_repository_impl, attrs = _COMMON_ATTR | { "path": attr.string( doc = "The path to the local Android NDK installation. If not set, ANDROID_NDK_HOME environment variable is used. May start with $WORKSPACE_ROOT to reference the workspace root.", @@ -227,6 +227,3 @@ local_android_ndk_repository = repository_rule( environ = ["ANDROID_NDK_HOME"], local = True, ) - -# For backward compatibility -android_ndk_repository = local_android_ndk_repository From e3a0820e8a1fcc4f6ced324d9268875573474c5f Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Tue, 7 Apr 2026 11:19:30 -0700 Subject: [PATCH 5/6] Additional rename --- rules.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rules.bzl b/rules.bzl index b533c00..0876847 100644 --- a/rules.bzl +++ b/rules.bzl @@ -180,14 +180,14 @@ _COMMON_ATTR = { ), } -def _exec_android_ndk_repository_impl(ctx): +def _exec_configuration_android_ndk_repository_impl(ctx): ndk_path = ctx.path(Label(ctx.attr.anchor)).dirname return _android_ndk_repository_impl(ctx, ndk_path) -exec_android_ndk_repository = repository_rule( +exec_configuration_android_ndk_repository = repository_rule( doc = "A repository rule that integrates the Android NDK from a workspace. Uses an anchor label to locate the NDK and requires the host platform and Clang resource directory to be specified. For local NDK installations, use android_ndk_repository instead.", - implementation = _exec_android_ndk_repository_impl, + implementation = _exec_configuration_android_ndk_repository_impl, attrs = _COMMON_ATTR | { "anchor": attr.string( doc = "A label to a file in the NDK directory. The directory containing this file is used as the NDK root path.", From aa464281cf1fc77ad2ffbc3e8847933ed7f34168 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Tue, 7 Apr 2026 11:22:03 -0700 Subject: [PATCH 6/6] Deconflict function name --- rules.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rules.bzl b/rules.bzl index 0876847..12a0e75 100644 --- a/rules.bzl +++ b/rules.bzl @@ -48,7 +48,7 @@ def _get_clang_resource_dir(ctx, clang_directory, is_windows): stdout = stdout.replace("\\", "/") return stdout.split(clang_directory)[1].strip("/") -def _android_ndk_repository_impl(ctx, ndk_path): +def _android_ndk_repository_common(ctx, ndk_path): """Install the Android NDK files. Args: @@ -183,7 +183,7 @@ _COMMON_ATTR = { def _exec_configuration_android_ndk_repository_impl(ctx): ndk_path = ctx.path(Label(ctx.attr.anchor)).dirname - return _android_ndk_repository_impl(ctx, ndk_path) + return _android_ndk_repository_common(ctx, ndk_path) exec_configuration_android_ndk_repository = repository_rule( doc = "A repository rule that integrates the Android NDK from a workspace. Uses an anchor label to locate the NDK and requires the host platform and Clang resource directory to be specified. For local NDK installations, use android_ndk_repository instead.", @@ -214,7 +214,7 @@ def _android_ndk_repository_impl(ctx): if ndk_path.startswith("$WORKSPACE_ROOT"): ndk_path = str(ctx.workspace_root) + ndk_path.removeprefix("$WORKSPACE_ROOT") - return _android_ndk_repository_impl(ctx, ndk_path) + return _android_ndk_repository_common(ctx, ndk_path) android_ndk_repository = repository_rule( doc = "A repository rule that integrates the Android NDK from a local path. Uses ANDROID_NDK_HOME environment variable or the path attribute. This is the rule used by the bzlmod extension.",