bazelbuild / bazelbuild/rules_android_ndk
Building cc_binary with rules unable to find cc_toolchain_suite
- Dominant language
- Starlark
- Stars
- 43
- Forks
- 32
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to upgrade a [project](https://github.com/ngzhian/cpuinfo/tree/workspace) to use rules_android_ndk (from the packaged one) and am facing some issues:
```
$ bazel build :cpuinfo --cpu=arm64-v8a --crosstool_top=@androidndk//:toolchain --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
ERROR: /usr/local/google/home/zhin/.cache/bazel/_bazel_zhin/6c29bbe1edd74d1c184bd5850967e7c9/external/androidndk/BUILD:9:6: no such target '@androidndk//toolchains/llvm/prebuilt/linux-x86_64:cc_toolchain_suite': target 'cc_toolchain_suite' not declared in package 'toolchains/llvm/prebuilt/linux-x86_64' defined by /usr/local/google/home/zhin/.cache/bazel/_bazel_zhin/6c29bbe1edd74d1c184bd5850967e7c9/external/androidndk/toolchains/llvm/prebuilt/linux-x86_64/BUILD.bazel (Tip: use `query "@androidndk//toolchains/llvm/prebuilt/linux-x86_64:*"` to see all the targets in that package) and referenced by '@androidndk//:toolchain'
ERROR: Analysis of target '//:cpuinfo' failed; build aborted:
INFO: Elapsed time: 0.126s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
```
I've read a couple of related issues here:
1. `cpuinfo` is a `cc_binary` so i'm using `--cpu` and `--crosstool_top` instead of the `--fat_apk_cpu` and `--android_crosstool_top` based on https://github.com/bazelbuild/rules_android_ndk/issues/19#issuecomment-1251257261
I also tried passing `--extra_toolchains=@androidndk//...`, and after resolving something related to `@rules_python`:
```
INFO: Build option --extra_toolchains has changed, discarding analysis cache.
ERROR: /usr/local/google/home/zhin/src/cpuinfo/BUILD.bazel:176:11: While resolving toolchains for target //:cpuinfo: invalid registered toolchain '@androidndk//...': error loading package under directory '': error loading package '@androidndk//sources/third_party/googletest/test': Unable to find package for @rules_python//python:defs.bzl: The repository '@rules_python' could not be resolved: Repository '@rules_python' is not defined.
ERROR: Analysis of target '//:cpuinfo' failed; build aborted:
INFO: Elapsed time: 0.231s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 6 targets configured)
currently loading: @androidndk//sources/third_party/googletest/test ... (2 packages)
```
by adding to WORKSPACE:
```
SHA = "84aec9e21cc56fbc7f1335035a71c850d1b9b5cc6ff497306f84cced9a769841"
VERSION = "0.23.1"
http_archive(
name = "rules_python",
sha256 = SHA,
strip_prefix = "rules_python-{}".format(VERSION),
url = "https://github.com/bazelbuild/rules_python/releases/download/{}/rules_python-{}.tar.gz".format(VERSION, VERSION),
)
load("@rules_python//python:repositories.bzl", "py_repositories")
py_repositories(
```
I get the same error about `no such target '@androidndk//toolchains/llvm/prebuilt/linux-x86_64:cc_toolchain_suite'`.
To reproduce:
```
git clone https://github.com/ngzhian/cpuinfo.git
cd cpuinfo
git checkout workspace
export ANDROID_NDK_HOME=/path/to/ndk/r25c # i'm using r25c
bazel build :cpuinfo --cpu=arm64-v8a --crosstool_top=@androidndk//:toolchain --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --fat_apk_cpu=arm64-v8a --android_crosstool_top=@androidndk//:toolchain
```
Contributor guide
Research direction
Start with the reproduced command and inspect the generated external/androidndk/BUILD and toolchains/llvm/prebuilt/linux-x86_64/BUILD.bazel files, then review the WORKSPACE setup for rules_android_ndk and rules_python. Compare the declared targets with the requested @androidndk//:toolchain and verify the arm64-v8a build completes without the missing cc_toolchain_suite error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100