Skip to content

Commit 51c8e7b

Browse files
committed
KSP2: Fix support of wasm
1 parent 9418d44 commit 51c8e7b

File tree

12 files changed

+90
-2
lines changed

12 files changed

+90
-2
lines changed

gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspAATask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ abstract class KspAAWorkerAction : WorkAction<KspAAWorkParameter> {
475475
KotlinPlatformType.js, KotlinPlatformType.wasm -> {
476476
KSPJsConfig.Builder().apply {
477477
this.setupSuper()
478-
backend = if (platformType == KotlinPlatformType.js) "JS" else "Wasm"
478+
backend = if (platformType == KotlinPlatformType.js) "JS" else "WASM"
479479
}.build()
480480
}
481481

integration-tests/src/test/kotlin/com/google/devtools/ksp/test/KMPImplementedIT.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,30 @@ class KMPImplementedIT(useKSP2: Boolean) {
108108
}
109109
}
110110

111+
@Test
112+
fun testWasm() {
113+
Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows", ignoreCase = true))
114+
val gradleRunner = GradleRunner.create().withProjectDir(project.root)
115+
116+
gradleRunner.withArguments(
117+
"--configuration-cache-problems=warn",
118+
"clean",
119+
":workload-wasm:build"
120+
).build().let {
121+
Assert.assertEquals(TaskOutcome.SUCCESS, it.task(":workload-wasm:build")?.outcome)
122+
verify(
123+
"workload-wasm/build/libs/workload-wasm-wasm-js-1.0-SNAPSHOT.klib",
124+
listOf(
125+
"default/ir/types.knt"
126+
)
127+
)
128+
Assert.assertFalse(it.output.contains("kotlin scripting plugin:"))
129+
Assert.assertTrue(it.output.contains("w: [ksp] platforms: [wasm-js"))
130+
Assert.assertTrue(it.output.contains("w: [ksp] List has superTypes: true"))
131+
checkExecutionOptimizations(it.output)
132+
}
133+
}
134+
111135
@Test
112136
fun testJsErrorLog() {
113137
Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows", ignoreCase = true))

integration-tests/src/test/resources/kmp/annotations/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ kotlin {
1212
browser()
1313
nodejs()
1414
}
15+
wasmJs {
16+
browser()
17+
binaries.executable()
18+
}
1519
linuxX64() {
1620
}
1721
androidNativeX64() {

integration-tests/src/test/resources/kmp/settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ include(":annotations")
1919
include(":workload")
2020
include(":workload-jvm")
2121
include(":workload-js")
22+
include(":workload-wasm")
2223
include(":workload-linuxX64")
2324
include(":workload-androidNative")
2425
include(":test-processor")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
plugins {
2+
kotlin("multiplatform")
3+
id("com.google.devtools.ksp")
4+
}
5+
6+
version = "1.0-SNAPSHOT"
7+
8+
kotlin {
9+
wasmJs {
10+
binaries.executable()
11+
browser()
12+
}
13+
sourceSets {
14+
val wasmJsMain by getting {
15+
dependencies {
16+
implementation(project(":annotations"))
17+
}
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
add("kspCommonMainMetadata", project(":test-processor"))
24+
add("kspWasmJs", project(":test-processor"))
25+
add("kspWasmJsTest", project(":test-processor"))
26+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.example
2+
3+
class Bar {
4+
val baz = Foo().baz
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.example
2+
3+
class Baz {
4+
val bar = Foo().bar
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.example
2+
3+
// https://github.com/google/ksp/issues/632
4+
@MyAnnotation
5+
@ExperimentalMultiplatform
6+
class ToBeValidated {
7+
// https://github.com/google/ksp/issues/574
8+
val ToBeInferred = listOf("string")
9+
}

integration-tests/src/test/resources/kmp/workload/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ kotlin {
1313
browser()
1414
nodejs()
1515
}
16+
wasmJs {
17+
browser()
18+
binaries.executable()
19+
}
1620
linuxX64() {
1721
binaries {
1822
executable()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.example
2+
3+
class Bar {
4+
val baz = Foo().baz
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.example
2+
3+
class Baz {
4+
val bar = Foo().bar
5+
}

kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/KotlinSymbolProcessing.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class KotlinSymbolProcessing(
182182
JvmPlatforms.jvmPlatformByTargetVersion(jvmTarget)
183183
}
184184
is KSPJsConfig -> when (kspConfig.backend) {
185-
"WASM" -> WasmPlatforms.Default
185+
"WASM" -> WasmPlatforms.wasmJs
186186
"JS" -> JsPlatforms.defaultJsPlatform
187187
else -> throw IllegalArgumentException("Unknown JS backend: ${kspConfig.backend}")
188188
}

0 commit comments

Comments
 (0)