Skip to content

Commit ce06a62

Browse files
authored
Add stub targets tags for platforms table (#397)
1 parent f6f6c12 commit ce06a62

File tree

5 files changed

+76
-32
lines changed

5 files changed

+76
-32
lines changed

docs/pages/kotlinx-rpc/topics/platforms.topic

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
- Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
4+
-->
5+
26
<!DOCTYPE topic
37
SYSTEM "https://resources.jetbrains.com/writerside/1.0/xhtml-entities.dtd">
48
<!--suppress WrsMissingSpaceChecker -->
@@ -47,8 +51,13 @@
4751
</table>
4852

4953
<p>
50-
The following table contains a list of all published modules and their supported platforms:
54+
The following table contains a list of all published modules and their supported platforms.
5155
</p>
56+
<note>
57+
Targets marked with the <b>[stub]</b> tag have published artifacts,
58+
but their runtime functionally is not supported.
59+
This is done to make sure that user projects sync without errors when some target is not present.
60+
</note>
5261
<table>
5362
<tr>
5463
<td>Module</td>

gradle-conventions/src/main/kotlin/util/targets/kmpConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class KmpConfig(
5656
private val excludeJvm: Boolean by optionalProperty("exclude")
5757
private val excludeJs: Boolean by optionalProperty("exclude")
5858
private val excludeWasmJs: Boolean by optionalProperty("exclude")
59-
private val excludeWasmJsD8: Boolean by optionalProperty("exclude")
59+
private val excludeWasmJsD8: Boolean by optionalProperty("exclude", "wasmJs")
6060
private val excludeWasmWasi: Boolean by optionalProperty("exclude")
6161
val excludeNative: Boolean by optionalProperty("exclude")
6262

gradle-conventions/src/main/kotlin/util/tasks/platformTable.kt

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
2323
import util.KOTLIN_JVM_PLUGIN_ID
2424
import util.KOTLIN_MULTIPLATFORM_PLUGIN_ID
2525
import util.other.isPublicModule
26+
import util.other.optionalPropertyValue
2627
import java.io.File
2728
import java.nio.file.Files
2829

@@ -38,13 +39,15 @@ enum class TableColumn {
3839
sealed interface PlatformTarget {
3940
val name: String
4041
val subtargets: List<PlatformTarget>
42+
val stub: Boolean get() = false
4143

4244
class Group(
4345
override val name: String,
4446
override val subtargets: List<PlatformTarget>,
47+
override val stub: Boolean,
4548
) : PlatformTarget
4649

47-
class LeafTarget(override val name: String) : PlatformTarget {
50+
class LeafTarget(override val name: String, override val stub: Boolean) : PlatformTarget {
4851
override val subtargets: List<PlatformTarget> = emptyList()
4952
}
5053
}
@@ -113,32 +116,44 @@ abstract class DumpPlatformsTask : DefaultTask() {
113116
.mapValues { (platform, targets) ->
114117
when (platform) {
115118
KotlinPlatformType.jvm -> {
116-
PlatformTarget.LeafTarget(TableColumn.Jvm.name.lowercase())
119+
val isStub = subproject.optionalPropertyValue(targets[0].name, "stub")
120+
PlatformTarget.LeafTarget(TableColumn.Jvm.name.lowercase(), isStub)
117121
}
118122

119123
KotlinPlatformType.js -> {
120-
val subtargets = targets.jsOrWasmSubTargets("js", subproject) {
124+
val (target, subtargets) = targets.jsOrWasmSubTargets("js", subproject) {
121125
it is KotlinJsIrTarget
122-
}
126+
} ?: return@mapValues null
123127

124-
PlatformTarget.Group(TableColumn.Js.name, subtargets)
128+
val isStub = subproject.optionalPropertyValue(target.name, "stub")
129+
PlatformTarget.Group(TableColumn.Js.name, subtargets, isStub)
125130
}
126131

127132
KotlinPlatformType.wasm -> {
128-
val jsSubtargets = targets.jsOrWasmSubTargets("wasmJs", subproject) {
133+
val (jsTarget, jsSubtargets) = targets.jsOrWasmSubTargets("wasmJs", subproject) {
129134
it is KotlinWasmJsTargetDsl && it.wasmTargetType == KotlinWasmTargetType.JS
130-
}
135+
} ?: (null to emptyList())
131136

132-
val wasiSubtargets = targets.jsOrWasmSubTargets("wasmWasi", subproject) {
137+
val (wasiTarget, wasiSubtargets) = targets.jsOrWasmSubTargets("wasmWasi", subproject) {
133138
it is KotlinWasmWasiTargetDsl && it.wasmTargetType == KotlinWasmTargetType.WASI
134-
}
139+
} ?: (null to emptyList())
140+
141+
val jsIsStub = jsTarget?.name
142+
?.let { subproject.optionalPropertyValue(it, "stub") } ?: false
143+
144+
val wasiIsStub = wasiTarget?.name
145+
?.let { subproject.optionalPropertyValue(it, "stub") } ?: false
135146

136147
val wasmSubtargets = listOfNotNull(
137-
PlatformTarget.Group("wasmJs", jsSubtargets).takeIf { jsSubtargets.isNotEmpty() },
138-
PlatformTarget.Group("wasmWasi", wasiSubtargets).takeIf { wasiSubtargets.isNotEmpty() },
148+
PlatformTarget.Group("wasmJs", jsSubtargets, jsIsStub).takeIf { jsSubtargets.isNotEmpty() },
149+
PlatformTarget.Group("wasmWasi", wasiSubtargets, wasiIsStub).takeIf { wasiSubtargets.isNotEmpty() },
139150
)
140151

141-
PlatformTarget.Group(TableColumn.Wasm.name, wasmSubtargets)
152+
PlatformTarget.Group(
153+
name = TableColumn.Wasm.name,
154+
subtargets = wasmSubtargets,
155+
stub = subproject.optionalPropertyValue(TableColumn.Wasm.name, "stub"),
156+
)
142157
}
143158

144159
KotlinPlatformType.native -> {
@@ -148,15 +163,17 @@ abstract class DumpPlatformsTask : DefaultTask() {
148163
PlatformTarget.Group(
149164
name = "apple",
150165
subtargets = listOf(
151-
targets.nativeGroup("ios"),
152-
targets.nativeGroup("macos"),
153-
targets.nativeGroup("watchos"),
154-
targets.nativeGroup("tvos"),
166+
targets.nativeGroup(subproject, "ios"),
167+
targets.nativeGroup(subproject, "macos"),
168+
targets.nativeGroup(subproject, "watchos"),
169+
targets.nativeGroup(subproject, "tvos"),
155170
),
171+
stub = subproject.optionalPropertyValue("apple", "stub"),
156172
),
157-
targets.nativeGroup("linux"),
158-
targets.nativeGroup("windows", "mingw"),
159-
)
173+
targets.nativeGroup(subproject, "linux"),
174+
targets.nativeGroup(subproject, "windows", "mingw"),
175+
),
176+
stub = subproject.optionalPropertyValue(TableColumn.Native.name, "stub"),
160177
)
161178
}
162179

@@ -173,29 +190,34 @@ abstract class DumpPlatformsTask : DefaultTask() {
173190
name: String,
174191
project: Project,
175192
condition: (KotlinTarget) -> Boolean,
176-
): List<PlatformTarget.LeafTarget> {
193+
): Pair<KotlinTarget, List<PlatformTarget.LeafTarget>>? {
177194
val foundTargets = filter(condition)
178195
.filterIsInstance<KotlinJsIrTarget>()
179196

180197
if (foundTargets.isEmpty()) {
181-
return emptyList()
198+
return null
182199
}
183200

184201
if (foundTargets.size > 1) {
185202
error("Multiple $name targets are not supported (project ${project.name})")
186203
}
187204

188-
val jsSubtargets = foundTargets.single().subTargets.map { subTargetWithBinary ->
189-
PlatformTarget.LeafTarget(subTargetWithBinary.name)
205+
val target = foundTargets.single()
206+
val jsSubtargets = target.subTargets.map { subTargetWithBinary ->
207+
val isStub = project.optionalPropertyValue(subTargetWithBinary.name, "stub", target.name)
208+
PlatformTarget.LeafTarget(subTargetWithBinary.name, isStub)
190209
}
191210

192-
return jsSubtargets
211+
return target to jsSubtargets
193212
}
194213

195-
private fun List<KotlinTarget>.nativeGroup(name: String, prefix: String = name): PlatformTarget.Group {
214+
private fun List<KotlinTarget>.nativeGroup(subproject: Project, name: String, prefix: String = name): PlatformTarget.Group {
196215
return PlatformTarget.Group(
197216
name = name,
198-
subtargets = filter { it.name.startsWith(prefix) }.map { PlatformTarget.LeafTarget(it.name) },
217+
subtargets = filter { it.name.startsWith(prefix) }.map {
218+
PlatformTarget.LeafTarget(it.name, subproject.optionalPropertyValue(it.name, "stub"))
219+
},
220+
stub = subproject.optionalPropertyValue(name, "stub")
199221
)
200222
}
201223

@@ -224,12 +246,25 @@ abstract class DumpPlatformsTask : DefaultTask() {
224246

225247
is PlatformTarget.LeafTarget -> {
226248
append(target.name)
249+
if (target.stub) {
250+
append(" <b>[stub]</b>")
251+
}
227252
}
228253

229254
is PlatformTarget.Group -> {
230-
if (!topLevel) {
231-
append(target.name)
255+
when {
256+
!topLevel -> {
257+
append(target.name)
258+
if (target.stub) {
259+
append(" <b>[stub]</b>")
260+
}
261+
}
262+
263+
target.stub -> {
264+
append("<b>[stubs]</b>")
265+
}
232266
}
267+
233268
append("<list>")
234269
target.subtargets.forEach { subtarget ->
235270
append("<li>")

krpc/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
# Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
#
44

55
# https://github.com/oshai/kotlin-logging/issues/433

krpc/krpc-test/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#
44

55
# tests fail with some obscure reason
6-
kotlinx.rpc.exclude.wasmJsD8=true
6+
kotlinx.rpc.exclude.wasmJs.d8=true

0 commit comments

Comments
 (0)