Skip to content

Conversation

@troelsbjerre
Copy link
Collaborator

The existing solution for finding the location of the JNI headers relies on the java.home of the running process. This can fail, when the gradle daemon is started from a JRE, which usually do not include the header files. This fix instead uses gradle's JavaToolChainService to find an appropriate JDK to access the headers from.

#KT-82607 Fixed

@troelsbjerre troelsbjerre requested review from a team as code owners January 9, 2026 10:25
@troelsbjerre troelsbjerre requested review from Badya and removed request for PavelPunegov and projedi January 9, 2026 10:25
@sbogolepov sbogolepov requested review from projedi and removed request for sbogolepov January 9, 2026 13:03
The existing solution for finding the location of the JNI headers relies
on the java.home of the running process. This can fail, when the gradle
daemon is started from a JRE, which usually do not include the header
files. This fix instead uses gradle's JavaToolChainService to find an
appropriate JDK to access the headers from.

#KT-82607 Fixed
This change modernizes JNI header discovery in the Kotlin/Native utilities
while providing a smart bridge for the current bootstrap process.

1. Enhanced ClangArgs.Jni Discovery:
   Updated the low-level discovery logic in native/utils to look for a JDK in
   the following order:
   - The 'konan.jdk.home' property (passed by Gradle).
   - The 'JAVA_HOME' environment variable (for standalone/CLI usage).
   - The process's own 'java.home' (as a final fallback).

2. Gradle Toolchain Integration:
   Updated PlatformManagerProvider to obtain the JDK 11 path via Gradle's
   JavaToolchainService and inject it into the 'konan.jdk.home' property.

3. Intermediate Bootstrap Workaround:
   Since the current build uses a bootstrap version of ClangArgs that doesn't
   yet recognize the new property, a temporary 'jniHostCompilerArgs' bridge
   is added to NativeToolsExtension. This property detects if the bootstrap's
   default paths are "broken" (missing jni.h) and automatically hot-patches
   them with the correct Toolchain JDK paths.

This allows tasks like :kotlin-native:Interop:Runtime:callbacks.o to succeed
immediately, even on JRE-only Gradle daemons, while ensuring the underlying
utilities are self-sufficient once bootstrapped.

^KT-82607
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