-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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: allow nested selects. #1623
Comments
@lberki following from last issue |
I don't think there is a philosophical objection against this, it just needs to be implemented. |
A workaround in some cases is to add a new target. Assume you want: cc_library(
name='foo',
defines=if_a(if_b(['-DAB=1']))
) Then a virtual target cc_library(
name='foo_a',
defines=if_b(['-DAB=1'])
)
cc_library(
name='foo',
deps=if_a(['foo_a']),
) |
Right, this is similar to AND chaining of The only philosophical caution I would mention about nested selects is the possibility of freezes or OOMs under certain obscure circumstances. Long story short is that certain build phases - most notably Bazel query - don't know which As for implementation challenge, I think a simple version of this wouldn't be too hard. The biggest concern is that
would be a lot harder than
|
So I proof-of-concepted nested selects: check out https://bazel-review.googlesource.com/c/bazel/+/44230/1#message-c2bbb6b8973380ea2eb65483e2364f600c07f295 Short story is the basic change is surprisingly easy. But there are a bunch of corner cases that substantially complicate it. So I put up this change as a starting point for further discussion and consensus. If anyone really wants nested selects, this is a good time to speak up. |
Present and accounted for! |
Christopher, Thanks so much for your input. We had some good conversation on the review thread linked from two comments ago, so I think there's some comfort about the concern of this making build files less readable. And it looks like your post is pretty thumbs up popular. Would you mind giving me more detail on what you'd like to do with this feature? |
Sure thing! We are primarily a Linux dev house. We've got some third party C++ libraries that make heavy use of Now we would like to support Windows as a native development platform. We're using If we had nested |
@gunan could you chime in with your requirements? I remember TF asking for this a year ago, and also recently. |
For TF, in our BUILD rules we manage a lot of configurations that are orthogonal to each other, such as CPU architecture, operating system, GPU, additional library support. Having nested selects will greatly improve readability and managability of our BUILD configs. |
While not quite the same as the prototype described in #1623 (comment), I just added a draft proposal to support Please do check it out and let me know where it helps and where it falls short. The main advantage of that vs. the nested select prototype is all the code is already written for the chaining. :) Proper nested select support has been blocked on the simple fact that it's a more concerted development effort. I'd still love to finish that out to production quality but it's hard for me to provide an ETA for that. Nevertheless, this remains on my radar. If anyone else has spare cycles earlier and wanted to make it happen I'd be happy to advise / review as well. |
We need support for nested selects. Our products are written in C and run on our proprietary hardware, which is very resource constrained. To get good build and test performance, we want to build minimal unit test binaries that only contain a production .c file, a test .c file, and mocks of all used functions. We only want to use public .h files and defines from We use a library macro that wraps |
If all the macro is doing is emptying out |
The same macro is used both in production and unit test builds. In production builds, However, there might be other ways to solve our use case. |
We have investigated alternatives to other use case, but it looks like we need support for nested Here is a summary of our use case, if my previous posts were hard to follow: We use a macro around |
@emusand what about this? def emptyable_cc_library(**kwargs):
name = kwargs["name"]
args_with_srcs = dict(kwargs)
args_with_srcs["name"] = name + "_with_srcs"
args_without_srcs = dict(kwargs)
args_without_srcs["name"] = name + "_without_srcs"
args_without_srcs["srcs"] = []
native.alias(
name = name,
actual = select({
":foo": ":" + args_with_srcs["name"],
":bar": ":" + args_without_srcs["name"]
}))
native.cc_library(**args_with_srcs)
native.cc_library(**args_without_srcs) I tried this in a sample repro and it worked fine (a Sorry to keep pushing back. In spite of my earlier enthusiasm I'm less convinced there'll be appetite to natively support nested selects. The reasons being
I think that empowers most cases. While it's true that's more complex than native direct support, we can abstract this away with predefined libraries and best practice patterns (like in Skylib). If you think of this stuff as features on a product that feels like unnecessary complexity. But if you think of it as a programming language (which it is), this is the standard way to extend and support new patterns, for a system that's already powerful enough to model new functionality with its existing feature set. So it becomes a challenge of designing clear, extensible patterns vs. trying to stuff all the complexity directly into the core. |
@gregestren thank you for the idea, and thank you for pushing back :) We also found another solution to our use case. So my previous posts were immature - we can avoid using nested |
For all the reasons discussed here, I'm going to close this. While technically possible, from a design and UI perspective we need a very high bar for considering direct support of nested selects. We have enough alternative approaches now that heavily mitigate the problem. I think future bugs should carefully demonstrate the deficiencies of other approaches and consider what enhancements to them are possible before coming back to this theme. |
Hi. :)
Are there others other than #1623 (comment)? This solution seems fine, except that (My thought was to empty the "bad" one's srcs, but it doesn't work if srcs might have any selects inside it. Turtles all the way down.) |
Current recommended practice is to try using https://github.com/bazelbuild/bazel-skylib/blob/master/docs/selects_doc.md. If you need both cc_libraries to exist, then I agree One option could be #3780, which @philsc is diligently working on in a PR (and might be a presentation at this year's BazelCon). This will fulfill a long-needed ability to skip some targets for Another option could be to write the libraries in different packages so Why doesn't emptying the srcs work in your case? |
I'll keep an eye on #3780; thank you for the link.
If |
Currently, if one writes a helper function that wraps a
select()
, he must clearly document where he used thatselect
. For example:where one can use
foo("bar", ["bar_arm.cc"], ["bar_x86.cc"])
, but cannot use, since
select()
cannot nest.Thus, in this feature request, I propose allowing nested selects. Since selects work on user inputs, in almost all practical situations, even nested selects would be pretty simple and in small scale. Allowing selects to nest would only provide flexibility to the user, and would not cause more slowdown than implemented otherwise.
Therefore, I believe allowing nested
selects
does not contradict with any existing Bazel philosophy, and could provide additional productivity.The text was updated successfully, but these errors were encountered: