-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
79 lines (67 loc) · 2.67 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
70
71
72
73
74
75
76
77
78
79
import org.jetbrains.kotlin.gradle.plugin.mpp.Executable
import org.jetbrains.kotlin.konan.target.Architecture
plugins {
kotlin("multiplatform") version "1.9.0"
kotlin("plugin.serialization") version "1.9.0"
}
group = "cn.awalol"
version = "1.0-SNAPSHOT"
val ktor_version = "2.3.2"
repositories {
mavenCentral()
jcenter()
}
kotlin {
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}
nativeTarget.apply {
compilations.getByName("main"){
cinterops{
val windows by creating
}
}
binaries {
executable {
windowsResources("${project.projectDir}/src/nativeMain/resources/samples.rc")
entryPoint = "cn.awalol.qqmusic.main"
}
}
}
sourceSets {
val nativeMain by getting{
dependencies {
implementation("com.github.msink:libui:0.1.8")
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-winhttp:$ktor_version")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
}
}
val nativeTest by getting
}
}
fun Executable.windowsResources(rcFileName: String) {
val taskName = linkTaskName.replaceFirst("link", "windres")
val inFile = File(rcFileName)
val outFile = buildDir.resolve("processedResources/$taskName.res")
val windresTask = tasks.create<Exec>(taskName) {
val konanDataDir = System.getenv("KONAN_DATA_DIR") ?: "${System.getProperty("user.home")}/.konan"
val toolchainBinDir = when (target.konanTarget.architecture) {
Architecture.X86 -> File("$konanDataDir/dependencies/msys2-mingw-w64-i686-2/bin").invariantSeparatorsPath
Architecture.X64 -> File("$konanDataDir/dependencies/msys2-mingw-w64-x86_64-2/bin").invariantSeparatorsPath
else -> error("Unsupported architecture")
}
inputs.file(inFile)
outputs.file(outFile)
commandLine("$toolchainBinDir/windres", inFile, "-D_${buildType.name}", "-O", "coff", "-o", outFile)
environment("PATH", "$toolchainBinDir;${System.getenv("PATH")}")
dependsOn(compilation.compileTaskProvider)
}
linkTask.dependsOn(windresTask)
linkerOpts(outFile.toString())
}