Skip to content

Commit 15490c5

Browse files
committed
Use aws-kotlin-repo-tools disableCrossCompile
1 parent c1c74af commit 15490c5

File tree

3 files changed

+11
-72
lines changed

3 files changed

+11
-72
lines changed

build.gradle.kts

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
import aws.sdk.kotlin.gradle.dsl.configureLinting
66
import aws.sdk.kotlin.gradle.dsl.configureNexus
77
import aws.sdk.kotlin.gradle.util.typedProp
8-
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
9-
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
10-
import org.jetbrains.kotlin.konan.target.Family
11-
import org.jetbrains.kotlin.konan.target.HostManager
12-
import kotlin.apply
138

149
buildscript {
1510
// NOTE: buildscript classpath for the root project is the parent classloader for the subprojects, we
@@ -159,69 +154,3 @@ apiValidation {
159154
),
160155
)
161156
}
162-
163-
val disableCrossCompile = typedProp<Boolean>("aws.kotlin.native.disableCrossCompile") == true
164-
165-
if (disableCrossCompile) {
166-
logger.warn("aws.kotlin.native.disableCrossCompile=true: Cross compilation is disabled.")
167-
disableCrossCompileTargets()
168-
}
169-
170-
private val KotlinNativeTarget.isLinux: Boolean
171-
get() = konanTarget.family == Family.LINUX
172-
173-
private val KotlinNativeTarget.isApple: Boolean
174-
get() = konanTarget.family.isAppleFamily
175-
176-
private val KotlinNativeTarget.isWindows: Boolean
177-
get() = konanTarget.family == Family.MINGW
178-
179-
/**
180-
* Kotlin/Native Linux and Windows targets are generally enabled on all hosts since
181-
* the Kotlin toolchain and backend compilers support cross compilation. We
182-
* are using cinterop and have to compile CRT for those platforms which sometimes
183-
* requires using docker which isn't always available in CI or setup in users environment.
184-
*
185-
* See [KT-30498](https://youtrack.jetbrains.com/issue/KT-30498)
186-
*/
187-
fun Project.disableCrossCompileTargets() {
188-
allprojects {
189-
plugins.withId("org.jetbrains.kotlin.multiplatform") {
190-
configure<KotlinMultiplatformExtension> {
191-
targets.withType<KotlinNativeTarget> {
192-
val knTarget = this
193-
when {
194-
HostManager.hostIsMac && (knTarget.isLinux || knTarget.isWindows) -> disable(knTarget)
195-
HostManager.hostIsLinux && knTarget.isApple -> disable(knTarget)
196-
HostManager.hostIsMingw && (knTarget.isLinux || knTarget.isApple) -> disable(knTarget)
197-
}
198-
}
199-
}
200-
}
201-
}
202-
}
203-
204-
internal fun Project.disable(knTarget: KotlinNativeTarget) {
205-
logger.warn("disabling Kotlin/Native target: ${knTarget.name}")
206-
knTarget.apply {
207-
compilations.all {
208-
cinterops.all {
209-
tasks.named(interopProcessingTaskName).configure { enabled = false }
210-
}
211-
compileTaskProvider.configure { enabled = false }
212-
}
213-
214-
binaries.all {
215-
linkTaskProvider.configure { enabled = false }
216-
}
217-
218-
mavenPublication {
219-
tasks.withType<AbstractPublishToMaven>().configureEach {
220-
onlyIf { publication != this@mavenPublication }
221-
}
222-
tasks.withType<GenerateModuleMetadata>().configureEach {
223-
onlyIf { publication != this@mavenPublication }
224-
}
225-
}
226-
}
227-
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
kotlin-version = "2.0.21"
33
dokka-version = "1.9.10"
44

5-
aws-kotlin-repo-tools-version = "0.4.19-kn"
5+
aws-kotlin-repo-tools-version = "0.4.20-kn"
66

77
# libs
88
coroutines-version = "1.9.0"

runtime/build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
import aws.sdk.kotlin.gradle.dsl.configurePublishing
66
import aws.sdk.kotlin.gradle.kmp.*
7+
import aws.sdk.kotlin.gradle.util.typedProp
78
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
89

910
plugins {
@@ -17,6 +18,15 @@ val sdkVersion: String by project
1718
// Apply KMP configuration from build plugin
1819
configureKmpTargets()
1920

21+
// Disable cross compilation if flag is set
22+
val disableCrossCompile = typedProp<Boolean>("aws.kotlin.native.disableCrossCompile") == true
23+
if (disableCrossCompile) {
24+
logger.warn("aws.kotlin.native.disableCrossCompile=true: Cross compilation is disabled.")
25+
allprojects {
26+
disableCrossCompileTargets()
27+
}
28+
}
29+
2030
// capture locally - scope issue with custom KMP plugin
2131
val libraries = libs
2232

0 commit comments

Comments
 (0)