bazelbuild / rules_swift

Bazel rules to build Swift on Apple and Linux platforms
Apache License 2.0
311 stars 134 forks source link

Applying swift.opt_uses_osize recursively to dependencies #492

Open michaeleisel opened 4 years ago

michaeleisel commented 4 years ago

Typically when my co-workers and I are picking between -O and -Osize, we think about it at the app level and not the module level. If one wants to use -Osize, they would generally want to use it everywhere and not just for specific modules. However, it seems like when this feature is applied to a swift rule, it only affects that rule, and not its recursive dependencies. It would be nice to have some way for the feature to propagate to them.

keith commented 4 years ago

You should pass --feature=swift.opt_uses_osize in your .bazelrc or something instead of adding them in the features = [], array

michaeleisel commented 4 years ago

this would apply globally though, no? which would include apps that we want to use -O for

keith commented 4 years ago

If you had 2 apps, one that wanted this and one that didn't, and they shared dependencies, and you built both at the same time, what flags would the shared dependencies get? or would you build them twice?

michaeleisel commented 4 years ago

they would be built twice

keith commented 4 years ago

I don't think bazel has the ability to do this kinda thing 🤔 without maybe creating a macro that created 2 underlying rules, one for each config

keith commented 4 years ago

For us passing the top level feature works because we never build multiple prod versions of the app in the same invocation

michaeleisel commented 4 years ago

i see, yeah i guess invocation level will do what i want. i just didn't want .bazelrc since then it would apply across multiple invocations. i think it's an adequate solution

keith commented 4 years ago

Yea makes sense. I do think there's room for a bazel improvement here

segiddins commented 4 years ago

I don't think bazel has the ability to do this kinda thing 🤔 without maybe creating a macro that created 2 underlying rules, one for each config

This is exactly what configuration transitions are for

keith commented 4 years ago

how would that setup look?

segiddins commented 4 years ago

It doesn't work with features (they don't propagate down), but you could define a starlark build flag that's used in a transition and then read in a rule implementation

keith commented 4 years ago

I wonder if any other languages solve this in bazel?

segiddins commented 4 years ago

It's how things like CPU and deployment target are propagated for C++/Swift.

keith commented 4 years ago

Sorry I meant more for optimization stuff