Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add Android Platforms build flags. #1054

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,24 @@ tasks:
name: "Example - Android"
platform: ubuntu1804
working_directory: examples/android
bazel: 7.0.0-pre.20230906.2
bazel: last_green
test_flags:
- "--incompatible_enable_android_toolchain_resolution"
- "--android_platforms=//:arm64-v8a"
- "--enable_bzlmod=false"
test_targets:
- //...
- //app:all
example-bzlmod-android:
name: "Example Bzlmod - Android"
platform: ubuntu1804
working_directory: examples/android
bazel: 7.0.0-pre.20230906.2
bazel: last_green
test_flags:
- "--incompatible_enable_android_toolchain_resolution"
- "--android_platforms=//:arm64-v8a"
- "--enable_bzlmod=true"
test_targets:
- //...
- //app:all
example-ksp:
name: "Example - Android KSP"
platform: ubuntu1804
Expand All @@ -76,8 +80,12 @@ tasks:
name: "Example - Anvil"
platform: ubuntu1804
working_directory: examples/anvil
bazel: last_green
test_flags:
- "--incompatible_enable_android_toolchain_resolution"
- "--android_platforms=//:arm64-v8a"
test_targets:
- //...
- //app:all
example-plugins:
name: "Example - Plugins"
platform: ubuntu1804
Expand Down Expand Up @@ -162,8 +170,12 @@ tasks:
name: "Example - Jetpack Compose"
platform: ubuntu1804
working_directory: examples/jetpack_compose
bazel: last_green
test_flags:
- "--incompatible_enable_android_toolchain_resolution"
- "--android_platforms=//:arm64-v8a"
test_targets:
- //...
- //app:all
stardoc:
name: Stardoc api documentation
platform: ubuntu1804
Expand Down
7 changes: 7 additions & 0 deletions examples/android/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
platform(
name = "arm64-v8a",
constraint_values = [
"@platforms//cpu:arm64",
"@platforms//os:android",
],
)
1 change: 1 addition & 0 deletions examples/android/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ bazel_dep(name = "rules_android", version = "0.1.1")
bazel_dep(name = "bazel_skylib", version = "1.2.1")
bazel_dep(name = "rules_robolectric", version = "4.10.3", repo_name = "robolectric")
bazel_dep(name = "rules_java", version = "6.4.0")
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "rules_kotlin")
local_path_override(
module_name = "rules_kotlin",
Expand Down
2 changes: 2 additions & 0 deletions examples/android/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ http_archive(
load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")

robolectric_repositories()

android_ndk_repository(name = "androidndk")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the NDK a requirement now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before enabling --incompatible_enable_android_toolchain_resolution, this was using the default (and useless) cc_toolchain from bazel's CC autodetection.

Since that's no longer appropriate (it claims armeabi-v7a, I don't know if the cc compiler in this image can actually do this), it seemed better to at least accurately declare that every Android binary needs an NDK for analysis. If you don't have any actual cc_library dependencies it isn't used (which is why the old one worked).

Ideally the Android rules would not require a CC toolchain if it's not being used, but currently they are.

8 changes: 8 additions & 0 deletions examples/anvil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ define_kt_toolchain(
name = "kotlin_toolchain",
jvm_target = "1.8",
)

platform(
name = "arm64-v8a",
constraint_values = [
"@platforms//cpu:arm64",
"@platforms//os:android",
],
)
2 changes: 2 additions & 0 deletions examples/anvil/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ load("@rules_android//android:rules.bzl", "android_sdk_repository")

android_sdk_repository(name = "androidsdk")

android_ndk_repository(name = "androidndk")

# Skylib, for build_test, so don't bother initializing the unit test infrastructure.
http_archive(
name = "bazel_skylib",
Expand Down
8 changes: 8 additions & 0 deletions examples/anvil/app/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@rules_android//android:rules.bzl", "android_binary")

android_binary(
Expand All @@ -9,3 +10,10 @@ android_binary(
"//app/src/main/java/com/squareup/anvil/sample",
],
)

build_test(
name = "force_build_apks_test",
targets = [
":app.apk",
],
)
8 changes: 8 additions & 0 deletions examples/jetpack_compose/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ kt_compiler_plugin(
"@maven//:androidx_compose_compiler_compiler",
],
)

platform(
name = "arm64-v8a",
constraint_values = [
"@platforms//cpu:arm64",
"@platforms//os:android",
],
)
2 changes: 2 additions & 0 deletions examples/jetpack_compose/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,5 @@ http_archive(
load("@rules_android//android:rules.bzl", "android_sdk_repository")

android_sdk_repository(name = "androidsdk")

android_ndk_repository(name = "androidndk")