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

Add support for generated Java code with KSP #1139

Merged
merged 4 commits into from
Apr 30, 2024

Conversation

zalewskise
Copy link
Contributor

@zalewskise zalewskise commented Mar 18, 2024

What has changed?

  • Added support for Java generated code with KSP
  • Renamed deshading to reshading to cover the case where plugins dependencies are clashing with kotlin compiler ones (proper solution would be: rules_kotlin should link the embeddable Kotlin compiler #624) and those need to be shaded.
  • Added guava shading rules
  • Added dagger code, generated with ksp plugin, to ksp sample project

Why it was changed?

  • To be able to use Dagger’s KSP processor with kt_ksp_plugin

Fixes

@zalewskise zalewskise force-pushed the ksp-java-gen branch 3 times, most recently from f6371e2 to efd7ad7 Compare March 18, 2024 23:47
@zalewskise zalewskise changed the title Add support for generating Java code with KSP Add support for generated Java code with KSP Mar 18, 2024
# the final ABI jar. Otherwise just use the KT ABI jar as final ABI jar.
if srcs.java or generated_kapt_src_jars or srcs.src_jars:
if srcs.java or generated_kapt_src_jars or srcs.src_jars or generated_ksp_src_jars:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't this essentially mean that all targets that execute KSP will be forced to run a Java compilation action even if the underlying KSP plugin only produces Kotlin or class file outputs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great point, that's correct.

I'm thinking how we could avoid that and I'm not really sure how we could get the information if the plugin is generating java code or not, without getting this provided as one of kt_ksp_plugin parameters.
Could be something like

kt_ksp_plugin = rule(
    attrs = {
        "generates_java": attr.bool(
                doc = """Runs Java compilation action for plugin generating Java output"""",
                default = False,
        ),
       ...
    }
    ...
}    

What do you think about this approach? Or maybe there is some detail information that I'm missing, that could be used to determine if we could enforce/avoid running Java compilation action for certain KSP plugins? 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Bencodes updated PR with the approach mentioned above

@zalewskise zalewskise force-pushed the ksp-java-gen branch 7 times, most recently from 10e6c02 to 4ab5cb5 Compare March 21, 2024 01:04
@zalewskise zalewskise marked this pull request as ready for review March 21, 2024 01:08
@zalewskise zalewskise force-pushed the ksp-java-gen branch 3 times, most recently from f5b40eb to 2f7e08c Compare March 28, 2024 20:21
@Bencodes Bencodes merged commit 60670b3 into bazelbuild:master Apr 30, 2024
1 of 2 checks passed
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