bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Report build error if target dependency chain contains conflicting constraints

Open tgeng opened this issue 1 year ago • 1 comments

Description of the feature request:

Consider the following

constraint_setting(
    name = "type",
)

constraint_value(
    name = "type_a",
    constraint_setting = ":type",
)

constraint_value(
    name = "type_b",
    constraint_setting = ":type",
)

py_library(
    name = "foo",
    srcs = ["foo.py"],
    target_compatible_with = [":type_a"],
)

py_library(
    name = "bar",
    srcs = ["bar.py"],
    deps = [
        ":foo",
    ],
    target_compatible_with = [":type_b"],
)

Target bar is ill-defined because there is no way for any platform to satisfy its constraints: bar needs :type_b while its dependency foo needs :type_a.

Building foo or bar specifically would fail as expected. But invoking bazel build ... would happily skip bar yet not reporting any errors. It would be nice if Bazel can proactively check such impossible constraints because such declarations would always be a user error.

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

We are using target_compatible_with to suppoort multi-architecture and multi-platform builds and we would like to surface any configuration errors like above when user invokes bazel build ....

Also, it would be nice if anyone can suggest a method to detect such problems. I don't know enough about Bazel internals to be able to come up with a way to detect such problems.

Which operating system are you running Bazel on?

macOS

What is the output of bazel info release?

release 6.0.0-pre.20220823.1

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

I haven't found anything related to this.

Any other information, logs, or outputs that you want to share?

No response

tgeng avatar Sep 15 '22 04:09 tgeng

It's not obvious that this is strictly an error or that the target should be skipped, or even if the outer target should build, but with one less dependency. It made us think about the need for a configuration linter or analyzer that can show what would happen here. I'm not turning that into a distinct feature request because I think we can do it with a cquery script. I'm going to leave this as a low priority idea to look at next quarter.

aiuto avatar Sep 16 '22 15:09 aiuto

Any hints on how I can detect this with a cquery script?

tgeng avatar Sep 27 '22 00:09 tgeng

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

github-actions[bot] avatar Dec 01 '23 01:12 github-actions[bot]

Making this situation an error in some way is actually the preferred solution to https://github.com/bazelbuild/bazel/issues/18707#issuecomment-1819575576 now.

fmeum avatar Dec 01 '23 07:12 fmeum