-
Notifications
You must be signed in to change notification settings - Fork 180
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
Feature Request: Negative/Not conditionals for selects
#272
Comments
selects
selects
@c-parsons @laurentlb @jin @aiuto @juliexxia Just looking at the CODEOWNERS file and thought I'd reach out to you guys directly. Is this something worth considering? |
Paging @juliexxia and @gregestren :) |
Hi @UebelAndre - someone was working on exactly this theme recently and we've exchanged a few emails. I don't know their GitHub handle but I forwarded them to this link. Stay tuned... To be clear, where does |
Hey @gregestren! Thank you so much for your reply 😄 The thing I'm currently working on is mapping arbitrary Rust cfg declarations into Bazel select statements in cargo-raze. The situation I'm running into is, when there's a cfg like the following: cfg(any(target_family = "windows", not(target_os = "ios"), not(target_arch = "powerpc")) What I'd like to do is map that to the following: selects.with_or({
(
"@io_bazel_rules_rust//rust/platform:windows",
not("@io_bazel_rules_rust//rust/platform:ios"),
not("@io_bazel_rules_rust//rust/platform:powerpc"),
): [
"my_src.rs",
],
"//condition:default": [],
}) Excusing for a second that that might not be the greatest example (though I've come across some legitimate cases of this which I'll try to find later), I do not have a way to express |
Would select({
"@io_bazel_rules_rust//rust/platform:ios": [], # empty
"@io_bazel_rules_rust//rust/platform:powerpc": [], # empty
"//conditions:default": ["my_src.rs"]
}) come? |
That does seem like it would solve for that specific example. But it's not so much how to write a specific configuration, it's trying to transcribe an arbitrary Rust configurations into a Bazel select statement such that there are no duplicated dependencies in any rendered statement. |
Here's an additional example: cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))) |
Got it. Let's wait for feedback on the proposal I mentioned in #272 (comment). |
Sounds good! Any idea when you might be able to share that proposal or do you know when a pull request might be posted? 😃 |
It's up to the author. But they basically implemented: config_setting(name = "mylib_v2", values = {...})
selects.config_setting_group(name = "mylib_v1", match_none = [":mylib_v2"]) It would probably take some poking around to see how that interacts with, e.g., |
There's another paradigm getting some attention recently about moving more complicated logic into Starlark expressions. That idea is that arbitrary boolean logic gets, well, complicated, and the more specialized APIs we need to support it the more complex our API surface area gets. And we already have an API for generic computation: Starlark. Examples: I'm not sure how that might fit here but it's an interesting idea to have one way to do all boolean logic and just invoke it where needed. |
Any updates here? 🙏 |
I haven't heard any, but I'll ping the author again. |
I have pinged them and there is some code, not yet shared, which looks pretty good. I just asked for a PR at https://github.com/bazelbuild/bazel-skylib. |
Greg, I completely agree with your general comment, and I've wondered in the past why we don't use Starlark expressions to express conditions for selects, but I think there are genuine obstacles here.
It reminds me of the situation with genrules: we all agree genrule has problems, and that Starlark expressions and formatting and templates are much richer that an ad-hoc shell/make language, but you can't easily make a one-off genrule based on Starlark expressions from within a BUILD file because there's no way to write an expression outside of a function. |
Hey, just pinging this thread. Any more updates? |
I've re-pinged the person who I think @gregestren was talking to |
As for the proposal to use Starlark expressions in select - it's an excellent idea, but it would be somewhat difficult to do, and it's unlikely to happen in the near future given current priorities. So for now, I think we'd be welcome to negative conditionals in |
Negative conditions would be solve for nearly all of my use cases so would be thrilled to see that implemented and merged. Starlark conditionals i can live without for now 😃 |
I know this is an old issue but if others fall upon this as I did (looking for logical "not" for settings / select), here is a workaround that seems to work in BUILD files (example for doing "not(msvc)":
Obviously, an actual function like "selects.not" would be obviously useful instead of this per-setting workaround. |
@mikael-s-persson and others - I know this is an old issue but we're still thinking about this. Because this continues to pop up regularly. I'm currently an advocate of just exposing As noted in #272 (comment) this still involves overhead vs. something super-cool like |
I don't have a clear proposal right now but wanted to put the request up to see if anyone else has thoughts or is interested.
I would like to use negative conditionals in selects functions. I'm not sure what that might look like. My initial thought was that there would be some string parsing done on the strings passed into the
selects
macros.Example:
To my knowledge the only way to do negative conditionals is the following which does seem to complicate potential solutions.
Perhaps in the coming days come up with a nicer proposal but I also know the owners of this project are incredibly talented people and may also already have brilliant insights on various implementations or potential issues.
Looking forward to responses 😄
The text was updated successfully, but these errors were encountered: