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

JDK 21 toolchain #876

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

Conversation

sgammon
Copy link
Contributor

@sgammon sgammon commented Jan 6, 2025

Summary

This PR updates dependencies and build process for Pkl to bring GraalVM and Truffle support up to their latest versions. Today, Pkl builds against Java 17+, and requires Java 17+ to run.

After merging this PR, Pkl would build against Java 21, test against Java 21, and impose no change to lib consumers (i.e. still only requiring Java 17+ to run or transitively compile against Pkl).

Test downstream here (updated), via Github Actions. On that fork PR, the change set is expressed in full, with fixups.

PR Tree

Rationale

  • Gradle Toolchains: Uses Gradle's toolchains feature to provision and use different versions of the JDK.

  • JDK 21 Toolchain: Builds (and tests) occur under JDK 21, with bytecode targeting JVM 17. Build bytecode adopts JVM 21 to accelerate build tooling with no change to lib consumers.

  • Truffle SVM Dependency: Certain superclasses used by Pkl (notably, AbstractTruffleException and TruffleFeature) have moved to the new org.graalvm.nativeimage:truffle-runtime-svm coordinate.

  • Multi-JDK testing: Adds stronger guarantees for backward compatibility with regard to Pkl and JVM execution (i.e. java -jar ... with a fat JAR). Tests against versions 18-23 with test suites and java -jar ... executions.

  • Flags and JSR305 compat for kotlinc: Applies -Xjsr305=strict support for Pkl's own annotations, org.pkl.core.util.Nullable and org.pkl.core.util.Nonnull. Java parameter names are retained in Kotlin bytecode, enabling smoother Java/Kotlin interop and debugging.

  • 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.

Known Issues

  • Failing Tests (pkl-gradle)
  • Exports on JVM17: Running against newer Truffle on JVM17 may need --add-exports=...

Pre-merge Checklist

  • Refresh Gradle lockfiles and review

Changelog

  • feat: support for jvm21+ toolchain
  • feat: support for gradle toolchains
  • feat: pass -PnativeArch=native to build with -march=native
  • test: multi-jdk testing support
  • feat: jsr305 compat for kotlinc
  • feat: upgrade to latest truffle api, dsl
  • feat: kotlin abi checks, initial dump
  • fix: remove mrjar classes at >jvm17 from fatjars
  • fix: use jdk21 to run the tests (needed for Unsafe.ensureInitialized)
  • fix: truffle svm dependency is required after graalvm 24.0.0
  • fix: warnings for gvm flag usage, renamed truffle svm macro
  • fix: build with --add-modules=jdk.unsupported where needed
  • fix: don't use gu tool for modern graalvm versions
  • chore: buildinfo changes for JVM targets, toolchains
  • chore: bump graalvm/truffle libs → 24.1.2
  • chore: update circleci jobs for multi-jdk testing

@sgammon sgammon force-pushed the feat/jvm21plus-upstream branch from 8c2a05f to dc45756 Compare January 6, 2025 04:52
@sgammon sgammon changed the title feat: jvm 21+ support JVM 21+ support Jan 6, 2025
@sgammon sgammon mentioned this pull request Jan 6, 2025
buildSrc/src/main/kotlin/BuildInfo.kt Show resolved Hide resolved
buildSrc/src/main/kotlin/BuildInfo.kt Outdated Show resolved Hide resolved
buildSrc/src/main/kotlin/InstallGraalVm.kt Show resolved Hide resolved
gradlew Outdated Show resolved Hide resolved
pkl-cli/pkl-cli.gradle.kts Show resolved Hide resolved
pkl-cli/pkl-cli.gradle.kts Show resolved Hide resolved
pkl-cli/pkl-cli.gradle.kts Show resolved Hide resolved
pkl-cli/pkl-cli.gradle.kts Outdated Show resolved Hide resolved
pkl-executor/pkl-executor.gradle.kts Outdated Show resolved Hide resolved
@bioball bioball changed the title JVM 21+ support JVM 22+ support Jan 6, 2025
@bioball
Copy link
Contributor

bioball commented Jan 6, 2025

This is great, thanks, Sam!

I will do a review of this by next week.

FYI: Pkl today supports Java 21. The range enabled here is Java 22+ (updated your PR title).

settings.gradle.kts Outdated Show resolved Hide resolved
@sgammon

This comment was marked as outdated.

@StefMa
Copy link
Contributor

StefMa commented Jan 6, 2025

@sgammon feel free to extract the toolchain support into another PR. Indeed, my PR is quited dated. I will close it...

@sgammon
Copy link
Contributor Author

sgammon commented Jan 6, 2025

@StefMa roger, no worries :) I am a well known offender in that regard

@sgammon sgammon force-pushed the feat/jvm21plus-upstream branch from dc45756 to 1982880 Compare January 6, 2025 22:00
@sgammon

This comment was marked as outdated.

@sgammon

This comment was marked as outdated.

Copy link
Contributor

@bioball bioball left a comment

Choose a reason for hiding this comment

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

Thanks for this!

Also, general note: we'll need to set up our CI to use Java 21 to compile (for various compileJava tasks), and ideally to test with all of JDK 17/21/22+. I actually think toolchains probably makes sense for this, so, I'd be okay with the toolchain changes coming back into this PR.

With toolchains, maybe the version of Java used for tasks.test can come from a build flag.

