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

[Api Discussion via docs] Adding a more manual/advanced scalapb rule #763

Closed
wants to merge 3 commits into from

Conversation

ianoc
Copy link
Contributor

@ianoc ianoc commented Jun 4, 2019

In the change i made to make these rules aspect based previously it has blocked/made difficult some of scalapb's options that don't translate well into aspects (and aren't supported in the java protobuf so don't come up there). This proposes adding another rule which would give full flexibility in invoking the scalapb to cover these use cases.

Using both rules in a repo does pose the risk of classpath conflicts of multiple implementations that are different of the same class name. Though I don't see a way around this issue in general. We could have the direct rule check to ensure none of its dependencies also contain the same class name it is emitting, to ensure it doesn't depend on an aspect for the same protobuf?

Thoughts @ittaiz @simuons @johnynek ?

@ianoc ianoc requested a review from johnynek as a code owner June 4, 2019 02:12
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@ittaiz
Copy link
Member

ittaiz commented Jun 11, 2019

@ianoc thanks for taking the time!
We are interested in the aspect approach for performance and since the current approach generates multiple copies of dependent protos (causes issues in IJ as well).
We are planning towards end of next week to prototype a suggested API on how to support multiple custom generators using toolchains and aspects. We might fail but we want to give it a try :)

@ittaiz
Copy link
Member

ittaiz commented Jun 11, 2019

In general I'm not against this if you have concrete use-cases internally you're aware of.
I think that the conflict check can be valuable depending on cost (both build time and dev time)

@ianoc
Copy link
Contributor Author

ianoc commented Jun 11, 2019

We don't have them internally, the use cases that were coming up are:

#765
#753
#751

so if your work managed to cover these and we didn't need it at all that would be better again

@ittaiz
Copy link
Member

ittaiz commented Jun 12, 2019

Very interesting. #751 and #753 indeed sound very very similar to our needs and concerns.
This is what we'll try to solve (don't know if we'll be able to though).
Can you or @johnynek refresh my memory about why aspects are better?
My idea before the aspect approach was to separate the "to-be-generated" protos from the "classpath" protos (which I'm fairly certain is an option in protoc). This should solve the multiple copies of a proto appearing in the scala classpath later on and will also greatly improve performance (less generation and less compilation in the next step).

Am I missing something? Are these indeed the benefits but you think I'm mistaken about protoc support for this?

@ianoc
Copy link
Contributor Author

ianoc commented Jun 12, 2019

@ittaiz You can with protoc for sure separate out the proto's from having multiple copies. (using the internal function of src to jar thats in there now would do this). The aspects make the whole chain fully automatic which is the big win(to add the aspects to our largest scala repo i had to add the toolchain then strip the per-target options -- so a pretty simple PR, it immediately dropped 6-8 minutes off average our CI times for the repo which was super nice). Aspects make a few things better here though:

  • You don't need to define the scalapb targets at every step of the chain. In our case this is huge since we have cross language bazel dependencies/generated proto's and similar, so you can define the scalapb in the repo you need it/where you need it and all of the intermediate targets are automatically supplied
  • You don't have folks globbing protobuf files/proto_library targets out of laziness into one scalapb (well they can, but internally via the aspect thats not what will happen).
  • With the former two issues you can wind up with 2 scalapb's referring to the same proto_library without a bunch of tooling/convention to stop it. So the aspects ensure you don't get duplicated classes from this.
  • Not the aspects so much, but the fact the options are configured on the toolchain while a pain for the extra options in scalapb makes the whole repo consistent in how the scala is generated which is a plus. (Mostly here the flat_package option has caused us problems in the past)

I think mostly what I was suggesting here is pretty close to what you were thinking about doing pre-aspects here, just having a rule that wouldn't produce all the classes all the time.

Copy link
Contributor

@tian000 tian000 left a comment

Choose a reason for hiding this comment

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

LGTM. I would like to use the with_java option to be able to gradually migrate over from java protobufs.

@jsbrucker
Copy link

@ianoc any plans to pick up work on this PR again?

@ianoc
Copy link
Contributor Author

ianoc commented Jun 1, 2020

No I'm afraid there didn't seem to be a consensus on design to drive it. So I've long since moved onto other things.

@liucijus
Copy link
Collaborator

closing as stale, feel free to reopen

@liucijus liucijus closed this Jan 31, 2024
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