Skip to content

Commit 9819a8d

Browse files
committed
Update to latest versions of everything
1 parent 266288f commit 9819a8d

File tree

18 files changed

+46968
-85861
lines changed

18 files changed

+46968
-85861
lines changed

.github/workflows/gradle.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v1
12-
- name: Set up JDK 1.8
13-
uses: actions/setup-java@v1
14-
with:
15-
java-version: 1.8
11+
- { uses: actions/checkout@v4 }
12+
- { name: Set up JDK, uses: actions/setup-java@v4, with: { distribution: "temurin", java-version: "21" } }
13+
- { name: Prepare Gradle, uses: gradle/actions/setup-gradle@d9c87d481d55275bb5441eef3fe0e46805f9ef70 } # https://github.com/gradle/actions/releases/tag/v3.5.0
1614
- name: Build with Gradle
1715
#run: ./gradlew -s -i check
1816
run: ./gradlew -s -i jvmTest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ a.out
2626
/samples/mp3dec.kt
2727
/samples/minimp3_korau.kt
2828
/temp/
29+
/.kotlin

build.gradle.kts

Lines changed: 121 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,28 @@
11
import org.gradle.api.tasks.testing.logging.TestLogEvent
2-
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
2+
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.approximateDeclarationType
3+
import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
34
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
45
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
56
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
67
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
7-
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
8-
import org.jetbrains.kotlin.gradle.tasks.KotlinJsDce
9-
import org.jetbrains.kotlin.konan.properties.*
10-
import org.jetbrains.kotlin.konan.util.*
11-
12-
//buildscript {
13-
// repositories {
14-
// mavenLocal()
15-
// mavenCentral()
16-
// maven { url = uri("https://kotlin.bintray.com/kotlin-dev") }
17-
// }
18-
// val kotlinVersion = "1.3.50-release-105"
19-
// dependencies {
20-
// classpath("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:$kotlinVersion")
21-
// }
22-
//}
8+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
239

2410
plugins {
25-
kotlin("multiplatform") version "1.6.21" apply true
26-
//kotlin("multiplatform") version "1.3.41" apply true
27-
//kotlin("multiplatform") version "1.3.50-release-105"
28-
//id("kotlinx-serialization") version "1.3.41"
11+
kotlin("multiplatform") version "2.0.20-RC2" apply true
12+
id("org.barfuin.gradle.taskinfo") version "2.2.0"
2913
idea
3014
}
3115

32-
//apply(plugin = "org.jetbrains.kotlin.multiplatform")
33-
apply(plugin = "kotlin-dce-js")
16+
//project.gradle.taskGraph.whenReady { println(project.gradle.taskGraph.allTasks) }
3417

3518
repositories {
3619
mavenLocal()
3720
mavenCentral()
38-
maven { url = uri("https://kotlin.bintray.com/kotlinx") }
39-
//maven { url = uri("https://kotlin.bintray.com/kotlin-dev") }
40-
}
41-
42-
43-
fun KotlinOnlyTarget<*>.mainDependencies(block: KotlinDependencyHandler.() -> Unit) {
44-
this.compilations["main"].dependencies(block)
45-
}
46-
47-
fun KotlinOnlyTarget<*>.testDependencies(block: KotlinDependencyHandler.() -> Unit) {
48-
this.compilations["test"].dependencies(block)
4921
}
5022

51-
operator fun File.get(key: String) = File(this, key)
52-
var File.textContent get() = this.readText(); set(value) = run { this.writeText(value) }
53-
5423
//val jsIndex = file("src/jsMain/resources/index.html")
5524
//jsIndex.textContent = jsIndex.textContent.replace(Regex("Kotlin C Compiler WIP Version ([\\d\\.]*)"), "Kotlin C Compiler WIP Version $version")
5625

57-
file("build/gen/kotlin/com/soywiz/ktcc/internal/version.kt").also { it.parentFile.mkdirs() }.textContent = "package com.soywiz.ktcc.internal\n\ninternal val KTCC_VERSION = \"$version\""
5826
//println(file("src/commonMain/kotlin/com/soywiz/ktcc/internal/version.kt").textContent)
5927

6028
//fun KotlinTargetContainerWithPresetFunctions.common(callback: KotlinOnlyTarget<*>.() -> Unit) {
@@ -71,15 +39,14 @@ kotlin {
7139
}
7240
}
7341

74-
//metadata {
75-
// mainDependencies {
76-
// implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
77-
// }
78-
// testDependencies {
79-
// implementation("org.jetbrains.kotlin:kotlin-test-annotations-common")
80-
// implementation("org.jetbrains.kotlin:kotlin-test-common")
81-
// }
82-
//}
42+
fun KotlinNativeTarget.configureNative() {
43+
configureAll()
44+
binaries {
45+
executable()
46+
}
47+
}
48+
49+
8350

