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

Set the compile jar to be the same as the output jar #479

Closed
wants to merge 1 commit into from
Closed

Set the compile jar to be the same as the output jar #479

wants to merge 1 commit into from

Conversation

szinn
Copy link
Contributor

@szinn szinn commented Feb 13, 2021

When kt_jvm_library is used to create a library that contains auxiliary files (lie .proto files) it does so correctly. However, when referred to via deps in the build of another module, bazel creates the -hjar file that strips these needed components from the .jar file used to link against.

This PR sets the compile / ijar resource to be the same as the created .jar file, thus eliminating this intermediate hjar creation. This is the same as a previous PR (#341)

@restingbull
Copy link
Collaborator

@jongerrish -- have a look? This would have changed during the large refactoring.

@@ -609,7 +609,7 @@ def kt_jvm_produce_jar_actions(ctx, rule_kind):

java_info = JavaInfo(
output_jar = output_jar,
compile_jar = compile_jar,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is going to make the compile jar the same as the output jar which will break the whole header / ABI jars for compile avoidance optimization.

Are you expecting any auxiliary files to be included in the compile jars? Note that the final binary (e.g: {java,android}_binary) will link in the output jar for each target, not the compile jar. That is intended only for compilation and why we do this optimization.

A test case showing what is broken would be helpful.

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, I'm expecting auxiliary files in the output_jar to be available for use by follow-on targets.

A specific example is doing a wire_proto compile which generates the jar containing the generated .class files as well as the .proto files.

A follow-on target uses takes as input this jar and requires both the .proto and .class files as input.

Without this PR, the .proto files get removed when the ijar / hjar file is generated prior to compiling the follow-on target.

An alternate solution would be to include the srcjar as an input to the follow-on target, but the output jar is really the proper generated target.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a way to force the output.jar to be used as a dep in a follow-on target build?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is wire_proto a Skylark rule?

I'm guessing that wire_proto invokes some tool to compile its local proto source into either Kotlin/Java source code or direct to JVM bytecode?

If the compiler needs access to transitive proto source, i.e: local proto source references protos in other libraries then you can make these protos available via a provider e.g: WireProtoInfo that your rule can then collect transitive instances of.

@szinn
Copy link
Contributor Author

szinn commented Feb 16, 2021

I was able to fix my wire proto bzl file to reference full_compile_jars rather than compile_jars. No need for this PR.

@szinn szinn closed this Feb 16, 2021
@szinn szinn deleted the szinn-set-compile-jar branch February 18, 2021 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants