This repository was archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathbuild.gradle.kts
69 lines (56 loc) · 1.82 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
}
kotlin {
targets {
val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true) {
iosTarget = ::iosArm64 // Real device
} else {
iosTarget = ::iosX64 // iOS emulator
}
iosTarget("iOS") {
binaries {
framework("SharedCode")
}
}
jvm("android")
}
sourceSets {
val commonMain by getting {
dependencies {
api("org.jetbrains.kotlin:kotlin-stdlib-common")
}
}
val androidMain by getting {
dependencies {
api("org.jetbrains.kotlin:kotlin-stdlib")
}
}
}
}
// workaround for https://youtrack.jetbrains.com/issue/KT-27170
configurations.create("compileClasspath")
tasks.register<Sync>("packForXCode") {
val frameworkDir = File(buildDir, "xcode-frameworks")
val property = project.findProperty("XCODE_CONFIGURATION") as String?
val mode = property?.toUpperCase() ?: "DEBUG"
val target = kotlin.targets.getByName("iOS") as KotlinNativeTarget
val framework = target.binaries.getFramework("SharedCode", mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
from(framework.outputFile.parentFile)
into(frameworkDir)
doLast {
val file = File(frameworkDir, "gradlew")
file.writeText("""
#!/bin/bash
export 'JAVA_HOME=${System.getProperty("java.home")}'
cd '${rootProject.rootDir}'
./gradlew $@
""".trimIndent())
file.setExecutable(true)
}
}
tasks.getByName("build").dependsOn("packForXCode")