[build] Disable KotlinNativeLink by default. Can be enabled by -Dmirai.native.link=true

This commit is contained in:
Him188 2022-11-25 18:37:27 +00:00
parent 9540bc95c5
commit 9f7face6eb
2 changed files with 20 additions and 5 deletions

View File

@ -134,7 +134,7 @@ jobs:
# FIXME there must be two or more targets, or we'll get error on `@OptionalExpectation`
# > Declaration annotated with '@OptionalExpectation' can only be used in common module sources
enableLocalPublishingTest: 'false'
gradleArgs: --scan "-Dmirai.target=jvm;${{ matrix.targetName }};!other" "-Pkotlin.compiler.execution.strategy=in-process" "-Dorg.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8"
gradleArgs: --scan "-Dmirai.target=jvm;${{ matrix.targetName }};~other" "-Pkotlin.compiler.execution.strategy=in-process" "-Dorg.gradle.jvmargs=-Xmx4096m" "-Dfile.encoding=UTF-8"
isMac: ${{ startsWith(matrix.os, 'macos') }}
isWindows: ${{ startsWith(matrix.os, 'windows') }}
isUbuntu: ${{ startsWith(matrix.os, 'ubuntu') }}

View File

@ -19,10 +19,8 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.TEST_COMPI
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
import java.io.File
val MIRAI_PLATFORM_ATTRIBUTE = Attribute.of(
@ -374,6 +372,14 @@ fun KotlinMultiplatformExtension.configureNativeTargetsHierarchical(
}
fun KotlinMultiplatformExtension.configureNativeTargetBinaries(project: Project) {
if (!System.getProperty("mirai.native.link", "false").toBoolean()) {
// Must enable KotlinNativeLink by argument "mirai.native.link".
// :mirai-core:linkReleaseSharedMacosX64
return
// disableNativeLinkTasks(project)
}
NATIVE_TARGETS.forEach { targetName ->
val target = targets.getByName(targetName) as KotlinNativeTarget
target.binaries {
@ -387,6 +393,15 @@ fun KotlinMultiplatformExtension.configureNativeTargetBinaries(project: Project)
}
}
private fun disableNativeLinkTasks(project: Project) {
project.tasks.withType<KotlinNativeLink>()
.filter { it.binary.outputKind != NativeOutputKind.TEST }
.forEach {
it.enabled = false
project.logger.warn("Disabling KotlinNativeLink: ${it.path}")
}
}
private fun KotlinNativeTarget.findOrCreateTest(buildType: NativeBuildType, configure: TestExecutable.() -> Unit) =
binaries.findTest(buildType)?.apply(configure) ?: binaries.test(listOf(buildType), configure)