Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate empty repo when path is not set #63

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,32 @@ cpu_features: &cpu_features
build_targets:
- "//:all"

hello_world_host_cc: &hello_world_host_cc
working_directory: tests/cc_binary
build_flags:
- "--incompatible_disallow_empty_glob"
build_targets:
- "//:all"

hello_world_ndk_cc: &hello_world_ndk_cc
working_directory: tests/cc_binary
build_flags:
- "--incompatible_disallow_empty_glob"
- "--incompatible_enable_android_toolchain_resolution"
- "--platforms=//:arm64-v8a"
build_targets:
- "//:all"

ubuntu2004: &ubuntu2004
platform: ubuntu2004
environment:
ANDROID_NDK_HOME: /opt/android-ndk-r25b

ubuntu2004-no-ndk: &ubuntu2004-no-ndk
platform: ubuntu2004
environment:
ANDROID_NDK_HOME: ""

macos: &macos
platform: macos
environment:
Expand Down Expand Up @@ -67,10 +88,17 @@ tasks:
name: Basic Example Bzlmod
<<: [*windows, *basic_example_bzlmod]


cpu_features_ubuntu2004:
name: CPU Features
<<: [*ubuntu2004, *cpu_features]
cpu_features_macos:
name: CPU Features
<<: [*macos, *cpu_features]

hello_world_host_cc_without_ndk:
name: Host Hello World without Android NDK
<<: [*ubuntu2004-no-ndk, *hello_world_host_cc]

hello_world_android_cc_without_ndk:
name: Host Hello World without Android NDK (should fail)
<<: [*ubuntu2004-no-ndk, *hello_world_ndk_cc]
58 changes: 58 additions & 0 deletions BUILD.empty.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
This module adds no-op repository rules when the Android NDK is not installed.
"""

package(default_visibility = ["//visibility:public"])

load(":dummy_cc_toolchain.bzl", "dummy_cc_config", "dummy_cc_toolchain")
load("//:target_systems.bzl", "CPU_CONSTRAINT", "TARGET_SYSTEM_NAMES")

# android_ndk_repository was used without a valid Android NDK being set.
# Either the path attribute of android_ndk_repository or the ANDROID_NDK_HOME
# environment variable must be set.
# This is a minimal BUILD file to allow non-Android builds to continue.

# Loop over TARGET_SYSTEM_NAMES and define all empty toolchain targets.
[toolchain(
name = "toolchain_%s" % target_system_name,
toolchain = ":dummy_android_ndk_toolchain_cc",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
target_compatible_with = [
"@platforms//os:android",
CPU_CONSTRAINT[target_system_name],
],
) for target_system_name in TARGET_SYSTEM_NAMES]

cc_toolchain(
name = "dummy_android_ndk_toolchain_cc",
all_files = ":invalid_android_ndk_repository_error",
compiler_files = ":invalid_android_ndk_repository_error",
dwp_files = ":invalid_android_ndk_repository_error",
linker_files = ":invalid_android_ndk_repository_error",
objcopy_files = ":invalid_android_ndk_repository_error",
strip_files = ":invalid_android_ndk_repository_error",
supports_param_files = 0,
toolchain_config = ":cc_toolchain_config",
toolchain_identifier = "dummy_wasm32_cc",
)

dummy_cc_config(
name = "cc_toolchain_config",
)

cc_library(
name = "cpufeatures",
data = [":error_message"],
)

genrule(
name = "invalid_android_ndk_repository_error",
outs = [
"error_message",
],
cmd = """echo
echo rules_android_ndk was used without a valid Android NDK being set: \
either the path attribute of android_ndk_repository or the ANDROID_NDK_HOME environment variable must be set.
echo
exit 1""",
)
111 changes: 111 additions & 0 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions dummy_cc_toolchain.bzl.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def _dummy_cc_toolchain_impl(_ctx):
# The `all_files` attribute is referenced by rustc_compile_action().
return [platform_common.ToolchainInfo(all_files = depset([]))]

dummy_cc_toolchain = rule(
implementation = _dummy_cc_toolchain_impl,
attrs = {},
)

# dummy values from https://bazel.build/tutorials/ccp-toolchain-config#configuring_the_c_toolchain
def _config_impl(ctx):
return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
toolchain_identifier = "dummy-android-ndk-toolchain-cc",
host_system_name = "unknown",
target_system_name = "unknown",
target_cpu = "unknown",
target_libc = "unknown",
compiler = "unknown",
abi_version = "unknown",
abi_libc_version = "unknown",
)

dummy_cc_config = rule(
implementation = _config_impl,
attrs = {},
provides = [CcToolchainConfigInfo],
)
Loading