gradlew Outdated Show resolved Hide resolved
buildSrc/src/main/kotlin/pklFatJar.gradle.kts Show resolved Hide resolved
gradle/libs.versions.toml Outdated Show resolved Hide resolved
pkl-cli/pkl-cli.gradle.kts Outdated Show resolved Hide resolved
buildSrc/src/main/kotlin/pklFatJar.gradle.kts Outdated Show resolved Hide resolved
@sgammon sgammon changed the title JVM 22+ support JDK 21+ toolchain Jan 22, 2025
@sgammon sgammon force-pushed the feat/jvm21plus-upstream branch from 1982880 to a314e92 Compare January 22, 2025 06:12
pkl-cli/pkl-cli.gradle.kts Outdated Show resolved Hide resolved
buildSrc/src/main/kotlin/BuildInfo.kt Outdated Show resolved Hide resolved
buildSrc/src/main/kotlin/BuildInfo.kt Outdated Show resolved Hide resolved
buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts Outdated Show resolved Hide resolved
buildSrc/src/main/kotlin/pklKotlinLibrary.gradle.kts Outdated Show resolved Hide resolved
settings.gradle.kts Outdated Show resolved Hide resolved
@sgammon sgammon requested a review from bioball January 22, 2025 06:26
@sgammon

This comment was marked as outdated.

@sgammon sgammon changed the title JDK 21+ toolchain JDK 21 toolchain Jan 22, 2025
@sgammon

This comment was marked as outdated.

@sgammon sgammon force-pushed the feat/jvm21plus-upstream branch from f9daed3 to 263588b Compare January 23, 2025 05:19
Copy link
Contributor Author

@sgammon sgammon left a comment

Choose a reason for hiding this comment

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

Initial support for multi-JDK testing. Runs testsuites as well as pkl-cli execution tests across JDK 18-23 (with JDK22 and JDK23 as experimental targets, so failures do not block the build).

This change is isolated to one commit so that it can be dropped or included here easily.

settings.gradle.kts Outdated Show resolved Hide resolved
pkl-cli/pkl-cli.gradle.kts Outdated Show resolved Hide resolved
pkl-executor/pkl-executor.gradle.kts Outdated Show resolved Hide resolved
buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts Outdated Show resolved Hide resolved
buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts Outdated Show resolved Hide resolved
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
@sgammon sgammon force-pushed the feat/jvm21plus-upstream branch from 8bfd605 to d087ea6 Compare January 24, 2025 01:25
@sgammon
Copy link
Contributor Author

sgammon commented Jan 24, 2025

Rebased against main to pick up #900

Signed-off-by: Sam Gammon <sam@elide.dev>
Signed-off-by: Sam Gammon <sam@elide.dev>
Comment on lines +186 to +193
private fun labelForVendor(vendor: JvmVendorSpec): String =
when (vendor) {
JvmVendorSpec.AZUL -> "Zulu"
JvmVendorSpec.GRAAL_VM -> "GraalVm"
JvmVendorSpec.ORACLE -> "Oracle"
JvmVendorSpec.ADOPTIUM -> "OpenJdk"
else -> error("Unrecognized JDK vendor: $vendor")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Multi-vendor JDK testing is off by default, but supported, in cases where checking compat across vendors is desirable. It adds test tasks to the check matrix if activated.

By default, multi-JDK tests are run against Azul Zulu for speed. With multi-vendor testing on, they are additionally run with GraalVM CE and Oracle JDKs.

Comment on lines +46 to +62
// must match the minimum JVM bytecode target for Pkl
jvmTarget = JvmTarget.fromTarget(buildInfo.jvmTarget.toString())

// enable java parameter names for stronger Kotlin-Java interop and debugging
javaParameters = true

// consider kotlin warnings errors if not otherwise suppressed
allWarningsAsErrors = true

freeCompilerArgs.addAll(
listOf(
// enable strict nullability checking and integration with pkl's own annotations
"-Xjsr305=strict",
"-Xjsr305=@org.pkl.core.util.Nullable:strict",
"-Xjsr305=@org.pkl.core.util.Nonnull:strict",
)
)
Copy link
Contributor Author

@sgammon sgammon Jan 24, 2025

Choose a reason for hiding this comment

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

after #900, the new compilerOptions { ... } Kotlin Gradle Plugin syntax can be used and the old kotlinOptions DSL is deprecated.

  • javaParameters: Allows Java reflection downstream on method parameters, and improves debugging by embedding parameter names within Kotlin bytecode

  • allWarningsAsErrors: Considers Kotlin compiler warnings as errors. Enabling this had no effect, as the Pkl project already essentially enforces this by convention.

  • -Xjsr305=@...:strict: Instructs kotlinc to consider Pkl's nullability annotations as authoritative. Java/Kotlin interop will respect these annotations such that Java types behave as T? if annotated with @Nullable, and T if annotated with @Nonnull. Enabling this had no negative impact.

Comment on lines +153 to 154
@Suppress("DEPRECATION")
private fun parseAsciidoc(docDescriptor: Descriptor.Path, selectors: List<UniqueIdSelector>) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Certain methods of AbstractDeque produce warnings, but they are just used here in tests, and the warnings involved describe missed optimizations. So I have suppressed them.

Signed-off-by: Sam Gammon <sam@elide.dev>

plugins {
id("pklJavaLibrary")

id("org.jetbrains.kotlinx.binary-compatibility-validator")
Copy link
Contributor Author

@sgammon sgammon Jan 24, 2025

Choose a reason for hiding this comment

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

I've added Kotlin ABI checking so that the Kotlin version change and JDK 21 change can be tested (w.r.t. library use) before release.

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