Hello! We are trying to to build an android_binary that depends on a cc_library that is also built for other (non-android) platforms.
When modifying
this example to have a select statement in a cc_library, like
cc_library(
name = "jni",
srcs = ["jni.cc"],
copts = select({
"@platforms//cpu:x86_64": ["This should not be selected for Android ARM"],
"//conditions:default": [],
}),
deps = [":jni_dep"],
)
and running `bazel build //examples/android/java/bazel:hello_world` the x86_64 branch is erroneously selected.
According to
the docs there should be a well-behaved transition from the android_binary to the cc_library, but I would expect that transition to not set "@platforms//cpu:x86_64" but rather some ARM cpu. If I inspect the output from `bazel config` for this target it looks like this:
FragmentOptions com.google.devtools.build.lib.analysis.PlatformOptions {
experimental_add_exec_constraints_to_targets: []
extra_execution_platforms: []
extra_toolchains: []
host_platform: null
incompatible_auto_configure_host_platform: true
incompatible_override_toolchain_transition: false
incompatible_use_toolchain_resolution_for_java_rules: false
platform_mappings: platforms/platform_mappings
platforms: [@local_config_platform//:host]
target_platform_fallback: @bazel_tools//platforms:target_platform
toolchain_resolution_debug: false
toolchain_resolution_override: []
}
I think that the issue here is that "platforms" is set to something that in turn sets the constraint_value "@platforms//cpu:x86_64". I would expect the value here to instead be some Android ARM or otherwise some null value.
I understand that android_rules is not ported to utilize the Platforms concept, but I have not found a way of using Platforms with select statements of this type. Are there any known workarounds?
Regards,
Johan