-
-
Notifications
You must be signed in to change notification settings - Fork 286
Create scala_proto_library rule using scalaPB #281
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
Conversation
Can one of the admins verify this patch? |
test this please (ci bot) |
@ittaiz the build seems to have failed. Is this a macos issue? |
yeah, passes on linux. The bazel ci is broken (needs to accept xcode license) cc @damienmg The travis macos timed out. Maybe a transient travis issue. Will review! Thanks man, this is great! |
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.
just a couple of minor comments.
This is great! Thanks for jumping on it.
scala_proto/scala_proto.bzl
Outdated
) | ||
|
||
native.maven_jar( | ||
name = "scala_proto_rules_slalapbc", |
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.
looks like a typo here: slala
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.
Whoops let me fix
val jarOutput = args.get(0) | ||
val protoFiles = args.get(1).split(':').toList | ||
|
||
val tmp = Paths.get(Option(System.getenv("TMPDIR")).getOrElse("/tmp")) |
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 think we actually want:
System.getProperty("java.io.tmpdir")
Which I think bazel sets up correctly.
we got burned on this somewhere else in some context. Did you copy this from another rule?
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.
Yeah I copied this from the scrooge rules. Want me to fix that one too?
test/BUILD
Outdated
scala_proto_library( | ||
name = "test_proto", | ||
deps = ["//test/proto:test2", "//test/proto:test3"] | ||
) |
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.
can you add a test that creates these things in some scala code?
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.
Sure, let me do that... I'll also add a mock grpc service to see how that works too
Yeah, if you could fix the Scrooge rules it would be great.
On Tue, Sep 26, 2017 at 18:31 Argyris Zymnis ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In test/BUILD
<#281 (comment)>
:
> @@ -432,3 +435,8 @@ scala_binary(
main_class = "scala.test.BinaryDependentOnJava",
deps = [":JavaOnlySources"],
)
+
+scala_proto_library(
+ name = "test_proto",
+ deps = ["//test/proto:test2", "//test/proto:test3"]
+)
Sure, let me do that... I'll also add a mock grpc service to see how that
works too
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#281 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEJdoy4nhL1FxQ3A6Ku_VA0hMNQq5hBks5smc-fgaJpZM4PktRQ>
.
--
P. Oscar Boykin, Ph.D. | http://twitter.com/posco | http://pobox.com/~boykin
|
@johnynek so I went ahead and added support for grpc service definitions but this opens up a whole can of worms: grpc depends on a ton of dependencies that I had to pull in. Added a flag to turn grpc service stub generation on and off for a target (this is supported by scalapb compiler). I also added a test for a dumb grpc server and client. The code compiles and runs on my machine, but not sure what the easiest way would be to actually run this in CI. Anyway, let me know what you think. Not happy that we need to pull in the universe to get grpc bindings to work, but not sure that there's really anything that we can do about it. |
Jenkins: retest this please (license should be fixed on all the mac slave now) |
test this please |
"//external:io_bazel_rules_scala/dependency/proto/scalapb_fastparse", | ||
] | ||
|
||
GRPC_DEPS = [ |
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.
deep dependency stack. :/
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.
Yeah it's kind of nuts actually
This looks good to me. 👍 |
I just added all other available scalapbc flags to this ( BTW I noticed that some of the travis builds time out. Is that a regression that I introduced or has it been going on for a while? This build is really really slow. Should we maybe break it up into separate jobs? Is calling |
test this please |
scala_proto/scala_proto.bzl
Outdated
executable = ctx.executable._pluck_scalapb_scala, | ||
inputs = list(acc_imports) + [argfile], | ||
outputs = [ctx.outputs.srcjar], | ||
mnemonic="ProtoScalaRule", |
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.
should this be ProtoScalaPbRule
or something?
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.
Yeah let me rename it
Any ideas about what to do with build timeouts? |
scala_proto/scala_proto.bzl
Outdated
|
||
external_deps = list(SCALAPB_DEPS + GRPC_DEPS if (with_grpc) else SCALAPB_DEPS) | ||
|
||
if with_java_conversions: |
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 doesn't seem like a java_conversion. Could we just call this with_java
since you are creating a whole new target, no?
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.
Sure. Maybe I should just remove all the with_
prefixes?
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.
sounds good.
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.
Actually, sorry misread your comment. Sure let me just change that
scala_proto/scala_proto.bzl
Outdated
if ctx.attr.with_grpc: | ||
flags.append("grpc") | ||
if ctx.attr.with_java_conversions: | ||
flags.append("java_conversions") |
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.
how does this flat change with scalapb? It seems like you are generating the java below with a native call?
mandatory=True, | ||
allow_rules=["proto_library"] | ||
), | ||
"with_grpc": attr.bool(default=False), |
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.
can you add comments so users understand how to use each of the options, that would be good.
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.
Will do
scala_proto/scala_proto.bzl
Outdated
"with_grpc": attr.bool(default=False), | ||
"with_java_conversions": attr.bool(default=False), | ||
"with_flat_package": attr.bool(default=False), | ||
"with_single_line_to_string": attr.bool(default=False), |
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 have no idea what this might do.
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 makes scalapb generate a toString
method for generated classes that prints a single line of text. Not sure why you would want that but it is available as a compiler option.
scala_proto/scala_proto.bzl
Outdated
), | ||
"with_grpc": attr.bool(default=False), | ||
"with_java_conversions": attr.bool(default=False), | ||
"with_flat_package": attr.bool(default=False), |
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 is this?
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.
Here's where all the scalapb compiler settings are explained https://scalapb.github.io/sbt-settings.html
I'm happy to add comments for all of these
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.
yeah, adding a link to these settings in the comment would be good.
test this please |
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
@johnynek I merged your branch and this seems to have made the @googlebot unhappy |
it's okay, that bot's not the boss of me. |
this is no longer WIP, right? Ready to merge @azymnis ? |
Yup ready!
…On Fri, Sep 29, 2017 at 5:12 PM P. Oscar Boykin ***@***.***> wrote:
this is no longer WIP, right?
Ready to merge @azymnis <https://github.com/azymnis> ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#281 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAMpF-Yy86gNlQByl3mIwbSS7H8HSvViks5snYdqgaJpZM4PktRQ>
.
|
@johnynek I should prob update the rule docs too in the readme. Hold off before merging till I do that |
@azymnis thanks so much for doing this! I'll tweet about this on Monday (to maximize exposure). I think the fact that the bazel rules now support proto and grpc is a big selling point. I hope this gets us more users, bringing more testing and more contributors! Thanks again! |
@johnynek no problem, happy to work on this and learn more about bazel |
Indeed thank you for this valuable addition. |
"//src/java/io/bazel/rulesscala/io_utils", | ||
"//src/java/io/bazel/rulesscala/jar", | ||
"//src/java/io/bazel/rulesscala/worker", | ||
"//src/scala/io/bazel/rules_scala/scrooge_support:compiler", |
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.
Why does protobuf generator need to depend on scrooge?
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.
val scalaPBArgs = s"--scala_out=${flagPrefix}${scalaPBOutput}" :: protoFiles | ||
val config = ScalaPBC.processArgs(scalaPBArgs.toArray) | ||
val code = ProtocBridge.runWithGenerators( | ||
protoc = a => com.github.os72.protocjar.Protoc.runProtoc(config.version +: a.toArray), |
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 library jar brings with it the compilers for the relevant platforms right? It doesn't download anything during build time according to the running platform, right?
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 that's right. My understanding while reading the ScalaPBC doc is that it depends on protoc-bridge
and protobuf-java
which I have added as explicit dependencies.
Oh good point, it shouldn't depend on Scrooge. I'll send a fix
…On Sat, Sep 30, 2017 at 10:58 PM Ittai Zeidman ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/scala/scripts/BUILD
<#281 (comment)>
:
> @@ -21,3 +21,29 @@ scala_binary(
":generator_lib",
],
)
+
+scala_library(
+ name = "scalapb_generator_lib",
+ srcs = ["ScalaPBGenerator.scala"],
+ visibility = ["//visibility:public"],
+ deps = [
+ "//external:io_bazel_rules_scala/dependency/proto/protoc",
+ "//external:io_bazel_rules_scala/dependency/proto/scalapb_plugin",
+ "//external:io_bazel_rules_scala/dependency/proto/protoc_bridge",
+ "//external:io_bazel_rules_scala/dependency/proto/scalapbc",
+ "//external:io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java",
+ "//src/java/io/bazel/rulesscala/io_utils",
+ "//src/java/io/bazel/rulesscala/jar",
+ "//src/java/io/bazel/rulesscala/worker",
+ "//src/scala/io/bazel/rules_scala/scrooge_support:compiler",
Why does protobuf generator need to depend on scrooge?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#281 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAMpFzdDzHUSKj49JXBhBLAa8ieyNgpcks5snyoWgaJpZM4PktRQ>
.
|
This addresses issue #144
@johnynek @ittaiz I put this up to get your feedback. This currently "works" but I need to test it more rigorously, add all available options that can be passed to scalapb, etc.
Note that I'm taking a different approach to the scrooge rules: there's only one parameter that you can pass into the rule and that is
deps
, which has to be of typeproto_library
. Sinceproto_library
already does the work of figuring out all transitive proto file dependencies, there is a lot less work that this rule has to do. This would not allow for remote proto jars, but I would argue that using these is a really bad idea in the first place.Anyway, let me know what you think.