bazel: Cannot use target_compatible_with to ignore MacOS only targets

Description of the problem:

I’m trying to use the target_compatible_with attribute to automatically skip MacOS only targets on other platforms, but I just get an error every time. I have a simple objc_library rule with target_compatible_with = [ "@platforms//os:macos" ] but whenever I run bazel build //...:all on non MacOS platforms I get this:

ERROR: /root/.cache/bazel/_bazel_root/eab0d61a99b6696edb3d2aff87b585e8/external/local_config_cc/BUILD:47:19: in cc_toolchain_suite rule @local_config_cc//:toolchain: cc_toolchain_suite '@local_config_cc//:toolchain' does not contain a toolchain for cpu 'darwin_x86_64'
ERROR: Analysis of target '//ble/platform/macos:ble_macos' failed; build aborted: Analysis of target '@local_config_cc//:toolchain' failed

Bugs: what’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Any objc_library rule fails instead of being ignored.

objc_library(
    name = 'ble',
    target_compatible_with = [
        "@platforms//os:macos",
    ],
)

I added a simple example here: jagobagascon/bazel-target-compatible It’s just an empty objc_library rule but you can se how the Ubuntu build fails while the MacOS just works: jagobagascon/bazel-target-compatible/actions/runs/512144112

What operating system are you running Bazel on?

I’m running it on a Docker image based on ubuntu:focal-20200423, but it also happens on a GitHub-hosted ubuntu-18.04.

What’s the output of bazel info release?

release 4.0.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 30 (27 by maintainers)

Commits related to this issue

Most upvoted comments

Sorry for dropping the ball on this ticket. It’s been a busy few months. I’m resuming work on this at the end of August.

If anyone else wants to take it over in the meantime, I can totally understand that.

Thanks for the update! Happy to provide any more feedback as needed!

I updated my proof-of-concept at https://github.com/philsc/bazel/tree/unreviewed/objc_library. It now passes all the existing tests and properly skips objc_library targets. However, it’s very hacky. I need to spend some more time cleaning it up and incorporating all the ideas that @gregestren provided earlier. (also, it’s based on a ~5 month old version of master)

I’m starting to remember why I didn’t solve this the last time I looked into it. I need to understand this part of the code better in order to make changes here. The guidance @gregestren has provided helps, but I still need to understand this code better. It’s currently still a bit “magic”. In other words, I feel like I’m making progress, but it’s slow going. At the moment it’s an archeology trip.