Skip to content

Commit

Permalink
Make it work with a proper error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
gferon committed Jul 31, 2024
1 parent bb05729 commit 785f09f
Show file tree
Hide file tree
Showing 10 changed files with 467 additions and 1,290 deletions.
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]
30 changes: 24 additions & 6 deletions BUILD.empty.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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.
Expand All @@ -14,14 +15,31 @@ load("//:target_systems.bzl", "CPU_CONSTRAINT", "TARGET_SYSTEM_NAMES")
# Loop over TARGET_SYSTEM_NAMES and define all empty toolchain targets.
[toolchain(
name = "toolchain_%s" % target_system_name,
toolchain = ":error_message",
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"],
Expand All @@ -32,9 +50,9 @@ genrule(
outs = [
"error_message",
],
cmd = """echo \
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. ; \
exit 1 """,
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

0 comments on commit 785f09f

Please sign in to comment.