question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accept config_settings in target_compatible_with

See original GitHub issue

Description of the feature request:

bazel 4.0 adds a target_compatible_with common attribute that accepts a list constraint_values. It would be great if it could also accept config_settings.

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

I would like to mark a target to be compatible only if :my_config_setting is true, so that the target itself and all inverse dependencies don’t build otherwise.

I can currently work around this by translating a config_setting into a constraint_value by select()ing the constraint_setting’s default_constraint_value. But apparently constraint_settings are supposed to be configuration independent, so that workaround is bad style:

config_setting(
  name = "my_config",
  ...
)
constraint_setting(
  name = "my_constraint",
  default_constraint_value = select({
    ":my_config": ":my_value",
    "//conditions_default": None,
  }),
)
constraint_value(
  name = "my_value",
  constraint_setting = ":my_constraint",
)
cc_binary(
  ...
  target_compatible_with = [
    # feature request: allow ":my_config" here instead
    ":my_value",
  ],
)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
chsiggcommented, Dec 6, 2020

Ha! Thanks a lot for thinking of this Philipp.

Yes, selecting on the target_compatible_with would be a perfectly fine alternative. I don’t mind the helper function.

In fact, that’s what I used before I realized that you can (currently, and I hear it might go away) select on the default_constraint_value. But by the time I wrote this issue I had already forgotten 😦

I’m happy with Philipp’s approach and as far as I’m concerned you can close this issue.

Thanks for your help!

0reactions
gregestrencommented, Dec 7, 2020

Closing as acknowledged.

To be clear, my preference is to try to limit built-in Bazel support to constraint_value and the mentioned to-be-implemented toolchain properties.

I like that a reasonable user-space approach was identified here, so you can get what you need without stretching Bazel’s core API complexity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found