https://kotlinlang.org logo
#eap
Title
# eap
t

tapchicoma

03/21/2024, 12:52 PM
Hi, I would like to ask you to take a closer look on the new feature added in 2.0 - migrating K/N compiler and dependencies provision to be kind-of similar to Gradle JDK toolchain feature. Kotlin Gradle plugin now downloads K/N compiler and related dependencies on Gradle execution phase mostly using Gradle itself to do it. This is enabled by default in beta releases. Relevant issues - one, two. I would be grateful for any feedback thank you color
2
youtrack 1
j

Javier

03/21/2024, 1:41 PM
With this we don’t need to cache the native dependencies as they will be somewhere inside the gradle home folder, right?
t

tapchicoma

03/21/2024, 1:49 PM
@Dmitrii Krasnov could you answer the question? 👏
d

Dmitrii Krasnov

03/21/2024, 1:55 PM
@Javier it is true for kotlin-native-prebuilt and kotlin-native. But for other native dependencies we still don't use Gradle configuration mechanisms for resolving them, because they are not published into Maven, so they will not be cached inside Gradle home for now.
👍 1
j

Javier

03/21/2024, 1:57 PM
The folder is somehow special and Gradle must support it manually in the official Gradle GitHub Action or they need to add it?
d

Dmitrii Krasnov

03/21/2024, 1:59 PM
kotlin-native-prebuilt and kotlin-native will be resolved as simple resolvable dependency and will be cached inside Gradle caches dir
j

Javier

03/21/2024, 2:00 PM
Perfect! Thank you for the info :)
l

louiscad

03/22/2024, 8:10 PM
Is it going to break the CompletKotlin Gradle plugin?
r

Rick Clephas

03/23/2024, 8:44 PM
Is there any way to manually depend on the native compiler from a Gradle task? I have some compiler plugin tests that require the
nativeHome
to be available.
🤔 1
t

tapchicoma

03/25/2024, 9:20 PM
Is there any way to manually depend on the native compiler from a Gradle task?
Not in this initial implementation, eventually we want to add into KGP API some interface like
UsesKotlinNativeCompiler
which tasks should implement to get K/N compiler compiler/tools (similar to Gradle JDK toolchain). Could you show how you used it so far?
r

Rick Clephas

03/25/2024, 9:26 PM
So far I have been depending on the old behaviour where the compiler was just available. Using the NativeCompilerDownloader to get the absolutePath. I guess that has always been sort of a hack. After this change I noticed some strange behaviour where the test would randomly fail. Turns out that the random failures were caused by missing caches. Running the tests in a clean environment will fail 100% of the time due to the missing native compiler. For now I have added a call to downloadIfNeeded to workaround this. But that obviously isn’t a great idea. P.S. I can create a YouTrack issue for this if you like. P.P.S. I am aware that most of the testing logic is part of the internal test infrastructure. So it could very well be that I am trying to do something that just isn’t really possible right now.
🤔 1
t

tapchicoma

03/25/2024, 9:28 PM
Is it going to break the CompletKotlin Gradle plugin?
Looking at the code of CompletKotlin Gradle plugin - I am not sure. Native toolchain adds marker file into downloaded K/N distribution
provisioned.ok
to check if distribution was provisioned correctly. So it seems will override distribution provided by CompletKotlin plugin. The best way is to check your plugin against Beta5 and report any issues in this thread. Generally it is also possible to disable native toolchain feature via
kotlin.native.toolchain.enabled
Gradle property
🙏🏼 1
For now I have added a call to downloadIfNeeded to workaround this. But that obviously isn’t a great idea.
Looks like it is ok workaround as a temporary solution. Please open an issue describing your use-case.
👍🏻 1
maybe small change that I would add to avoid downloading on configuration time:
Copy code
tasks.test {
    val downloadedNativeCompilerPath = project.provider {
           val compilerDownloader = NativeCompilerDownloader(project)
           compilerDownloader.downloadIfNeeded()
           compilerDownloader.compilerDirectory.absolutePath
    }

    doFirst {
        systemProperty("kotlin.internal.native.test.nativeHome", downloadedNativeCompilerPath.get())
    }
}
thank you color 1
r

Rick Clephas

03/26/2024, 7:44 AM