Skip to content
New issue

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

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

Already on GitHub? # to your account

Error in fail: Unable to find a CC toolchain using toolchain resolution. #20970

Open
sgowroji opened this issue Jan 22, 2024 · 8 comments · May be fixed by bazelbuild/examples#455
Open

Error in fail: Unable to find a CC toolchain using toolchain resolution. #20970

sgowroji opened this issue Jan 22, 2024 · 8 comments · May be fixed by bazelbuild/examples#455
Assignees

Comments

@sgowroji
Copy link
Member

sgowroji commented Jan 22, 2024

CI: https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/3608#018d2ef4-1d2c-446b-a314-c133272f58d9

Platform: Ubuntu, MacOS

Logs:

Traceback (most recent call last):
	File "/virtual_builtins_bzl/common/cc/cc_toolchain_alias.bzl", line 26, column 48, in _impl
	File "/virtual_builtins_bzl/common/cc/cc_helper.bzl", line 217, column 13, in _find_cpp_toolchain
Error in fail: Unable to find a CC toolchain using toolchain resolution. Target: @@bazel_tools//tools/cpp:current_cc_toolchain, Platform: @@//:arm64-v8a, Exec platform: @@local_config_platform//:host
(02:20:31) ERROR: /var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/051ad6a69d7a84f28cf16b88c532f996/external/bazel_tools/tools/cpp/BUILD:58:19: Analysis of target '@@bazel_tools//tools/cpp:current_cc_toolchain' failed
(02:20:31) ERROR: Analysis of target '//app/src/main:app' failed; build aborted: Analysis failed

Culprit: 03490b9, 8ba6618

Steps:

git clone -v https://github.com/bazelbuild/examples.git 
git reset d18ce42623f136616e9512d713a47c33f9ad6a58 --hard
export USE_BAZEL_VERSION=addf41bce1f26e8bc4bd0b09cb2fbffbb0446f25
cd examples/android/jetpack-compose
bazel build  --android_platforms=//:arm64-v8a --remote_download_outputs=all --enable_bzlmod  //app/src/main:app 

CC Greenteam @comius

@AnDevi
Copy link

AnDevi commented Feb 15, 2024

Hello, I'm using bazel 7.0.2 right now and I'm facing exactly the same problem. Is there possibility that that issue came back ?

@comius
Copy link
Contributor

comius commented Feb 28, 2024

Hey @ted-xie, this looks like Android NDK toolchains problem happening https://github.com/bazelbuild/examples/tree/main/android/jetpack-compose. Could you investigate?

@comius
Copy link
Contributor

comius commented Mar 21, 2024

@ted-xie @ahumesky friendly ping

1 similar comment
@comius
Copy link
Contributor

comius commented May 3, 2024

@ted-xie @ahumesky friendly ping

@comius
Copy link
Contributor

comius commented May 3, 2024

cc @meisterT

@ted-xie
Copy link
Contributor

ted-xie commented May 13, 2024

