Skip to content

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

Merged
merged 12 commits into from
Sep 30, 2017

Conversation

azymnis
Copy link
Contributor

@azymnis azymnis commented Sep 26, 2017

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 type proto_library. Since proto_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.

@bazel-io
Copy link

Can one of the admins verify this patch?

@ittaiz
Copy link
Contributor

ittaiz commented Sep 26, 2017

test this please (ci bot)

@azymnis
Copy link
Contributor Author

azymnis commented Sep 26, 2017

@ittaiz the build seems to have failed. Is this a macos issue?

@johnynek
Copy link
Contributor

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!

Copy link
Contributor

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

)

native.maven_jar(
name = "scala_proto_rules_slalapbc",
Copy link
Contributor

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

Copy link
Contributor Author

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"))
Copy link
Contributor

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?

Copy link
Contributor Author

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"]
)
Copy link
Contributor

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?

Copy link
Contributor Author

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

@johnynek
Copy link
Contributor

johnynek commented Sep 27, 2017 via email

@azymnis
Copy link
Contributor Author

azymnis commented Sep 27, 2017

@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.

@damienmg
Copy link
Contributor

Jenkins: retest this please

(license should be fixed on all the mac slave now)

@azymnis
Copy link
Contributor Author

azymnis commented Sep 27, 2017

@damienmg there was an error in one of my BUILD files, which I just fixed

@johnynek @ittaiz what do you think of calling the rule scalapb_proto_library?

@johnynek
Copy link
Contributor

test this please

"//external:io_bazel_rules_scala/dependency/proto/scalapb_fastparse",
]

GRPC_DEPS = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deep dependency stack. :/

Copy link
Contributor Author

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

@johnynek
Copy link
Contributor

This looks good to me.

👍

@azymnis
Copy link
Contributor Author

azymnis commented Sep 28, 2017

I just added all other available scalapbc flags to this (java_conversions, flat_package, single_line_to_string).

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 bazel clean the cause of slowness?

@johnynek
Copy link
Contributor

test this please

executable = ctx.executable._pluck_scalapb_scala,
inputs = list(acc_imports) + [argfile],
outputs = [ctx.outputs.srcjar],
mnemonic="ProtoScalaRule",
Copy link
Contributor

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?

Copy link
Contributor Author

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

@azymnis
Copy link
Contributor Author

azymnis commented Sep 29, 2017

Any ideas about what to do with build timeouts?


external_deps = list(SCALAPB_DEPS + GRPC_DEPS if (with_grpc) else SCALAPB_DEPS)

if with_java_conversions:
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good.

Copy link
Contributor Author

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

if ctx.attr.with_grpc:
flags.append("grpc")
if ctx.attr.with_java_conversions:
flags.append("java_conversions")
Copy link
Contributor

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),
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

"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),
Copy link
Contributor

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.

Copy link
Contributor Author

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.

),
"with_grpc": attr.bool(default=False),
"with_java_conversions": attr.bool(default=False),
"with_flat_package": attr.bool(default=False),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this?

Copy link
Contributor Author

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

Copy link
Contributor

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.

@johnynek
Copy link
Contributor

test this please

@googlebot
Copy link

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 cla/google commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@azymnis
Copy link
Contributor Author

azymnis commented Sep 29, 2017

@johnynek I merged your branch and this seems to have made the @googlebot unhappy

@johnynek johnynek mentioned this pull request Sep 29, 2017
@johnynek
Copy link
Contributor

it's okay, that bot's not the boss of me.

@johnynek johnynek added cla: yes and removed cla: no labels Sep 29, 2017
@johnynek
Copy link
Contributor

this is no longer WIP, right?

Ready to merge @azymnis ?

@azymnis
Copy link
Contributor Author

azymnis commented Sep 30, 2017 via email

@johnynek johnynek changed the title WIP: Create scala_proto_library rule using scalaPB Create scala_proto_library rule using scalaPB Sep 30, 2017
@johnynek
Copy link
Contributor

👍

I think I'll let @ittaiz merge #285 first (not squash/rebase I hope) then I will merge this after that.

@azymnis
Copy link
Contributor Author

azymnis commented Sep 30, 2017

@johnynek I should prob update the rule docs too in the readme. Hold off before merging till I do that

@johnynek johnynek merged commit 1a856c2 into bazel-contrib:master Sep 30, 2017
@johnynek
Copy link
Contributor

@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!

@azymnis
Copy link
Contributor Author

azymnis commented Oct 1, 2017

@johnynek no problem, happy to work on this and learn more about bazel

@ittaiz
Copy link
Contributor

ittaiz commented Oct 1, 2017

Indeed thank you for this valuable addition.
I was out of the loop due to holidays and backlog but as we (Wix) are moving a lot of our RPC to gRpc this will be heavily used.

"//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",
Copy link
Contributor

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?

Copy link
Contributor Author

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),
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@azymnis
Copy link
Contributor Author

azymnis commented Oct 1, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants