Open alexander-shiryaev opened 1 year ago
Would https://github.com/bazelbuild/bazel-skylib/pull/440 help with your use case?
@fmeum Actually it would not help, because I want a calculated string (and by "calculated" I mean target-provided), not a user-defined one.
To be clear,
You're saying you'd like
my_target(
name = "value_provider",
value = "the actual value"
when can be referenced by any string attribute on any other target, and resolves that attribute to "the actual value"?
@gregestren
Yes, exactly (but the underlying provider should be public). That would allow a lot of interesting patterns, like analyzing targets in transitions.
cc_shared_library(
name = "mylib",
shared_lib_name = resolve_feature_flag("mylib_name"),
)
Feature will help me too! @gregestren, maybe it will be possible to include it in the new release?
Aside from the implementation, what use case are you trying to solve?
@gregestren Are you asking me or @TsynkPavel?
Either! I'm wondering if other Starlark tricks could also fulfill it.
I want to be able to pass calculated values to rule attributes. This will allow me to examine these values in transitions. In particular, I want to pass to transition the index of the field that should be removed from the string_list. And I currently have no other way than to create a bunch of config_setting
s (as in the example in the original post). Which, of course, negatively affects overall performance.
Description of the feature request:
I would like to pass a computed string to an arbitrary rule. If the string can only take a finite number of values, the problem can be solved by implementing a rule that returns
config_common.FeatureFlagInfo
and a set ofconfig_setting
, one for each of the allowed values (seeresolve_feature_flag_emulation
).However, if the string can have an unlimited number of values, there is currently no way to achieve the desired functionality.
In this example, you can see how the value of the
shared_lib_name
attribute should be computed based on the givenstring_flag
.My suggestion is to implement the
resolve_feature_flag
operator, which would function similarly toselect
and convert the value fromconfig_common.FeatureFlagInfo
to a string, similar to howresolve_feature_flag_emulation
works. However, it should support an unlimited set of values.What underlying problem are you trying to solve with this feature?
I want to have an ability to pass computed values to the rule attributes.
What is the output of
bazel info release
?release 6.1.0
Have you found anything relevant by searching the web?
No.
Any other information, logs, or outputs that you want to share?
Code for this proposal: https://github.com/alexander-shiryaev/bazel_issue/tree/main/feature_request/feature_flag_value