rules_android_ndk icon indicating copy to clipboard operation
rules_android_ndk copied to clipboard

Generate empty repo when path is not set

Open gferon opened this issue 2 years ago • 6 comments

Declare an empty repository with empty toolchains and an error message when the path to the NDK was missing.

Based on a comment from https://github.com/bazelbuild/rules_android_ndk/pull/61#discussion_r1473436245 and a very similar approach to what's done in the starlark version of rules_android.

gferon avatar Jan 31 '24 21:01 gferon

Note: this doesn't exactly work yet as we'd like to, as it errors with the following message

While resolving toolchains for target @@bazel_tools//tools/cpp:current_cc_toolchain (2f4faa5): toolchain type @@bazel_tools//tools/cpp:toolchain_type resolved to target @@androidndk//:error_message, but that target does not provide ToolchainInfo

gferon avatar Jan 31 '24 21:01 gferon

It would be great to also look at how to add a test for this. It would probably require a new task in .bazelci/presubmit.yml because all the tests will set ANDROID_NDK_HOME

ahumesky avatar Feb 01 '24 21:02 ahumesky

Hi, any update on this change?

ahumesky avatar Mar 08 '24 01:03 ahumesky

@ahumesky I finally took the time to make it work as I wanted to. It involves adding a dummy_cc_toolchain like it is done in rules_rust for wasm32 (which doesn't have any CC toolchain).

I added two tests in .bazelci/presubmit.yml but don't know how to make the job expect a failure (for the hello-world-android-without-ndk variant). Could you fix that for me?

A failure will look like this (when building for Android platforms only):

bazel build //:all --platforms=//
:arm64-v8a --incompatible_enable_android_toolchain_resol
ution
INFO: Invocation ID: 45bffac4-903c-4be0-aae1-1949130af331
WARNING: Build option --platforms has changed, discarding analysis cache (this can be expensive, see https://bazel.build/advanced/performance/iteration-speed).
INFO: Analyzed target //:hello-world (83 packages loaded, 426 targets configured).
ERROR: /Volumes/bazel-cache/981d0988d8cc33709e99b10fe2f0cc90/external/rules_android_ndk~~android_ndk_repository_extension~androidndk/BUILD.bazel:48:8: Executing genrule @@rules_android_ndk~~android_ndk_repository_extension~androidndk//:invalid_android_ndk_repository_error [for tool] failed: (Exit 1): bash failed: error executing Genrule command (from target @@rules_android_ndk~~android_ndk_repository_extension~androidndk//:invalid_android_ndk_repository_error) /bin/bash -c ... (remaining 1 argument skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging

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.

Target //:hello-world failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.342s, Critical Path: 0.02s
INFO: 3 processes: 3 internal.
ERROR: Build did NOT complete successfully

gferon avatar Jul 31 '24 13:07 gferon

Hmm yes expecting a failure in a test like this is tricky, I'm not sure that bazelci is setup up for negative tests. The alternative is to refactor the tests into "bazel within bazel test" integration tests: https://github.com/bazel-contrib/rules_bazel_integration_test

I'm not a big fan of those because they tend to very fragile and somewhat slow, but unless bazelci can do this or that's added to bazelci, might be the only option.

ahumesky avatar Sep 18 '24 23:09 ahumesky