-
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
ProtoConfiguration: Expose some fields to Starlark #12484
Conversation
d7657e4
to
b8355d6
Compare
Since we have a long term plan to write everything in Starlark, it might make more sense to implement this already in Starlark in the rules_proto repository. See for example rules Scala which alread uses Starlark https://github.com/bazelbuild/rules_scala/blob/master/scala/scala_toolchain.bzl |
I did choose to implement this as a native rule for two reasons:
I absolutely do plan to rewrite this new rule in Starlark as soon as the command-line flags are removed. |
Can you be a bit more specific. Are you talking about ProtoConfiguration flags? I'll go forward with the review, but I would still like to know about this.
I also thought so and I would accept a new native Provider, however if you take a look at scala toolchain, there is a case where they don't need a new provider and can extend it with arbitrary attributes. @lberki, @katre is Scala using ToolchainInfo provider (https://github.com/bazelbuild/rules_scala/blob/master/scala/scala_toolchain.bzl#L51) in a good way by ad hoc extending it or is this going to create another technical debt?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done, thanks. But I still think, the whole PR can already be done in Starlark.
src/main/java/com/google/devtools/build/lib/rules/proto/ProtoToolchainRule.java
Outdated
Show resolved
Hide resolved
Yes, I'm talking about ProtoConfiguration options. I did experiment with exposing the fields on the fragment and writing the rule in Starlark in #9000, but it wasn't simpler than implementing it as native rule (and I never came to try out how exactly to use the Starlark toolchain from native rules). I think having this as a native rule for now is the better option.
AFAIK, ToolchainInfo is the recommended way to create toolchains in Starlark and would work if we only read the values from Starlark. However, there are native rules that would also need to access the fields of the toolchain. It's still possible, but it doesn't feel right. Once everything is migrated to Starlark, we can switch to ToolchainInfo.
|
src/main/java/com/google/devtools/build/lib/rules/proto/ProtoToolchainInfo.java
Outdated
Show resolved
Hide resolved
This change exposes the values of `--protoc` and `--proto_options` to Starlark, thus making it possible to implement `proto_toolchain` in Starlark. See bazelbuild/rules_proto#82 for the implementation of `proto_toolchain`. Working towards bazelbuild#10005
b8355d6
to
af11d09
Compare
Rewrote this CL to expose the fragment fields that are necessary for writing I also have some tests to verify that this is working as intended, but they depend on bazelbuild/rules_proto#82, so I'd like to wait until thet PR lands and we roll @comius PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything else seems fine.
public interface ProtoCommonApi extends StarlarkValue { | ||
@Deprecated | ||
@StarlarkMethod( | ||
name = "available_configuration_fields", | ||
doc = | ||
"Indicates that this version exposes fields on this configuration fragment. Do not use " | ||
+ "this field, its only purpose is to help with migration.", | ||
documented = false, | ||
structField = true) | ||
default ImmutableList<String> availableConfigurationFields() { | ||
return ImmutableList.of("protoc", "protoc_options"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my comments in bazelbuild/rules_proto#82
Hi there! Thank you for contributing to the Bazel repository. We appreciate your time and effort. We're doing a clean up of old PRs and will be closing this one since it seems to have stalled. Please feel free to reopen if you’re still interested in pursuing this or if you'd like to discuss anything further. We’ll respond as soon as we have the bandwidth/resources to do so. |
This change exposes the values of
--protoc
and--proto_options
toStarlark, thus making it possible to implement
proto_toolchain
inStarlark. See bazelbuild/rules_proto#82 for the
implementation of
proto_toolchain
.Working towards #10005