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

Allow filtering of expanded targets according to the available exec configuration (like target_compatible_with but for exec) #16206

Closed
sitaktif opened this issue Sep 2, 2022 · 3 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Configurability platforms, toolchains, cquery, select(), config transitions type: feature request

Comments

@sitaktif
Copy link
Contributor

sitaktif commented Sep 2, 2022

Description of the feature request:

The target_compatible_with attribute allows skipping targets (and targets that transitively depend on it) when using target pattern expansion (e.g. //...), which is great.

Now, it appears that exec_compatible_with does not work that way: it adds constraints, but still includes the target (and targets that transitively depend on it) during target pattern expansion. In other words, if we don't have any way to satisfy these exec constraints, the build will fail (No matching toolchains) instead of skipping the target.

The suggested feature is to achieve the equivalent of target_compatible_with but for the exec config.

What underlying problem are you trying to solve with this feature?

As a user, I want bazel build //... to be successful both locally on macos and on Linux for my repository, even if that means skipping some targets that I would otherwise not be able to build on a given platform. Note that this is a goal stated in https://bazel.build/community/roadmaps-configurability#goal.

One of the targets in my repository builds a docker image and depends on a binary in a "Linux OS" configuration; unfortunately we do not support cross-compiling this binary from macos to Linux. So I would like this target to be skipped when running it on a Mac.

In summary, I would like to be able to say "when running bazel build //..., don't build this target (nor its dependents) if you can't find executors that satisfy the Linux OS constraint".

(another problem that might be worth solving is the fact that target_compatible_with and exec_compatible_with are not doing equivalent things with target and exec configurations despite having having equivalent option names)

Which operating system are you running Bazel on?

Mac, Linux

What is the output of bazel info release?

release 5.1.1

Have you found anything relevant by searching the web?

Related to #10945 (target_compatible_with implementation).

@sgowroji sgowroji added type: feature request team-Configurability platforms, toolchains, cquery, select(), config transitions untriaged labels Sep 2, 2022
@aiuto aiuto added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Sep 16, 2022
@katre
Copy link
Member

katre commented Sep 19, 2022

target_compatible_with and exec_compatible_with have similar names but actually do different things, which I agree is unfortunate.

It's a bit tricky to figure out how to change from "no toolchains found" errors to skipping targets, since the skipping logic is at a much earlier and higher level in the code. Also, given that toolchains can be optional, this may not be detected at all.

I'm going to close this for now, but if you have a concrete proposal or further ideas feel free to reply further.

@katre katre closed this as completed Sep 19, 2022
@rosds
Copy link

rosds commented Mar 21, 2023

I was also recently surprised with this behavior. In my case, I have a code generator that only runs in x86, but the generated code can be compiled and run in many targets. If I understand correctly, this means that my code generator is exec_compatible_with = [ "@platforms//cpu:x86_64" ]. I would expect that running bazel build //... in a aarch64 host would just skip the generation of the code and also the target that depends on the generated code.

@jesses-canva
Copy link

@rosds I think your code generator needs target_compatible_with = ["@platforms//cpu:x86_64"] and depended on via cfg = "exec" (or via tools of a genrule).

exec_compatible_with would be for the platforms where the code generator can be built, not the platforms it can run on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Configurability platforms, toolchains, cquery, select(), config transitions type: feature request
Projects
None yet
Development

No branches or pull requests

6 participants