8451
//common {
8552
//}
@@ -90,19 +57,12 @@ kotlin {
9057
js {
9158
configureAll()
9259
browser()
93-
compilations.all {
94-
kotlinOptions {
95-
sourceMap = true
96-
metaInfo = true
97-
moduleKind = "umd"
98-
}
99-
}
100-
}
101-
102-
fun KotlinNativeTarget.configureNative() {
103-
configureAll()
104-
binaries {
105-
executable()
60+
binaries.executable()
61+
compilerOptions {
62+
this.target = "es2015"
63+
this.useEsClasses = true
64+
sourceMap = true
65+
moduleKind = JsModuleKind.MODULE_ES
10666
}
10767
}
10868

@@ -112,14 +72,13 @@ kotlin {
11272
linuxX64 { configureNative() }
11373
mingwX64 { configureNative() }
11474

115-
sourceSets {
116-
val nativeCommonMain = this.create("nativeCommonMain")
117-
val nativeCommonTest = this.create("nativeCommonTest")
118-
119-
configure(listOf(this.getByName("macosX64Main"), this.getByName("macosArm64Main"), this.getByName("linuxX64Main"), this.getByName("mingwX64Main"))) {
120-
dependsOn(nativeCommonMain)
121-
}
122-
}
75+
//sourceSets {
76+
// val nativeMain = this.create("nativeMain")
77+
// val nativeTest = this.create("nativeTest")
78+
// configure(listOf(this.getByName("macosX64Main"), this.getByName("macosArm64Main"), this.getByName("linuxX64Main"), this.getByName("mingwX64Main"))) {
79+
// dependsOn(nativeMain)
80+
// }
81+
//}
12382
}
12483

12584
sourceSets["commonMain"].kotlin.srcDir("build/gen")
@@ -148,52 +107,73 @@ val mainClassName = "com.soywiz.ktcc.cli.CLI"
148107

149108
val jsCompilations = kotlin.targets["js"].compilations
150109

151-
val GENERATED_DO_NOT_MODIFY = "// GENERATED. Do not modify"
110+
open class GenerateSourcesTask : DefaultTask() {
111+
private val rootDir = project.rootDir
112+
private val version = project.version
152113

153-
fun String.escapeTripleQuote(): String {
154-
return this.replace("$", "\${DOLLAR}").replace("\"\"\"", "\${TRIPLET}")
155-
}
114+
private val GENERATED_DO_NOT_MODIFY = "// GENERATED. Do not modify"
156115

157-
fun generateIncludes(): String {
158-
val lines = arrayListOf<String>()
159-
lines += GENERATED_DO_NOT_MODIFY
160-
lines += "package com.soywiz.ktcc.headers"
161-
lines += "private val DOLLAR = '$'"
162-
lines += "private val TRIPLET = \"\\\"\\\"\\\"\""
163-
lines += "val CStdIncludes = CIncludes().apply {"
164-
165-
val includeDir = File(rootDir, "include").absoluteFile
166-
for (file in includeDir.walkTopDown().toList().sortedBy { it.absolutePath }) {
167-
if (!file.name.endsWith(".h")) continue
168-
val ktFile = File(file.absolutePath.removeSuffix(".h") + ".kt")
169-
val cFile = File(file.absolutePath.removeSuffix(".h") + ".c")
170-
//println(file)
171-
lines += buildString {
172-
append("FILE(\"${file.relativeTo(includeDir).path}\", \"\"\"${file.readText().escapeTripleQuote()}\"\"\"")
173-
if (ktFile.exists()) append(", ktImpl = \"\"\"${ktFile.readText().escapeTripleQuote()}\"\"\"")
174-
if (cFile.exists()) append(", cImpl = \"\"\"${cFile.readText().escapeTripleQuote()}\"\"\"")
175-
append(")")
116+
private fun String.escapeTripleQuote(): String {
117+
return this.replace("$", "\${DOLLAR}").replace("\"\"\"", "\${TRIPLET}")
118+
}
119+
120+
private operator fun File.get(key: String) = File(this, key)
121+
private var File.textContent get() = this.readText(); set(value) = run { this.writeText(value) }
122+
123+
fun generateIncludes(): String {
124+
val lines = arrayListOf<String>()
125+
lines += GENERATED_DO_NOT_MODIFY
126+
lines += "package com.soywiz.ktcc.headers"
127+
lines += "private val DOLLAR = '$'"
128+
lines += "private val TRIPLET = \"\\\"\\\"\\\"\""
129+
lines += "val CStdIncludes = CIncludes().apply {"
130+
131+
val includeDir = File(rootDir, "include").absoluteFile
132+
for (file in includeDir.walkTopDown().toList().sortedBy { it.absolutePath }) {
133+
if (!file.name.endsWith(".h")) continue
134+
val ktFile = File(file.absolutePath.removeSuffix(".h") + ".kt")
135+
val cFile = File(file.absolutePath.removeSuffix(".h") + ".c")
136+
//println(file)
137+
lines += buildString {
138+
append("FILE(\"${file.relativeTo(includeDir).path}\", \"\"\"${file.readText().escapeTripleQuote()}\"\"\"")
139+
if (ktFile.exists()) append(", ktImpl = \"\"\"${ktFile.readText().escapeTripleQuote()}\"\"\"")
140+
if (cFile.exists()) append(", cImpl = \"\"\"${cFile.readText().escapeTripleQuote()}\"\"\"")
141+
append(")")
142+
}
176143
}
144+
145+
lines += "}.map.toMap()"
146+
lines += ""
147+
return lines.joinToString("\n")
177148
}
178149

179-
lines += "}.map.toMap()"
180-
lines += ""
181-
return lines.joinToString("\n")
150+
@TaskAction
151+
fun action() {
152+
File(rootDir, "build/gen/kotlin/com/soywiz/ktcc/internal/version.kt").also { it.parentFile.mkdirs() }.textContent = "package com.soywiz.ktcc.internal\n\ninternal val KTCC_VERSION = \"$version\""
153+
File(rootDir, "build/gen/kotlin/com/soywiz/ktcc/headers/CStdIncludesGenerated.kt").also { it.parentFile.mkdirs() }.writeText(generateIncludes())
154+
File(rootDir, "build/gen/kotlin/com/soywiz/ktcc/gen/KotlinGen.kt").also { it.parentFile.mkdirs() }.writeText(
155+
"$GENERATED_DO_NOT_MODIFY\n" +
156+
"package com.soywiz.ktcc.gen\n\n" +
157+
"private val DOLLAR = '$'\n" +
158+
"private val TRIPLET = \"\\\"\\\"\\\"\"\n" +
159+
"val KotlinRuntime = \"\"\"${File(rootDir, "src/commonMain/kotlin/Runtime.kt").readText().escapeTripleQuote()}\"\"\"\n" +
160+
"val KotlinRuntimeJvm = \"\"\"${File(rootDir, "src/jvmMain/kotlin/RuntimeJvm.kt").readText().escapeTripleQuote()}\"\"\"\n"
161+
)
162+
}
182163
}
183164

184-
File(rootDir, "build/gen/kotlin/com/soywiz/ktcc/headers/CStdIncludesGenerated.kt").also { it.parentFile.mkdirs() }.writeText(generateIncludes())
185-
File(rootDir, "build/gen/kotlin/com/soywiz/ktcc/gen/KotlinGen.kt").also { it.parentFile.mkdirs() }.writeText(
186-
"$GENERATED_DO_NOT_MODIFY\n" +
187-
"package com.soywiz.ktcc.gen\n\n" +
188-
"private val DOLLAR = '$'\n" +
189-
"private val TRIPLET = \"\\\"\\\"\\\"\"\n" +
190-
"val KotlinRuntime = \"\"\"${File(rootDir, "src/commonMain/kotlin/Runtime.kt").readText().escapeTripleQuote()}\"\"\"\n" +
191-
"val KotlinRuntimeJvm = \"\"\"${File(rootDir, "src/jvmMain/kotlin/RuntimeJvm.kt").readText().escapeTripleQuote()}\"\"\"\n"
192-
)
193-
194165
tasks {
195-
val runDceJsKotlin = named<KotlinJsDce>("runDceJsKotlin").get()
196-
create<Jar>("fatJar") {
166+
val generateSources by creating(GenerateSourcesTask::class)
167+
168+
//val runDceJsKotlin = named<KotlinJsDce>("runDceJsKotlin").get()
169+
val jvmJar by getting(Jar::class)
170+
171+
val compileKotlinJvm by getting(KotlinCompile::class)
172+
173+
compileKotlinJvm.dependsOn(generateSources)
174+
//println("compileKotlinJvm=${compileKotlinJvm::class}")
175+
176+
val fatJar by creating(Jar::class) {
197177
duplicatesStrategy = org.gradle.api.file.DuplicatesStrategy.INCLUDE
198178
archiveBaseName.set("${project.name}-all")
199179
//archiveVersion.set(null as String?)
@@ -204,65 +184,67 @@ tasks {
204184
attributes("Main-Class" to mainClassName)
205185
}
206186

207-
afterEvaluate {
208-
for (it in (kotlin.targets["jvm"].compilations["main"] as KotlinJvmCompilation).runtimeDependencyFiles) {
209-
from(if (it.isDirectory) it else zipTree(it))
210-
}
211-
}
187+
//println(configurations.names.toList())
188+
from(provider { configurations["jvmRuntimeClasspath"].map { if (it.isDirectory) it else zipTree(it) } })
212189

213-
with(named<Jar>("jvmJar").get())
190+
with(jvmJar)
214191
}
215192

216-
val jsWebResourcesDce = create<Copy>("jsWebResourcesDce") {
217-
dependsOn(runDceJsKotlin)
218-
into(rootDir["docs"])
219-
includeEmptyDirs = false
220-
from(kotlin.sourceSets["jsMain"].resources)
221-
from(kotlin.sourceSets["commonMain"].resources)
222-
}
193+
//val jsWebResourcesDce by creating(Copy::class) {
194+
// dependsOn(runDceJsKotlin)
195+
// into(file("docs"))
196+
// includeEmptyDirs = false
197+
// from(kotlin.sourceSets["jsMain"].resources)
198+
// from(kotlin.sourceSets["commonMain"].resources)
199+
//}
223200

224-
val jsWebResources = create<Copy>("jsWebResources") {
201+
val jsWebResources by creating(Copy::class) {
225202
dependsOn("jsMainClasses")
226-
into(rootDir["docs"])
203+
into(file("docs"))
227204
includeEmptyDirs = false
228205
from(kotlin.sourceSets["jsMain"].resources)
229206
from(kotlin.sourceSets["commonMain"].resources)
230207
}
231208

209+
//val jsWebDce by creating(Copy::class) {
210+
// dependsOn(jsWebResourcesDce)
211+
// into(file("docs"))
212+
// includeEmptyDirs = false
213+
// exclude("**/*.kjsm", "**/*.kotlin_metadata", "**/*.kotlin_module", "**/*.MF", "**/*.meta.js", "**/*.map")
214+
// from(named("compileProductionExecutableKotlinJs").get().outputs)
215+
//}
232216

233-
create<Copy>("jsWebDce") {
234-
dependsOn(jsWebResourcesDce)
235-
into(rootDir["docs"])
236-
includeEmptyDirs = false
237-
exclude("**/*.kjsm", "**/*.kotlin_metadata", "**/*.kotlin_module", "**/*.MF", "**/*.meta.js", "**/*.map")
238-
afterEvaluate {
239-
from(runDceJsKotlin.destinationDir)
240-
}
241-
}
242-
create<Copy>("jsWeb") {
217+
val jsWeb by creating(Copy::class) {
243218
dependsOn(jsWebResources)
244-
into(rootDir["docs"])
219+
into(file("docs"))
245220
includeEmptyDirs = false
246221
exclude("**/*.kjsm", "**/*.kotlin_metadata", "**/*.kotlin_module", "**/*.MF", "**/*.meta.js", "**/*.map")
247-
from(jsCompilations["main"].output.allOutputs)
248-
afterEvaluate {
249-
for (f in (jsCompilations["main"] as KotlinJsCompilation).runtimeDependencyFiles) if (f.exists() && !f.isDirectory()) from(zipTree(f.absolutePath))
250-
}
222+
//from(named("compileProductionExecutableKotlinJs").get().outputs)
223+
from(named("compileDevelopmentExecutableKotlinJs").get().outputs)
251224
}
252-
create<Task>("buildDockerImage") {
225+
226+
val buildDockerImage by creating {
253227
afterEvaluate {
254228
dependsOn("linkReleaseExecutableLinuxX64")
255229
}
256230
doLast {
257231
exec { commandLine = listOf("docker", "build", ".", "-t", "soywiz/ktcc:latest") }
258232
}
259233
}
260-
create<Task>("buildDockerImageAndPublish") {
234+
val buildDockerImageAndPublish by creating {
261235
dependsOn("buildDockerImage")
262236
doLast {
263237
exec { commandLine = listOf("docker", "push", "soywiz/ktcc:latest") }
264238
}
265239
}
240+
project.tasks.withType(ProcessResources::class) {
241+
this.dependsOn(generateSources)
242+
//println("resources=$this : ${this::class}")
243+
}
244+
245+
val prepare by creating {
246+
dependsOn(generateSources)
247+
}
266248
}
267249

268250
afterEvaluate {
@@ -295,4 +277,4 @@ idea {
295277
module {
296278
excludeDirs = excludeDirs + setOf(file(".gradle"), file("@old"), file("doc"), file("docs"), file("samples"), file("gradle"), file("build"), file("include"), file(".idea"), file(".github"), file("temp"), file("build/gen"))
297279
}
298-
}
280+
}

0 commit comments

Comments
 (0)