[Gradle, Native] Enable embeddable compiler jar by default
For Kotlin/Native compilations, apply generic (backend-agnostic) compiler plugin artifacts instead of Native-specific ones by default. `kotlin.native.useEmbeddableCompilerJar=false` project property allows switching to the previous legacy behaviour. This flag will be removed in a future release. ^KT-48595 Fixed
This commit is contained in:
committed by
Space
parent
0c6421d53f
commit
d0a26d1d85
+5
-4
@@ -136,11 +136,12 @@ interface KotlinCompilerPluginSupportPlugin : Plugin<Project> {
|
||||
fun getPluginArtifact(): SubpluginArtifact
|
||||
|
||||
/**
|
||||
* Kotlin/Native-specific plugin artifact.
|
||||
* Legacy Kotlin/Native-specific plugin artifact.
|
||||
*
|
||||
* If Gradle is configured to use Kotlin/Native embeddable compiler jar
|
||||
* (with `kotlin.native.useEmbeddableCompilerJar=true` project property),
|
||||
* then [getPluginArtifact] is used instead.
|
||||
* It is used only if Gradle is configured not to use Kotlin/Native embeddable compiler jar
|
||||
* (with `kotlin.native.useEmbeddableCompilerJar=false` project property).
|
||||
*
|
||||
* Otherwise, [getPluginArtifact] is used by default.
|
||||
*/
|
||||
fun getPluginArtifactForNative(): SubpluginArtifact? = null
|
||||
}
|
||||
|
||||
+1
-1
@@ -875,7 +875,7 @@ class GeneralNativeIT : BaseGradleIT() {
|
||||
}
|
||||
|
||||
// Check that changing K/N version lead to tasks rerun
|
||||
build(*compileTasksArray, "-Porg.jetbrains.kotlin.native.version=1.5.30") {
|
||||
build(*compileTasksArray, "-Porg.jetbrains.kotlin.native.version=1.6.10") {
|
||||
assertSuccessful()
|
||||
assertTasksExecuted(compileTasks)
|
||||
}
|
||||
|
||||
+7
-7
@@ -28,8 +28,8 @@ class NativeEmbeddableCompilerJarIT : BaseGradleIT() {
|
||||
build(":linkDebugExecutableHost") {
|
||||
assertSuccessful()
|
||||
withNativeCompilerClasspath(":linkDebugExecutableHost", ":compileKotlinHost") {
|
||||
assertTrue(it.includesRegularJar())
|
||||
assertFalse(it.includesEmbeddableJar())
|
||||
assertFalse(it.includesRegularJar())
|
||||
assertTrue(it.includesEmbeddableJar())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,8 +61,8 @@ class NativeEmbeddableCompilerJarIT : BaseGradleIT() {
|
||||
build(":linkDebugExecutableHost") {
|
||||
assertSuccessful()
|
||||
withNativeCompilerClasspath(":linkDebugExecutableHost", ":compileKotlinHost") {
|
||||
assertTrue(it.includesRegularJar())
|
||||
assertFalse(it.includesEmbeddableJar())
|
||||
assertFalse(it.includesRegularJar())
|
||||
assertTrue(it.includesEmbeddableJar())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,12 +70,12 @@ class NativeEmbeddableCompilerJarIT : BaseGradleIT() {
|
||||
assertTasksUpToDate(":linkDebugExecutableHost", ":compileKotlinHost")
|
||||
}
|
||||
|
||||
build(":linkDebugExecutableHost", "-Pkotlin.native.useEmbeddableCompilerJar=true") {
|
||||
build(":linkDebugExecutableHost", "-Pkotlin.native.useEmbeddableCompilerJar=false") {
|
||||
assertSuccessful()
|
||||
assertTasksExecuted(":linkDebugExecutableHost", ":compileKotlinHost")
|
||||
withNativeCompilerClasspath(":linkDebugExecutableHost", ":compileKotlinHost") {
|
||||
assertFalse(it.includesRegularJar())
|
||||
assertTrue(it.includesEmbeddableJar())
|
||||
assertTrue(it.includesRegularJar())
|
||||
assertFalse(it.includesEmbeddableJar())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+46
-19
@@ -20,8 +20,8 @@ import kotlin.test.*
|
||||
|
||||
internal class CompilationSpecificPluginPath {
|
||||
@Test
|
||||
fun `native common sourceset should be compiled with native plugins`() {
|
||||
// Given plugin but with native-specific artifact
|
||||
fun `native common sourceset should be compiled with common plugins`() {
|
||||
// Given plugin but with legacy-native-specific artifact
|
||||
class NativeSpecificPlugin : FakeSubPlugin("common", "native", { true })
|
||||
|
||||
val project = buildProject {
|
||||
@@ -53,12 +53,12 @@ internal class CompilationSpecificPluginPath {
|
||||
}
|
||||
project.evaluate()
|
||||
|
||||
// Then expect native artifact to be used for nativeMain metadata compilation
|
||||
assertEquals(setOf("native"), project.compileTaskSubplugins("compileNativeMainKotlinMetadata"))
|
||||
// Then expect common artifact to be used for all compilations, including nativeMain metadata
|
||||
assertEquals(setOf("common"), project.compileTaskSubplugins("compileNativeMainKotlinMetadata"))
|
||||
assertEquals(setOf("common"), project.compileTaskSubplugins("compileKotlinMetadata"))
|
||||
assertEquals(setOf("common"), project.compileTaskSubplugins("compileCommonMainKotlinMetadata"))
|
||||
assertEquals(setOf("common"), project.compileTaskSubplugins("compileKotlinJvm"))
|
||||
assertEquals(setOf("native"), project.compileTaskSubplugins("compileKotlinLinuxX64"))
|
||||
assertEquals(setOf("common"), project.compileTaskSubplugins("compileKotlinLinuxX64"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,11 +110,11 @@ internal class CompilationSpecificPluginPath {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `only native artifact should be taken for native platforms`() {
|
||||
// Given plugin but with native-specific artifact
|
||||
fun `only common artifacts should be taken for native platforms`() {
|
||||
// Given plugin but with legacy-native-specific artifact
|
||||
class NativeSpecificPlugin : FakeSubPlugin("common1", "native", { true })
|
||||
|
||||
// And plugin without native artifact but applicable on all platforms
|
||||
// And plugin without legacy native artifact but applicable on all platforms
|
||||
class RegularPluginWithoutNativeArtifact : FakeSubPlugin("common2", null, { true })
|
||||
|
||||
// When applying these plugins
|
||||
@@ -129,15 +129,13 @@ internal class CompilationSpecificPluginPath {
|
||||
}
|
||||
project.evaluate()
|
||||
|
||||
// Expect jvm target have both artifacts
|
||||
// Expect jvm and native targets have both common artifacts and no legacy native artifacts
|
||||
assertEquals(listOf("common1", "common2"), project.subplugins("jvm"))
|
||||
|
||||
// And native target should have only NativeSpecificPlugin artifacts
|
||||
assertEquals(listOf("native"), project.subplugins("linuxX64"))
|
||||
assertEquals(listOf("common1", "common2"), project.subplugins("linuxX64"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `native should use regular artifact when embeddable compiler jar is used`() {
|
||||
fun `native platform and common sourcesets should be compiled with native plugin artifacts when embeddable compiler jar is not used`() {
|
||||
// Given plugin but with native-specific artifact
|
||||
class NativeSpecificPlugin : FakeSubPlugin("common1", "native", { true })
|
||||
|
||||
@@ -149,17 +147,46 @@ internal class CompilationSpecificPluginPath {
|
||||
plugins.apply(NativeSpecificPlugin::class.java)
|
||||
plugins.apply(RegularPluginWithoutNativeArtifact::class.java)
|
||||
|
||||
// With kotlin.native.useEmbeddableCompilerJar=true
|
||||
extensions.getByType(ExtraPropertiesExtension::class.java).set("kotlin.native.useEmbeddableCompilerJar", "true")
|
||||
extensions.getByType(ExtraPropertiesExtension::class.java).set("kotlin.mpp.enableGranularSourceSetsMetadata", "true")
|
||||
|
||||
// With kotlin.native.useEmbeddableCompilerJar=false
|
||||
extensions.getByType(ExtraPropertiesExtension::class.java).set("kotlin.native.useEmbeddableCompilerJar", "false")
|
||||
|
||||
kotlin {
|
||||
linuxX64()
|
||||
mingwX64()
|
||||
jvm()
|
||||
|
||||
sourceSets.apply {
|
||||
val commonMain = getByName("commonMain")
|
||||
val nativeMain = create("nativeMain")
|
||||
val linuxX64 = getByName("linuxX64Main")
|
||||
val mingwX64 = getByName("mingwX64Main")
|
||||
val jvm = getByName("jvmMain")
|
||||
|
||||
// Make nativeMain be common source set for linuxX64 and mingwX64
|
||||
nativeMain.dependsOn(commonMain)
|
||||
linuxX64.dependsOn(nativeMain)
|
||||
mingwX64.dependsOn(nativeMain)
|
||||
jvm.dependsOn(commonMain)
|
||||
}
|
||||
}
|
||||
}
|
||||
project.evaluate()
|
||||
|
||||
// Expect native target have both regular artifacts
|
||||
assertEquals(listOf("common1", "common2"), project.subplugins("linuxX64"))
|
||||
// Then expect native artifact to be used for nativeMain metadata compilation
|
||||
assertEquals(setOf("native"), project.compileTaskSubplugins("compileNativeMainKotlinMetadata"))
|
||||
assertEquals(setOf("common1", "common2"), project.compileTaskSubplugins("compileKotlinMetadata"))
|
||||
assertEquals(setOf("common1", "common2"), project.compileTaskSubplugins("compileCommonMainKotlinMetadata"))
|
||||
assertEquals(setOf("common1", "common2"), project.compileTaskSubplugins("compileKotlinJvm"))
|
||||
assertEquals(setOf("native"), project.compileTaskSubplugins("compileKotlinLinuxX64"))
|
||||
|
||||
// Expect jvm target have both artifacts
|
||||
assertEquals(listOf("common1", "common2"), project.subplugins("jvm"))
|
||||
|
||||
// And native target should have only NativeSpecificPlugin artifacts
|
||||
assertEquals(listOf("native"), project.subplugins("linuxX64"))
|
||||
assertEquals(listOf("native"), project.subplugins("mingwX64"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -228,7 +255,7 @@ internal class CompilationSpecificPluginPath {
|
||||
|
||||
private abstract class FakeSubPlugin(
|
||||
val id: String,
|
||||
val idNative: String? = null,
|
||||
val idLegacyNative: String? = null,
|
||||
val isApplicablePredicate: KotlinCompilation<*>.() -> Boolean
|
||||
) : KotlinCompilerPluginSupportPlugin {
|
||||
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = kotlinCompilation.isApplicablePredicate()
|
||||
@@ -243,7 +270,7 @@ internal class CompilationSpecificPluginPath {
|
||||
id
|
||||
)
|
||||
|
||||
override fun getPluginArtifactForNative(): SubpluginArtifact? = idNative?.let {
|
||||
override fun getPluginArtifactForNative(): SubpluginArtifact? = idLegacyNative?.let {
|
||||
SubpluginArtifact(
|
||||
"test",
|
||||
it
|
||||
|
||||
+1
-1
@@ -316,7 +316,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
|
||||
* Will be default after proper migration.
|
||||
*/
|
||||
val nativeUseEmbeddableCompilerJar: Boolean
|
||||
get() = booleanProperty("kotlin.native.useEmbeddableCompilerJar") ?: false
|
||||
get() = booleanProperty("kotlin.native.useEmbeddableCompilerJar") ?: true
|
||||
|
||||
/**
|
||||
* Allows a user to set project-wide options that will be passed to the K/N compiler via -Xbinary flag.
|
||||
|
||||
Reference in New Issue
Block a user