Skip to content

Commit 785f09f

Browse files
committed
Make it work with a proper error msg
1 parent bb05729 commit 785f09f

10 files changed

+467
-1290
lines changed

.bazelci/presubmit.yml

+29-1
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,32 @@ cpu_features: &cpu_features
3131
build_targets:
3232
- "//:all"
3333

34+
hello_world_host_cc: &hello_world_host_cc
35+
working_directory: tests/cc_binary
36+
build_flags:
37+
- "--incompatible_disallow_empty_glob"
38+
build_targets:
39+
- "//:all"
40+
41+
hello_world_ndk_cc: &hello_world_ndk_cc
42+
working_directory: tests/cc_binary
43+
build_flags:
44+
- "--incompatible_disallow_empty_glob"
45+
- "--incompatible_enable_android_toolchain_resolution"
46+
- "--platforms=//:arm64-v8a"
47+
build_targets:
48+
- "//:all"
49+
3450
ubuntu2004: &ubuntu2004
3551
platform: ubuntu2004
3652
environment:
3753
ANDROID_NDK_HOME: /opt/android-ndk-r25b
3854

55+
ubuntu2004-no-ndk: &ubuntu2004-no-ndk
56+
platform: ubuntu2004
57+
environment:
58+
ANDROID_NDK_HOME: ""
59+
3960
macos: &macos
4061
platform: macos
4162
environment:
@@ -67,10 +88,17 @@ tasks:
6788
name: Basic Example Bzlmod
6889
<<: [*windows, *basic_example_bzlmod]
6990

70-
7191
cpu_features_ubuntu2004:
7292
name: CPU Features
7393
<<: [*ubuntu2004, *cpu_features]
7494
cpu_features_macos:
7595
name: CPU Features
7696
<<: [*macos, *cpu_features]
97+
98+
hello_world_host_cc_without_ndk:
99+
name: Host Hello World without Android NDK
100+
<<: [*ubuntu2004-no-ndk, *hello_world_host_cc]
101+
102+
hello_world_android_cc_without_ndk:
103+
name: Host Hello World without Android NDK (should fail)
104+
<<: [*ubuntu2004-no-ndk, *hello_world_ndk_cc]

BUILD.empty.tpl

+24-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This module adds no-op repository rules when the Android NDK is not installed.
44

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

7+
load(":dummy_cc_toolchain.bzl", "dummy_cc_config", "dummy_cc_toolchain")
78
load("//:target_systems.bzl", "CPU_CONSTRAINT", "TARGET_SYSTEM_NAMES")
89

910
# android_ndk_repository was used without a valid Android NDK being set.
@@ -14,14 +15,31 @@ load("//:target_systems.bzl", "CPU_CONSTRAINT", "TARGET_SYSTEM_NAMES")
1415
# Loop over TARGET_SYSTEM_NAMES and define all empty toolchain targets.
1516
[toolchain(
1617
name = "toolchain_%s" % target_system_name,
17-
toolchain = ":error_message",
18+
toolchain = ":dummy_android_ndk_toolchain_cc",
1819
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
1920
target_compatible_with = [
2021
"@platforms//os:android",
2122
CPU_CONSTRAINT[target_system_name],
2223
],
2324
) for target_system_name in TARGET_SYSTEM_NAMES]
2425

26+
cc_toolchain(
27+
name = "dummy_android_ndk_toolchain_cc",
28+
all_files = ":invalid_android_ndk_repository_error",
29+
compiler_files = ":invalid_android_ndk_repository_error",
30+
dwp_files = ":invalid_android_ndk_repository_error",
31+
linker_files = ":invalid_android_ndk_repository_error",
32+
objcopy_files = ":invalid_android_ndk_repository_error",
33+
strip_files = ":invalid_android_ndk_repository_error",
34+
supports_param_files = 0,
35+
toolchain_config = ":cc_toolchain_config",
36+
toolchain_identifier = "dummy_wasm32_cc",
37+
)
38+
39+
dummy_cc_config(
40+
name = "cc_toolchain_config",
41+
)
42+
2543
cc_library(
2644
name = "cpufeatures",
2745
data = [":error_message"],
@@ -32,9 +50,9 @@ genrule(
3250
outs = [
3351
"error_message",
3452
],
35-
cmd = """echo \
36-
android_ndk_repository was used without a valid Android NDK being set. \
37-
Either the path attribute of android_ndk_repository or the ANDROID_NDK_HOME \
38-
environment variable must be set. ; \
39-
exit 1 """,
53+
cmd = """echo
54+
echo rules_android_ndk was used without a valid Android NDK being set: \
55+
either the path attribute of android_ndk_repository or the ANDROID_NDK_HOME environment variable must be set.
56+
echo
57+
exit 1""",
4058
)

MODULE.bazel.lock

+111
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dummy_cc_toolchain.bzl.tpl

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def _dummy_cc_toolchain_impl(_ctx):
2+
# The `all_files` attribute is referenced by rustc_compile_action().
3+
return [platform_common.ToolchainInfo(all_files = depset([]))]
4+
5+
dummy_cc_toolchain = rule(
6+
implementation = _dummy_cc_toolchain_impl,
7+
attrs = {},
8+
)
9+
10+
# dummy values from https://bazel.build/tutorials/ccp-toolchain-config#configuring_the_c_toolchain
11+
def _config_impl(ctx):
12+
return cc_common.create_cc_toolchain_config_info(
13+
ctx = ctx,
14+
toolchain_identifier = "dummy-android-ndk-toolchain-cc",
15+
host_system_name = "unknown",
16+
target_system_name = "unknown",
17+
target_cpu = "unknown",
18+
target_libc = "unknown",
19+
compiler = "unknown",
20+
abi_version = "unknown",
21+
abi_libc_version = "unknown",
22+
)
23+
24+
dummy_cc_config = rule(
25+
implementation = _config_impl,
26+
attrs = {},
27+
provides = [CcToolchainConfigInfo],
28+
)

0 commit comments

Comments
 (0)