Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

Yannic
Copy link
Contributor

@Yannic Yannic commented Nov 14, 2020

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 #10005

@google-cla google-cla bot added the cla: yes label Nov 14, 2020
@Yannic Yannic force-pushed the proto_toolchain_rule branch 5 times, most recently from d7657e4 to b8355d6 Compare November 14, 2020 14:12
@Yannic Yannic mentioned this pull request Nov 14, 2020
9 tasks
@Yannic Yannic marked this pull request as ready for review November 14, 2020 14:48
@Yannic Yannic requested a review from lberki as a code owner November 14, 2020 14:48
@Yannic
Copy link
Contributor Author

Yannic commented Nov 14, 2020

@comius or @lberki PTAL, thanks!

@comius
Copy link
Contributor

comius commented Jan 14, 2021

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

@Yannic
Copy link
Contributor Author

Yannic commented Jan 14, 2021

I did choose to implement this as a native rule for two reasons:

  • It avoids exposing the porto-related command-line flags to Starlark that would tie the proto_toolchain rule to specific versions of Bazel that support these fields and that we do not want anyone to depend on, and
  • We most likely need at least a new native Provider to migrate the native protobuf rules to use the toolchain.

I absolutely do plan to rewrite this new rule in Starlark as soon as the command-line flags are removed.

@comius
Copy link
Contributor

comius commented Jan 15, 2021

I did choose to implement this as a native rule for two reasons:

  • It avoids exposing the porto-related command-line flags to Starlark that would tie the proto_toolchain rule to specific versions of Bazel that support these fields and that we do not want anyone to depend on, and

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.

  • We most likely need at least a new native Provider to migrate the native protobuf rules to use the toolchain.

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?

I absolutely do plan to rewrite this new rule in Starlark as soon as the command-line flags are removed.

Copy link
Contributor

@comius comius left a 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.

@Yannic
Copy link
Contributor Author

Yannic commented Jan 15, 2021

I did choose to implement this as a native rule for two reasons:

  • It avoids exposing the porto-related command-line flags to Starlark that would tie the proto_toolchain rule to specific versions of Bazel that support these fields and that we do not want anyone to depend on, and

Can you be a bit more specific. Are you talking about ProtoConfiguration flags?

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.

I'll go forward with the review, but I would still like to know about this.

  • We most likely need at least a new native Provider to migrate the native protobuf rules to use the toolchain.

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?

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.

I absolutely do plan to rewrite this new rule in Starlark as soon as the command-line flags are removed.

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
@Yannic Yannic changed the title Create proto_toolchain rule ProtoConfiguration: Expose some fields to Starlark Jan 26, 2021
@Yannic
Copy link
Contributor Author

Yannic commented Jan 26, 2021

Rewrote this CL to expose the fragment fields that are necessary for writing proto_toolchain in Starlark.

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 @rules_proto if that's ok

@comius PTAL

Copy link
Contributor

@comius comius left a 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.

Comment on lines +36 to +48
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");
}
}
Copy link
Contributor

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

@jin jin added the team-Rules-Server Issues for serverside rules included with Bazel label Mar 1, 2021
@sgowroji sgowroji added the awaiting-user-response Awaiting a response from the author label Oct 19, 2022
@keertk
Copy link
Member

keertk commented Dec 7, 2022

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.

@keertk keertk closed this Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-user-response Awaiting a response from the author cla: yes team-Rules-Server Issues for serverside rules included with Bazel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants