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

Kotlin ABI checks #919

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

sgammon
Copy link
Contributor

@sgammon sgammon commented Jan 31, 2025

Summary

Kotlin ABI Check: Checks Kotlin public library symbols for drift. Run apiCheck to make sure a change does not break downstream Java/Kotlin library consumers; run apiDump to re-seal public API lockfiles.

Initial API lockfiles were generated as well. apiCheck runs on ./gradlew check by default, preventing downstream API/ABI breakage when Pkl is used as a Maven library.

  • API Locking
    • Kotlin modules: Klib API
    • Kotlin modules: JVM API
    • Pure Java modules: JVM API
  • Tooling
    • Provide new PklExperimental annotation for opt-out of API pinning
    • Use PklExperimental as Kotlin opt-in

@sgammon sgammon changed the title feat: kotlin abi checks, initial dump Kotlin ABI checks Jan 31, 2025
@sgammon sgammon mentioned this pull request Jan 31, 2025
3 tasks
@sgammon sgammon force-pushed the feat/kotlin-abi-checks branch 3 times, most recently from 5f9dd4b to 084ebbd Compare February 3, 2025 22:11
sgammon

This comment was marked as outdated.

@sgammon sgammon force-pushed the feat/kotlin-abi-checks branch from 084ebbd to dd85a2d Compare February 3, 2025 22:55
@sgammon sgammon force-pushed the feat/kotlin-abi-checks branch from dd85a2d to 7058067 Compare February 3, 2025 23:27
Comment on lines +84 to +89
apiValidation {
ignoredProjects += listOf("bench", "docs")
nonPublicMarkers += "org.pkl.commons.annotations.PklExperimental"

@OptIn(kotlinx.validation.ExperimentalBCVApi::class) klib { enabled = true }
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's best to configure this plugin in the root build.gradle.kts, because then projects can be ignored by name. I've enabled experimental KLib validation since Pkl is well past the minimum of 1.9.20.

Comment on lines +18 to +25
/**
* Marks experimental APIs in Kotlin or Java. Such APIs may be publicly exposed by the Pkl project,
* but are not provided with a stability guarantee, and require opt-in use from Kotlin.
*/
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.BINARY)
annotation class PklExperimental
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this annotation is added as an escape hatch for public API pins. it can be used like this:

@PklExperimental
public class SomeClass {
  // ...
}

Then, in user code:

@OptIn(PklExperimental::class)
fun someUserFunction {
  // usage of an experimental type
  val x = SomeClass()
}

Omission of the @OptIn generates a compile-time warning, and any type annotated with @PklExperimental is omitted from API pins.

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.

1 participant