Skip to content

Commit 5ab633d

Browse files
committed
Apply iOS simulator fixes from aws-crt-kotlin
1 parent be248ae commit 5ab633d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

runtime/build.gradle.kts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import aws.sdk.kotlin.gradle.dsl.configurePublishing
66
import aws.sdk.kotlin.gradle.kmp.*
77
import aws.sdk.kotlin.gradle.util.typedProp
8+
import org.gradle.kotlin.dsl.withType
89
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
10+
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest
11+
import org.jetbrains.kotlin.konan.target.HostManager
912

1013
plugins {
1114
alias(libs.plugins.dokka)
@@ -67,6 +70,47 @@ subprojects {
6770
}
6871
}
6972
}
73+
74+
75+
// disable "standalone" mode in simulator tests since it causes TLS issues. this means we need to manage the simulator
76+
// ourselves (booting / shutting down). FIXME: https://youtrack.jetbrains.com/issue/KT-38317
77+
val simulatorDeviceName = project.findProperty("iosSimulatorDevice") as? String ?: "iPhone 15"
78+
79+
val xcrun = "/usr/bin/xcrun"
80+
81+
tasks.register<Exec>("bootIosSimulatorDevice") {
82+
isIgnoreExitValue = true
83+
commandLine(xcrun, "simctl", "boot", simulatorDeviceName)
84+
85+
doLast {
86+
val result = executionResult.get()
87+
val code = result.exitValue
88+
if (code != 148 && code != 149) { // ignore "simulator already running" errors
89+
result.assertNormalExitValue()
90+
}
91+
}
92+
}
93+
94+
tasks.register<Exec>("shutdownIosSimulatorDevice") {
95+
mustRunAfter(tasks.withType<KotlinNativeSimulatorTest>())
96+
commandLine(xcrun, "simctl", "shutdown", simulatorDeviceName)
97+
98+
doLast {
99+
executionResult.get().assertNormalExitValue()
100+
}
101+
}
102+
103+
tasks.withType<KotlinNativeSimulatorTest>().configureEach {
104+
if (!HostManager.hostIsMac) {
105+
return@configureEach
106+
}
107+
108+
dependsOn("bootIosSimulatorDevice")
109+
finalizedBy("shutdownIosSimulatorDevice")
110+
111+
standalone = false
112+
device = simulatorDeviceName
113+
}
70114
}
71115

72116
kotlin.sourceSets.all {

0 commit comments

Comments
 (0)