Semantics of bazel build //... with transitions

65 views
Skip to first unread message

Fabian Meumertzheim

unread,
Feb 8, 2023, 5:35:54 AM2/8/23
to bazel-discuss
Hi everyone,

An issue opened on rules_go (https://github.com/bazelbuild/rules_go/issues/3203) led to an interesting interaction between command-line target wildcard patterns and transitions that I would like to hear opinions on.

Consider the following fictitious BUILD:

foo_binary(
    name = "main",
    ...,
    transitive_defines = ["bar"],
    deps = [":lib"],
)

foo_library(
    name = "lib",
    ...
)

Now assume foo_binary internally uses a transition to apply the transitive_defines to all its transitive dependencies. Assuming further that :lib requires "bar" to be defined in order to compile, in this situation `bazel build //:main` would pass but `bazel build //...` would fail.

In this particular case this is easily worked around by adding `tags = ["manual"]` to :lib, but that doesn't scale and also risks :lib breaking without being noticed if all targets that depend on it go away. Even if the build of :lib doesn't fail outright, having it built both through :main and in the top-level configuration increases build times, often without the user being aware of this duplication.

Is anyone else experiencing this issue? Do you have thoughts on how to deal with this issue properly?

Fabian

Brentley Jones

unread,
Feb 8, 2023, 6:45:00 PM2/8/23
to bazel-discuss
rules_apple has these top-level target rules (https://github.com/bazelbuild/rules_apple/blob/master/doc/rules-ios.md#ios_build_test) to ensure the proper transition is applied to a library, so within that ecosystem it's recommended that `tags = ["manual"]` is applied to libraries and the `*_build_test` rules are caught with `//...` instead.

Brian Silverman

unread,
Feb 8, 2023, 6:49:20 PM2/8/23
to Brentley Jones, bazel-discuss
I use target_compatible_with (which triggers incompatible target skipping) extensively. I think that would address this too, by marking foo_library with target_compatible_with that only matches after the appropriate transition(s).

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/d3886088-0462-4d06-a3bd-2a38c7caba05n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages