Skip to content

Commit 4b10e82

Browse files
authored
fix: iOS simulator TLS negotiation errors (#101)
1 parent ee467c8 commit 4b10e82

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

aws-crt-kotlin/build.gradle.kts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import aws.sdk.kotlin.gradle.kmp.IDEA_ACTIVE
1111
import aws.sdk.kotlin.gradle.kmp.configureKmpTargets
1212
import aws.sdk.kotlin.gradle.util.typedProp
1313
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
14+
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest
15+
import org.jetbrains.kotlin.konan.target.HostManager
1416

1517
plugins {
1618
alias(libs.plugins.kotlin.multiplatform)
@@ -167,6 +169,45 @@ kotlin {
167169
}
168170
}
169171

172+
// disable "standalone" mode in simulator tests since it causes TLS issues. this means we need to manage the simulator
173+
// ourselves (booting / shutting down). FIXME: https://youtrack.jetbrains.com/issue/KT-38317
174+
kotlin {
175+
val simulatorDeviceName = project.findProperty("iosSimulatorDevice") as? String ?: "iPhone 15"
176+
177+
val xcrun = "/usr/bin/xcrun"
178+
179+
tasks.register<Exec>("bootIosSimulatorDevice") {
180+
commandLine(xcrun, "simctl", "boot", simulatorDeviceName)
181+
182+
doLast {
183+
val result = executionResult.get()
184+
val code = result.exitValue
185+
if (code != 148 && code != 149) { // ignore "simulator already running" errors
186+
result.assertNormalExitValue()
187+
}
188+
}
189+
}
190+
191+
tasks.register<Exec>("shutdownIosSimulatorDevice") {
192+
mustRunAfter(tasks.withType<KotlinNativeSimulatorTest>())
193+
commandLine(xcrun, "simctl", "shutdown", simulatorDeviceName)
194+
195+
doLast {
196+
executionResult.get().assertNormalExitValue()
197+
}
198+
}
199+
200+
tasks.withType<KotlinNativeSimulatorTest>().configureEach {
201+
if (!HostManager.hostIsMac) { return@configureEach }
202+
203+
dependsOn("bootIosSimulatorDevice")
204+
finalizedBy("shutdownIosSimulatorDevice")
205+
206+
standalone = false
207+
device = simulatorDeviceName
208+
}
209+
}
210+
170211
// Publishing
171212
configurePublishing("aws-crt-kotlin")
172213

0 commit comments

Comments
 (0)