Skip to content

Commit 6abdf34

Browse files
committed
undo
1 parent 5a50657 commit 6abdf34

File tree

7 files changed

+151
-130
lines changed

7 files changed

+151
-130
lines changed

core/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import util.applyAtomicfuPlugin
1010

1111
plugins {
1212
alias(libs.plugins.conventions.kmp)
13-
alias(libs.plugins.kotlinx.rpc)
14-
alias(libs.plugins.serialization)
1513
}
1614

1715
applyAtomicfuPlugin()

gradle-conventions-settings/src/main/kotlin/util/JsTarget.kt

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,77 +4,53 @@
44

55
package util
66

7-
import org.gradle.api.Action
7+
import org.gradle.kotlin.dsl.getValue
8+
import org.gradle.kotlin.dsl.getting
89
import org.gradle.kotlin.dsl.invoke
9-
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
1010
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
11-
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
1211
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
1312
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
1413
import java.io.File
1514

1615
fun ProjectKotlinConfig.configureJsAndWasmJs() {
17-
configureJsAndWasmJsTasks()
16+
if (!js) {
17+
return
18+
}
1819

1920
kotlin {
20-
sourceSets {
21-
if (js) {
22-
jsTest {
23-
puppeteer()
24-
}
25-
}
26-
27-
if (wasmJs) {
28-
wasmJsMain {
29-
dependencies {
30-
implementation(libs.kotlinx.browser)
31-
}
32-
}
21+
js(IR) {
22+
configureJsAndWasmJsTasks()
23+
}
3324

34-
wasmJsTest {
35-
puppeteer()
36-
}
25+
sourceSets {
26+
val jsTest by getting {
27+
puppeteer()
3728
}
3829
}
3930
}
4031
}
4132

42-
private fun KotlinSourceSet.puppeteer() {
33+
fun KotlinSourceSet.puppeteer() {
4334
dependencies {
4435
implementation(npm("puppeteer", "*"))
4536
}
4637
}
4738

48-
private fun ProjectKotlinConfig.configureJsAndWasmJsTasks() {
49-
kotlin {
50-
jsAnsWasmJs(this@configureJsAndWasmJsTasks) {
51-
nodejs {
52-
testTask {
53-
useMocha {
54-
timeout = "10000"
55-
}
56-
}
39+
fun KotlinJsTargetDsl.configureJsAndWasmJsTasks() {
40+
nodejs {
41+
testTask {
42+
useMocha {
43+
timeout = "10000"
5744
}
45+
}
46+
}
5847

59-
(this as KotlinJsIrTarget).whenBrowserConfigured {
60-
testTask {
61-
useKarma {
62-
useChromeHeadless()
63-
useConfigDirectory(File(project.rootProject.projectDir, "karma"))
64-
}
65-
}
48+
(this as KotlinJsIrTarget).whenBrowserConfigured {
49+
testTask {
50+
useKarma {
51+
useChromeHeadless()
52+
useConfigDirectory(File(project.rootProject.projectDir, "karma"))
6653
}
6754
}
6855
}
6956
}
70-
71-
@OptIn(ExperimentalWasmDsl::class)
72-
private fun KotlinMultiplatformExtension.jsAnsWasmJs(
73-
config: ProjectKotlinConfig,
74-
configure: Action<KotlinJsTargetDsl>,
75-
) {
76-
listOfNotNull(
77-
if (config.js) js(IR) else null,
78-
if (config.wasmJs) wasmJs() else null,
79-
).forEach { configure(it) }
80-
}

gradle-conventions-settings/src/main/kotlin/util/ProjectKotlinConfig.kt

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,80 @@
44

55
package util
66

7+
import groovy.json.JsonSlurper
78
import org.gradle.api.Project
89
import org.gradle.kotlin.dsl.extra
910
import org.gradle.kotlin.dsl.provideDelegate
11+
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
12+
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
13+
import java.io.File
14+
import kotlin.reflect.full.memberFunctions
15+
16+
const val UNSUPPORTED_TARGET = "-"
17+
const val FULLY_SUPPORTED_TARGET = "*"
18+
const val TARGETS_SINCE_KOTLIN_LOOKUP_PATH = "versions-root/targets-since-kotlin-lookup.json"
19+
20+
/**
21+
* In the lookup table:
22+
* "*" – target supported any Kotlin compiler version
23+
* "-" – target supported none of Kotlin compiler versions
24+
* "<some_version>" – target supported since a <some_version> Kotlin version including that version
25+
*/
26+
@Suppress("UNCHECKED_CAST")
27+
private fun loadTargetsSinceKotlinLookupTable(rootDir: String): Map<String, String> {
28+
val file = File("$rootDir/$TARGETS_SINCE_KOTLIN_LOOKUP_PATH")
29+
val table = JsonSlurper()
30+
.parseText(file.readText(Charsets.UTF_8)) as Map<String, String>
31+
32+
return table.filterValues { value -> value != UNSUPPORTED_TARGET }
33+
}
1034

1135
class ProjectKotlinConfig(
1236
project: Project,
1337
val kotlinVersion: KotlinVersion,
14-
val jvm: Boolean = true,
15-
val js: Boolean = true,
16-
val wasmJs: Boolean = true,
17-
val wasmWasi: Boolean = true,
38+
jvm: Boolean = true,
39+
js: Boolean = true,
40+
wasmJs: Boolean = true,
41+
wasmWasi: Boolean = true,
1842
val native: Boolean = true,
19-
) : Project by project
43+
) : Project by project {
44+
private val targetsLookup by lazy {
45+
val globalRootDir: String by extra
46+
loadTargetsSinceKotlinLookupTable(globalRootDir)
47+
}
48+
49+
private fun isIncluded(
50+
targetName: String,
51+
kotlinVersion: KotlinVersion,
52+
lookupTable: Map<String, String>,
53+
): Boolean {
54+
return lookupTable[targetName]?.let { sinceKotlin ->
55+
sinceKotlin == FULLY_SUPPORTED_TARGET || sinceKotlin.kotlinVersionParsed() <= kotlinVersion
56+
} ?: false
57+
}
58+
59+
val jvm: Boolean by lazy { jvm && isIncluded("jvm", kotlinVersion, targetsLookup) }
60+
val js: Boolean by lazy { js && isIncluded("js", kotlinVersion, targetsLookup) }
61+
val wasmJs: Boolean by lazy { wasmJs && isIncluded("wasmJs", kotlinVersion, targetsLookup) }
62+
val wasmWasi: Boolean by lazy { wasmWasi && isIncluded("wasmWasi", kotlinVersion, targetsLookup) }
63+
64+
private val nativeLookup by lazy {
65+
targetsLookup.filterKeys { key ->
66+
key != "jvm" && key != "js" && !key.startsWith("wasm")
67+
}
68+
}
69+
70+
fun nativeTargets(kmp: KotlinMultiplatformExtension) = kmp::class.memberFunctions
71+
.filter { targetFunction ->
72+
targetFunction.parameters.size == 1 && isIncluded(
73+
targetName = targetFunction.name,
74+
kotlinVersion = kotlinVersion,
75+
lookupTable = nativeLookup,
76+
)
77+
}.map { function ->
78+
function.call(kmp) as KotlinTarget
79+
}
80+
}
2081

2182
fun Project.withKotlinConfig(configure: ProjectKotlinConfig.() -> Unit) {
2283
val kotlinVersion: KotlinVersion by extra

gradle-conventions-settings/src/main/kotlin/util/TargetUtils.kt

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,19 @@
44

55
package util
66

7-
import groovy.json.JsonSlurper
87
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
98
import org.gradle.api.Action
109
import org.gradle.api.Project
1110
import org.gradle.jvm.toolchain.JavaLanguageVersion
1211
import org.gradle.kotlin.dsl.the
1312
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
1413
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
15-
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
16-
import java.io.File
17-
import kotlin.reflect.full.memberFunctions
18-
19-
const val UNSUPPORTED_TARGET = "-"
20-
const val FULLY_SUPPORTED_TARGET = "*"
21-
const val TARGETS_SINCE_KOTLIN_LOOKUP_PATH = "versions-root/targets-since-kotlin-lookup.json"
22-
23-
/**
24-
* In the lookup table:
25-
* "*" – target supported any Kotlin compiler version
26-
* "-" – target supported none of Kotlin compiler versions
27-
* "<some_version>" – target supported since a <some_version> Kotlin version including that version
28-
*/
29-
@Suppress("UNCHECKED_CAST")
30-
private fun loadTargetsSinceKotlinLookupTable(rootDir: String): Map<String, String> {
31-
val file = File("$rootDir/$TARGETS_SINCE_KOTLIN_LOOKUP_PATH")
32-
val table = JsonSlurper()
33-
.parseText(file.readText(Charsets.UTF_8)) as Map<String, String>
34-
35-
return table.filterValues { value -> value != UNSUPPORTED_TARGET }
36-
}
3714

38-
private fun isIncluded(targetName: String, kotlinVersion: KotlinVersion, lookupTable: Map<String, String>): Boolean {
39-
return lookupTable[targetName]?.let { sinceKotlin ->
40-
sinceKotlin == FULLY_SUPPORTED_TARGET || sinceKotlin.kotlinVersionParsed() <= kotlinVersion
41-
} ?: false
42-
}
43-
44-
@OptIn(ExperimentalWasmDsl::class)
45-
private fun KotlinMultiplatformExtension.configureTargets(
46-
targetsLookup: Map<String, String>,
47-
config: ProjectKotlinConfig,
48-
): List<KotlinTarget> {
15+
private fun KotlinMultiplatformExtension.configureTargets(config: ProjectKotlinConfig): List<KotlinTarget> {
4916
val targets = mutableListOf<KotlinTarget>()
5017

5118
if (config.native) {
52-
val nativeLookup = targetsLookup.filterKeys { key ->
53-
key != "jvm" && key != "js" && !key.startsWith("wasm")
54-
}
55-
56-
val nativeTargets = this::class.memberFunctions
57-
.filter { targetFunction ->
58-
targetFunction.parameters.size == 1 && isIncluded(
59-
targetName = targetFunction.name,
60-
kotlinVersion = config.kotlinVersion,
61-
lookupTable = nativeLookup,
62-
)
63-
}.map { function ->
64-
function.call(this) as KotlinTarget
65-
}
66-
19+
val nativeTargets = config.nativeTargets(this)
6720
targets.addAll(nativeTargets)
6821

6922
// TLDR: Default hierarchy template is enabled by default since 1.9.20
@@ -85,11 +38,11 @@ private fun KotlinMultiplatformExtension.configureTargets(
8538
}
8639
}
8740

88-
if (config.jvm && isIncluded("jvm", config.kotlinVersion, targetsLookup)) {
41+
if (config.jvm) {
8942
jvm().also { targets.add(it) }
9043
}
9144

92-
if (config.js && isIncluded("js", config.kotlinVersion, targetsLookup)) {
45+
if (config.js) {
9346
js(IR) {
9447
nodejs()
9548
browser()
@@ -98,23 +51,6 @@ private fun KotlinMultiplatformExtension.configureTargets(
9851
}.also { targets.add(it) }
9952
}
10053

101-
if (config.wasmJs && isIncluded("wasmJs", config.kotlinVersion, targetsLookup)) {
102-
wasmJs {
103-
browser()
104-
nodejs()
105-
106-
binaries.library()
107-
}
108-
}
109-
110-
if (config.wasmWasi && isIncluded("wasmWasi", config.kotlinVersion, targetsLookup)) {
111-
wasmWasi {
112-
nodejs()
113-
114-
binaries.library()
115-
}
116-
}
117-
11854
targets.forEach { target ->
11955
target.mavenPublication {
12056
setPublicArtifactId(config.project)
@@ -133,12 +69,10 @@ private fun Project.configureDetekt(targets: List<KotlinTarget>) {
13369
}
13470

13571
fun ProjectKotlinConfig.configureKotlin(action: Action<KotlinMultiplatformExtension> = Action { }) {
136-
val lookupTable = loadTargetsSinceKotlinLookupTable(rootProject.rootDir.absolutePath)
137-
13872
configureJsAndWasmJs()
13973

14074
kotlin {
141-
val includedTargets = configureTargets(lookupTable, this@configureKotlin)
75+
val includedTargets = configureTargets(this@configureKotlin)
14276

14377
configureDetekt(includedTargets)
14478

gradle-conventions/src/main/kotlin/conventions-kmp.gradle.kts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
*/
44

55
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
6-
import util.configureJvm
7-
import util.configureKotlin
8-
import util.optInForRPCApi
9-
import util.withKotlinConfig
6+
import util.*
107

118
plugins {
129
id("conventions-common")
@@ -21,6 +18,7 @@ configure<KotlinMultiplatformExtension> {
2118

2219
withKotlinConfig {
2320
configureKotlin()
21+
configureWasm()
2422
}
2523

2624
configureJvm(isKmp = true)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package util
6+
7+
import org.gradle.kotlin.dsl.invoke
8+
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
9+
10+
@OptIn(ExperimentalWasmDsl::class)
11+
fun ProjectKotlinConfig.configureWasm() {
12+
kotlin {
13+
if (wasmJs) {
14+
wasmJs {
15+
configureJsAndWasmJsTasks()
16+
17+
browser()
18+
nodejs()
19+
d8()
20+
21+
binaries.library()
22+
}
23+
24+
sourceSets {
25+
wasmJsMain {
26+
dependencies {
27+
implementation(libs.kotlinx.browser)
28+
}
29+
}
30+
31+
wasmJsTest {
32+
puppeteer()
33+
}
34+
}
35+
}
36+
37+
if (wasmWasi) {
38+
wasmWasi {
39+
nodejs()
40+
41+
binaries.library()
42+
}
43+
}
44+
}
45+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package util
6+
7+
fun ProjectKotlinConfig.configureWasm() {
8+
// do nothing
9+
}

0 commit comments

Comments
 (0)