-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Expose proto fragment fields necessary for writing proto_toolchain to Starlark #9000
Expose proto fragment fields necessary for writing proto_toolchain to Starlark #9000
Conversation
src/main/java/com/google/devtools/build/lib/skylarkbuildapi/proto/ProtoModuleApi.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/skylarkbuildapi/ProtoConfigurationApi.java
Show resolved
Hide resolved
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.
Mind also adding some rudimentary tests?
@SkylarkConfigurationField( | ||
// Must match the value of `_protoc_key` | ||
// in `@rules_proto//proto/private/rules:proto_toolchain.bzl`. | ||
name = "protoc_do_not_use_or_we_will_break_you_without_mercy", |
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.
What's the plan for this command line option?
The usual thing we do is to have rules like CcToolchainAliasRule
, although those can just as well be implemented in Starlark. That way, you don't need to have a late-bound default. Even better, you can prescribe a particular name for that rule so that people use it as little as possible (although we don't do that for the rest of the alias rules)
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.
All of these options here are meant for use in a new proto_toolchain
rule that is eventually going to replace the command-line options.
i.e. Now, proto_toolchain
exposes the options and looks like this: https://github.com/bazelbuild/rules_proto/blob/919671ef0f73f5a82037eaabedc39c938c13cf60/proto/BUILD#L8, and eventually, it will look like this, and the command-line options are deprecated and removed:
proto_toolchain(
name = "default_toolchain_impl",
compiler = "@com_google_protobuf//:protoc",
protocopt = ["--foo", "--bar"],
strict_deps = "ERROR",
visibility = ["//visibility:public"],
)
I guess we could also implement proto_toolchain
as native rule first, but since we're going to replace it with a Starlark rule eventually, we can also implement it Starlark now.
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.
Oh my question I already sent is answered here :) So you plan to replace command line options completely?
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.
Yes, long-term (>1y), I'd like to get rid of the (native) command-line options.
return "OFF"; | ||
|
||
case WARN: | ||
return "WARN"; |
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.
Do we actually use "WARN"? AFAIU it's only used for the Java sandwich, but that's passed in from Starlark. And if not, how about using a Boolean?
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.
Today, WARN==ERROR
(and DEFAULT==OFF
[1], but the default value for --strict_proto_deps
is error 🤷♀). I'd like proto_library
to support WARN
eventually, and also print some nice buildozer commands when there are errors or warnings, similar to what Java does.
src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/skylarkbuildapi/ProtoConfigurationApi.java
Show resolved
Hide resolved
doc = "Do not use this field, its only purpose is to help with migration of " | ||
+ "Protobuf rules to Starlark.", | ||
structField = true) | ||
default void configurationFieldProtocExists() {} |
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.
What's this used for? To check for the presence of other fields? Then why not check directly for their presence instead?
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.
This is used to check whether --proto_compiler
is available. Unfortunately, it's the only way to feature-detect late-bound defaults. https://github.com/bazelbuild/rules_proto/blob/919671ef0f73f5a82037eaabedc39c938c13cf60/proto/private/rules/proto_toolchain.bzl#L35
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.
Alternative is to check for Bazel version (like we do e.g. here: https://github.com/bazelbuild/rules_rust/blob/master/rust/private/rustc.bzl#L138). That requires creating an external repository to write the bazel version.
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.
cc @laurentlb your thoughts on this? This is an example of users having to jump through hoops because we don't have a way to test if constant is defined?
@SkylarkCallable( | ||
// Must match the value of `_protocopt_key` | ||
// in `@rules_proto//proto/private/rules:proto_toolchain.bzl`. | ||
name = "protocopt_do_not_use_or_we_will_break_you_without_mercy", |
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.
@hlopko , how about living without the scary "this is not a supported API" suffix?
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.
I thought you like these suffices :) For my perspective I don't think this can cause too much trouble if we expose it under short name. And removing the option using an incompatible flag won't be too bad either. So feel free to use the short name Yannic, if you don't feel strongly.
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.
I don't feel strongly either way. @lberki originally suggested them, so it's your call whether we use long or short names :). I'd like to keep the access them through proto_toolchain
-suggestion, though.
Thanks! I'll add some tests to verify the fields are there and return the correct values. As I said, the goal is to eventually remove the command-line options, thus the fields, so I'd like to keep the usage as low as possible. |
Do we want to remove the command-line options? I thought |
When I talked about removing command-line options, I was talking about the native ones in The reason I'm submitting this PR is to get the work on rewriting |
Is this PR about preparing for |
This is about creating |
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.
Added some tests and comments. ptal.
src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java
Outdated
Show resolved
Hide resolved
return "OFF"; | ||
|
||
case WARN: | ||
return "WARN"; |
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.
Today, WARN==ERROR
(and DEFAULT==OFF
[1], but the default value for --strict_proto_deps
is error 🤷♀). I'd like proto_library
to support WARN
eventually, and also print some nice buildozer commands when there are errors or warnings, similar to what Java does.
@lberki Friendly ping? |
ping |
Closing in favor of #10937 |
This change exposes some of the Protobuf-related command-line flags to Starlark.
There is a risk of adding these fields, so we gave them a scary name and documented how users are supposed to access them. Hopefully, this will be enough to fight Hyrum's Law.
Blocking #10006
Working towards #10005
Design doc:
https://docs.google.com/document/d/1u95vlQ1lWeQNR4bUw5T4cMeHTGJla2_e1dHHx7v4Dvg/edit#