bazel-skylib icon indicating copy to clipboard operation
bazel-skylib copied to clipboard

Add `lib/compatibility.bzl`

Open philsc opened this issue 3 years ago • 8 comments
trafficstars

This patch adds new helper macros for dealing with incompatible target skipping. Specifically, the macros help make the target_compatible_with more readable and easier to understand.

Without these helpers you are left to write verbose select() statements.

For example, you might write the following to express a target that is incompatible with QNX and bare-bones systems.

cc_library(
    name = "lib",
    srcs = ["lib.cc"],
    target_compatible_with = select({
        "@platforms//os:qnx": ["@platforms//:incompatible"],
        "@platforms//os:none": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
)

WIth one of the helpers from this patch you can instead rewrite this as:

cc_library(
    name = "lib",
    srcs = ["lib.cc"],
    target_compatible_with = compatibility.none_of(
        "@platforms//os:qnx",
        "@platforms//os:none",
    ),
)

That is now easier to understand. Especially for folks new to incompatible target skipping.

This patch is based on @trybka's trybka/bazel-skylib#1. The implementation is his. I cleaned up the tests and added documentation.

philsc avatar Aug 09 '22 05:08 philsc

Oh hey -- thanks for picking this up!

trybka avatar Aug 09 '22 15:08 trybka

If anyone has an idea why bazel is segfaulting on shutdown in one of the Windows tests, I'd appreciate it.

philsc avatar Aug 10 '22 05:08 philsc

Any of the 5 code owners interested in taking a look at this PR?

philsc avatar Aug 15 '22 18:08 philsc

@brandjon , @tetromino , @comius , @hvadehra , @c-mita , any thoughts? I am not sure what to make of the complete lack of feedback here.

philsc avatar Aug 23 '22 17:08 philsc

comius avatar Aug 24 '22 09:08 comius

Ups, wrong button.

any thoughts? I am not sure what to make of the complete lack of feedback here.

Too many reviewers - each one of them has time to review, but all of them together don't have it :)

comius avatar Aug 24 '22 09:08 comius

@comius , any thoughts?

philsc avatar Sep 09 '22 17:09 philsc

@comius , any thoughts?

I did a quick pass. Looks nice and looks ok, thanks. I'll do another more thorough pass and let you know.

comius avatar Sep 09 '22 18:09 comius