Skip to content

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
# If there is Java source or KAPT/KSP generated Java source compile that Java and fold it into
# 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 requested a review from Bencodes 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
@restingbull restingbull self-assigned this Apr 26, 2024
@Bencodes Bencodes self-assigned this Apr 30, 2024
@Bencodes Bencodes merged commit 60670b3 into bazelbuild:master Apr 30, 2024
@zalewskise zalewskise deleted the ksp-java-gen branch June 7, 2024 21:55
cgruber added a commit that referenced this pull request Mar 18, 2025
As of #1139 ksp plugins which generate Java seem to be supported.
@cgruber cgruber mentioned this pull request Mar 18, 2025
Bencodes pushed a commit that referenced this pull request Mar 18, 2025
As of #1139 ksp plugins which generate Java seem to be supported.
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