Skip to content

Check for klib cross compilation support from the KotlinNativeCompilation - #2738

Merged
hfmehmed merged 2 commits into
google:mainfrom
eygraber:patch-1
Mar 17, 2026
Merged

Check for klib cross compilation support from the KotlinNativeCompilation#2738
hfmehmed merged 2 commits into
google:mainfrom
eygraber:patch-1

Conversation

@eygraber

Copy link
Copy Markdown
Contributor

@ting-yuan
ting-yuan requested a review from hfmehmed December 22, 2025 20:27
Comment thread gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspAATask.kt Outdated
@hfmehmed

Copy link
Copy Markdown
Collaborator

Can you rebase the PR on main?

@hfmehmed

Copy link
Copy Markdown
Collaborator

Thanks for the contribution.

@hfmehmed
hfmehmed merged commit 6a56a52 into google:main Mar 17, 2026
3 checks passed
@eygraber
eygraber deleted the patch-1 branch March 17, 2026 17:55
@omarismail94

omarismail94 commented May 18, 2026

Copy link
Copy Markdown
Collaborator

It looks like this change introduces a Gradle Configuration Cache invalidation issue for projects using Kotlin Multiplatform with Kotlin Native targets.

Migrating to kotlinCompilation.crossCompilationSupported causes a configuration cache miss on subsequent builds. e.g.

Calculating task graph as configuration cache cannot be reused because the file system entry '../../out/androidx/room3/room3-common/build/kotlin/kotlin-project-shared-data/crossCompilationMetadata_linuxArm64ApiElements.json' has been created.

@eygraber

Copy link
Copy Markdown
Contributor Author

@Tapchicoma is there an underlying issue with the provider, or is it being used incorrectly here?

@hfmehmed

Copy link
Copy Markdown
Collaborator

It's possible that KotlinNativeCompilation object in not serializable, potentially ?

@Tapchicoma

Copy link
Copy Markdown

KotlinNativeCompilation is not serializable

@hfmehmed

Copy link
Copy Markdown
Collaborator

Actually to me it seems that, after the first build KGP creates some file which make the config cache not reusable during the second build.

Calculating task graph as configuration cache cannot be reused because the file system entry 'annotations/build/kotlin/kotlin-project-shared-data/crossCompilationMetadata_linuxX64ApiElements.json' has been created.

@Tapchicoma can you comment on the creation of crossCompilationMetadata_linuxX64ApiElements.json

@AYastrebov

Copy link
Copy Markdown

crossCompilationSupported needs to know whether dependency subprojects have cinterops, so it pulls that information via shared data between projects. Each native target writes a small JSON file (like crossCompilationMetadata_linuxArm64ApiElements.json) into build/kotlin/kotlin-project-shared-data/

@hfmehmed

Copy link
Copy Markdown
Collaborator

The problem is this arifacts is something that is produced by the execution phase. So what seems to be happening is that in the first run (fresh gradle run), Gradle records this json file as a configuration input (but it doesnt exist yet). Then the build executes and the file is created. On the next build, Gradle checks if it can re-use the configuration cache - but it sees that the file now exists which does not match the state it stored before so it invalidates the cache and reruns full configuration.

This is my (possibly wrong?) understanding of what is going on here. Does that have any truth in it?

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.

5 participants