I was able to reproduce this (after a small change in the repro instructions that I've edited the original issue for). I think I've seen this before; we should just need some extra flags in bazelrc IIRC.

@ted-xie
Copy link
Contributor

ted-xie commented May 16, 2024

I think there may be multiple problems with this example. I noticed there was no NDK repository specified anywhere, so I added it:

diff --git a/android/jetpack-compose/WORKSPACE b/android/jetpack-compose/WORKSPACE
index b0325a8..db38a08 100644
--- a/android/jetpack-compose/WORKSPACE
+++ b/android/jetpack-compose/WORKSPACE
@@ -41,3 +41,14 @@ load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")
 
 kt_register_toolchains()
 
+http_archive(
+    name = "rules_android_ndk",
+    sha256 = "b1a5ddd784e6ed915c2035c0db536a278b5f50c64412128c06877115991391ef",
+    strip_prefix = "rules_android_ndk-877c68ef34c9f3353028bf490d269230c1990483",
+    url = "https://github.com/bazelbuild/rules_android_ndk/archive/877c68ef34c9f3353028bf490d269230c1990483.zip",
+)
+
+load("@rules_android_ndk//:rules.bzl", "android_ndk_repository")
+
+android_ndk_repository(name = "androidndk")
+

Then when I try to build the example app, there's a different error about a missing Java toolchain:

$ bazelisk build  --android_platforms=//:arm64-v8a --remote_download_outputs=all --enable_bzlmod  //app/src/main:app 
ERROR: /usr/local/google/home/tedx/work/github/bazel_issue_20970/examples/android/jetpack-compose/app/src/main/BUILD.bazel:4:19: While resolving toolchains for target //app/src/main:lib_kt (aadbf16): No matching toolchains found for types @@bazel_tools//tools/jdk:runtime_toolchain_type.

I think overall it may be better to deprecate this jetpack compose example entirely, since rules_kotlin has its own version here that is more actively maintained and closer to the development pulse. @Bencodes

@ted-xie
Copy link
Contributor

ted-xie commented May 16, 2024

Updating to a more recent rules_kotlin version seems to make things a little better, but not entirely; at least now there are no more toolchain-related issues.

My patch:

diff --git a/android/jetpack-compose/WORKSPACE b/android/jetpack-compose/WORKSPACE
index b0325a8..2ab68f2 100644
--- a/android/jetpack-compose/WORKSPACE
+++ b/android/jetpack-compose/WORKSPACE
@@ -22,10 +22,15 @@ android_sdk_repository(name = "androidsdk")
 
 ## Kotlin
 
+#http_archive(
+#    name = "io_bazel_rules_kotlin",
+#    sha256 = "f033fa36f51073eae224f18428d9493966e67c27387728b6be2ebbdae43f140e",
+#    url = "https://github.com/bazelbuild/rules_kotlin/releases/download/v1.7.0-RC-3/rules_kotlin_release.tgz",
+#)
 http_archive(
     name = "io_bazel_rules_kotlin",
-    sha256 = "f033fa36f51073eae224f18428d9493966e67c27387728b6be2ebbdae43f140e",
-    url = "https://github.com/bazelbuild/rules_kotlin/releases/download/v1.7.0-RC-3/rules_kotlin_release.tgz",
+    sha256 = "34e8c0351764b71d78f76c8746e98063979ce08dcf1a91666f3f3bc2949a533d",
+    url = "https://github.com/bazelbuild/rules_kotlin/releases/download/v1.9.5/rules_kotlin-v1.9.5.tar.gz",
 )
 
 load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "kotlinc_version")
@@ -41,3 +46,15 @@ load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")
 
 kt_register_toolchains()
 
+## NDK
+http_archive(
+    name = "rules_android_ndk",
+    sha256 = "b1a5ddd784e6ed915c2035c0db536a278b5f50c64412128c06877115991391ef",
+    strip_prefix = "rules_android_ndk-877c68ef34c9f3353028bf490d269230c1990483",
+    url = "https://github.com/bazelbuild/rules_android_ndk/archive/877c68ef34c9f3353028bf490d269230c1990483.zip",
+)
+
+load("@rules_android_ndk//:rules.bzl", "android_ndk_repository")
+
+android_ndk_repository(name = "androidndk")

The build:

$ bazelisk build --android_platforms=//:arm64-v8a --remote_download_outputs=all --enable_bzlmod  //app/src/main:app  
INFO: Analyzed target //app/src/main:app (12 packages loaded, 6078 targets configured).
INFO: From KotlinCompile //app/src/main:lib_kt { kt: 1, java: 0, srcjars: 0 } for k8:
warning: language version 1.9 is experimental, there are no backwards compatibility guarantees for new language and library features
warning: language version 1.9 is experimental, there are no backwards compatibility guarantees for new language and library features
ERROR: /usr/local/google/home/tedx/work/github/bazel_issue_20970/examples/android/jetpack-compose/app/src/main/BUILD.bazel:4:19: output 'app/src/main/lib_kt-kt.jdeps' was not created
ERROR: /usr/local/google/home/tedx/work/github/bazel_issue_20970/examples/android/jetpack-compose/app/src/main/BUILD.bazel:4:19: KotlinCompile //app/src/main:lib_kt { kt: 1, java: 0, srcjars: 0 } for k8 failed: not all outputs were created or valid

I think this needs some input from the rules_kotlin folks on how to proceed.

ted-xie added a commit to ted-xie/bazelbuild-examples that referenced this issue May 16, 2024
* Use a more recent rules_kotlin version (1.9.5)
* Use a more recent compose compiler version (1.9.22)
* Add android_ndk_repository dependency

Fixes bazelbuild/bazel#20970
@ted-xie ted-xie linked a pull request May 16, 2024 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants