Skip to content

Commit 8843582

Browse files
authored
feat: Kotlin/Native Windows compilation (#91)
* ⚠️ WIP changes for Windows compilation * clean up
1 parent 03eebb0 commit 8843582

File tree

1 file changed

+6
-75
lines changed

1 file changed

+6
-75
lines changed

build-plugins/kmp-conventions/src/main/kotlin/aws/sdk/kotlin/gradle/kmp/ConfigureTargets.kt

Lines changed: 6 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@ package aws.sdk.kotlin.gradle.kmp
66

77
import aws.sdk.kotlin.gradle.util.prop
88
import org.gradle.api.Project
9-
import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven
10-
import org.gradle.api.publish.tasks.GenerateModuleMetadata
119
import org.gradle.api.tasks.testing.Test
1210
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
13-
import org.gradle.kotlin.dsl.*
11+
import org.gradle.kotlin.dsl.named
1412
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
1513
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
16-
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
17-
import org.jetbrains.kotlin.konan.target.Family
1814
import org.jetbrains.kotlin.konan.target.HostManager
1915
import java.io.File
2016

@@ -51,7 +47,7 @@ val Project.hasWindows: Boolean get() = hasNative || files.any { it.name == "win
5147
* Test if a project follows the convention and needs configured for KMP (used in handful of spots where we have a
5248
* subproject that is just a container for other projects but isn't a KMP project itself).
5349
*/
54-
public val Project.needsKmpConfigured: Boolean get() = hasCommon || hasJvm || hasNative || hasJs || hasJvmAndNative || hasDesktop || hasLinux || hasApple || hasWindows
50+
val Project.needsKmpConfigured: Boolean get() = hasCommon || hasJvm || hasNative || hasJs || hasJvmAndNative || hasDesktop || hasLinux || hasApple || hasWindows
5551

5652
@OptIn(ExperimentalKotlinGradlePluginApi::class)
5753
fun Project.configureKmpTargets() {
@@ -112,22 +108,15 @@ fun Project.configureKmpTargets() {
112108
// FIXME Configure JS
113109

114110
if (NATIVE_ENABLED) {
115-
if (hasApple) {
111+
if ((hasApple || hasDesktop) && HostManager.hostIsMac) {
116112
kmpExt.apply { configureApple() }
117113
}
118-
if (hasWindows) {
114+
if ((hasWindows || hasDesktop) && HostManager.hostIsMingw) {
119115
kmpExt.apply { configureWindows() }
120116
}
121-
if (hasLinux) {
117+
if ((hasLinux || hasDesktop) && HostManager.hostIsLinux) {
122118
kmpExt.apply { configureLinux() }
123119
}
124-
if (hasDesktop) {
125-
kmpExt.apply {
126-
configureLinux()
127-
configureMacos()
128-
configureWindows()
129-
}
130-
}
131120
}
132121

133122
kmpExt.configureSourceSetsConvention()
@@ -193,8 +182,7 @@ fun Project.configureMacos() {
193182

194183
fun Project.configureWindows() {
195184
kotlin {
196-
// FIXME Set up Docker files and CMake tasks for Windows
197-
// mingwX64()
185+
mingwX64()
198186
}
199187
}
200188

@@ -213,60 +201,3 @@ fun KotlinMultiplatformExtension.configureSourceSetsConvention() {
213201

214202
val Project.JVM_ENABLED get() = prop("aws.kotlin.jvm")?.let { it == "true" } ?: true
215203
val Project.NATIVE_ENABLED get() = prop("aws.kotlin.native")?.let { it == "true" } ?: true
216-
217-
/**
218-
* Kotlin/Native Linux and Windows targets are generally enabled on all hosts since
219-
* the Kotlin toolchain and backend compilers support cross compilation. We
220-
* are using cinterop and have to compile CRT for those platforms which sometimes
221-
* requires using docker which isn't always available in CI or setup in users environment.
222-
*
223-
* See [KT-30498](https://youtrack.jetbrains.com/issue/KT-30498)
224-
*/
225-
fun Project.disableCrossCompileTargets() {
226-
plugins.withId("org.jetbrains.kotlin.multiplatform") {
227-
configure<KotlinMultiplatformExtension> {
228-
targets.withType<KotlinNativeTarget> {
229-
val knTarget = this
230-
when {
231-
HostManager.hostIsMac && (knTarget.isLinux || knTarget.isWindows) -> disable(knTarget)
232-
HostManager.hostIsLinux && knTarget.isApple -> disable(knTarget)
233-
HostManager.hostIsMingw && (knTarget.isLinux || knTarget.isApple) -> disable(knTarget)
234-
}
235-
}
236-
}
237-
}
238-
}
239-
240-
private val KotlinNativeTarget.isLinux: Boolean
241-
get() = konanTarget.family == Family.LINUX
242-
243-
private val KotlinNativeTarget.isApple: Boolean
244-
get() = konanTarget.family.isAppleFamily
245-
246-
private val KotlinNativeTarget.isWindows: Boolean
247-
get() = konanTarget.family == Family.MINGW
248-
249-
internal fun Project.disable(knTarget: KotlinNativeTarget) {
250-
logger.warn("disabling Kotlin/Native target: ${knTarget.name}")
251-
knTarget.apply {
252-
compilations.all {
253-
cinterops.all {
254-
tasks.named(interopProcessingTaskName).configure { enabled = false }
255-
}
256-
compileTaskProvider.configure { enabled = false }
257-
}
258-
259-
binaries.all {
260-
linkTaskProvider.configure { enabled = false }
261-
}
262-
263-
mavenPublication {
264-
tasks.withType<AbstractPublishToMaven>().configureEach {
265-
onlyIf { publication != this@mavenPublication }
266-
}
267-
tasks.withType<GenerateModuleMetadata>().configureEach {
268-
onlyIf { publication != this@mavenPublication }
269-
}
270-
}
271-
}
272-
}

0 commit comments

Comments
 (0)