Skip to content

Fix configuration cache invalidation in klib cross-compilation check#3014

Open
omarismail94 wants to merge 1 commit into
google:mainfrom
omarismail94:main
Open

Fix configuration cache invalidation in klib cross-compilation check#3014
omarismail94 wants to merge 1 commit into
google:mainfrom
omarismail94:main

Conversation

@omarismail94

Copy link
Copy Markdown
Contributor

KotlinNativeCompilation.crossCompilationSupported resolves the crossCompilationMetadata JSONs exported by project dependencies and probes their existence. Capturing it in onlyIf makes the configuration cache evaluate it at store time, before the exporting tasks have run. When the build subsequently creates these files, the next build discards the cache entry with: "configuration cache cannot be reused because the file system entry ... has been created".

To fix this, we mirror KGP's own compileKotlin task behavior:

  • Keep the target-level condition (cross-compilation property enabled and no cinterops) in a stored provider
  • Declare the metadata JSONs as task inputs so that the exporting tasks run first.
  • Read and parse these metadata files in onlyIf at execution time.

TESTED: Update the regression test (testNativeConfigurationCacheReuse) which could not catch this bug previously. The old test used a host-supported target that never took the cross-compilation target. The updated test targets iosArm64 to force the cross-compilation path, and builds the iosArm64 klib and asserts configuration cache reuse.

KotlinNativeCompilation.crossCompilationSupported resolves the crossCompilationMetadata JSONs exported by project dependencies and probes their existence. Capturing it in onlyIf makes the configuration cache evaluate it at store time, before the exporting tasks have run. When the build subsequently creates these files, the next build discards the cache entry with: "configuration cache cannot be reused because the file system entry ... has been created".

To fix this, we mirror KGP's own compileKotlin<Target> task behavior:

* Keep the target-level condition (cross-compilation property enabled and no cinterops) in a stored provider
* Declare the metadata JSONs as task inputs so that the exporting tasks run first.
* Read and parse these metadata files in onlyIf at execution time.

TESTED: Update the regression test (testNativeConfigurationCacheReuse) which could not catch this bug previously. The old test used a host-supported target that never took the cross-compilation target. The updated test targets iosArm64 to force the cross-compilation path, and builds the iosArm64 klib and asserts configuration cache reuse.
@jaschdoc

jaschdoc commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

I think this PR requires a review from @hfmehmed :)

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