rules_kotlin icon indicating copy to clipboard operation
rules_kotlin copied to clipboard

Add support for experimental treatInternalAsPrivate and removePrivateClasses in abi.jar

Open rbeazleyspot opened this issue 11 months ago • 2 comments

This is in relation to https://youtrack.jetbrains.com/issue/KT-65690 and https://youtrack.jetbrains.com/issue/KT-64590

Current ABI jar generation includes not only public classes but internal and in some instances private which I belives can lead to unnecessary build invalidations.

As far as I can tell we would need to include optional configuration of the jvm-abi plugin in or around here

You might expect something along these lines in that file

plugin(plugins.jvmAbiGen) {
  flag("outputDir", directories.abiClasses)
  if(task.info.publicOnlyAbiJar) {
    flag("treatInternalAsPrivate", "true")
    flag("removePrivateClasses", "true")
   }
}

I think it would make sense to bundle both these plugin options behind one experimental flag on the rule.

Your thoughts on this?

Im currently exploring how this might look in the codebase but progress is slow (however I do have a failing test for the core part of this)

rbeazleyspot avatar Dec 16 '24 17:12 rbeazleyspot

If I get this to work im thinking of extending the CompilationTaskInfo proto with

    bool public_only_abi_jar = 12;

and adding this attribute to kt_toolchain

        "experimental_use_public_only_abi_jars": attr.bool(
            doc = """Compile using public only abi jars.
            This applies the following two compiler plugin options.
            plugin:org.jetbrains.kotlin.jvm.abi:treatInternalAsPrivate=true
            plugin:org.jetbrains.kotlin.jvm.abi:removePrivateClasses=true
            Can be disabled for an individual target using the tag.
            `kt_abi_plugin_incompatible`""",
            default = False,
        ),

plus all the other bits, however I think these are the ones worth early discussion

rbeazleyspot avatar Dec 16 '24 17:12 rbeazleyspot

Ive opened a draft pr for your consideration

rbeazleyspot avatar Dec 18 '24 16:12 rbeazleyspot

implemented in #1248

rbeazleyspot avatar Jun 23 '25 09:06 rbeazleyspot