Skip to content

Clean up how KSP checks for klib cross-compilation support#2953

Merged
hfmehmed merged 2 commits into
google:mainfrom
omarismail94:main
May 20, 2026
Merged

Clean up how KSP checks for klib cross-compilation support#2953
hfmehmed merged 2 commits into
google:mainfrom
omarismail94:main

Conversation

@omarismail94
Copy link
Copy Markdown
Contributor

@omarismail94 omarismail94 commented May 18, 2026

Querying KGP's kotlinCompilation.crossCompilationSupported eagerly writes a metadata JSON file inside the build directory during task graph serialization. This dynamic file creation invalidates the Gradle Configuration Cache on subsequent runs.

To fix:

  1. Consolidated native cross-compilation support checking on KGP's standard kotlin.native.enableKlibsCrossCompilation property as the single source of truth.
  2. Swapped the operands in the task onlyIf check so host native compiles (like linuxX64 on Linux) short-circuit immediately and skip querying the cross-compilation property entirely.
  3. Added two integration tests to verify that the configuration cache now successfully reuses on native compilations, and that subproject DSL overrides are correctly captured and respected.

CC: @eygraber @liutikas

Comment thread gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspAATask.kt Outdated
Comment thread gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspAATask.kt Outdated
@omarismail94 omarismail94 force-pushed the main branch 2 times, most recently from 5cd6968 to a79a78f Compare May 19, 2026 12:45
Instead of introducing a custom KSP DSL property, this consolidates native
cross-compilation checking on KGP's standard
`kotlin.native.enableKlibsCrossCompilation` property as the single source of truth.

- Removed `enableKlibsCrossCompilation` from the KSP extension DSL.
- Moved the `enableKlibsCrossCompilation` property inside `KspGradleConfig` task
  input to prevent task-level capture of `kspAATask` during closure serialization.
- Re-implemented the `getKlibCrossCompilationSupport` helper to prioritize
  subproject-level overrides (from `ext` or subproject `gradle.properties`) eagerly
  via `findProperty`, cleanly falling back to a lazy Gradle property provider chain.
- Bypassed KGP's `crossCompilationSupported` provider check to resolve dynamic
  filesystem modifications during task graph serialization that was invalidating
  the configuration cache.
- Updated the `KMPImplementedIT.testSubprojectPropertyOverride` integration test to
  explicitly set the global fallback to false and dynamically override inside the
  subproject's `gradle.properties` file.
@hfmehmed hfmehmed merged commit 6bec1b4 into google:main May 20, 2026
19 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.

2 participants