Skip to content

Commit

Permalink
KSP2: Fix support of wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
ting-yuan committed May 14, 2024
1 parent 9418d44 commit 51c8e7b
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ abstract class KspAAWorkerAction : WorkAction<KspAAWorkParameter> {
KotlinPlatformType.js, KotlinPlatformType.wasm -> {
KSPJsConfig.Builder().apply {
this.setupSuper()
backend = if (platformType == KotlinPlatformType.js) "JS" else "Wasm"
backend = if (platformType == KotlinPlatformType.js) "JS" else "WASM"
}.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,30 @@ class KMPImplementedIT(useKSP2: Boolean) {
}
}

@Test
fun testWasm() {
Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows", ignoreCase = true))
val gradleRunner = GradleRunner.create().withProjectDir(project.root)

gradleRunner.withArguments(
"--configuration-cache-problems=warn",
"clean",
":workload-wasm:build"
).build().let {
Assert.assertEquals(TaskOutcome.SUCCESS, it.task(":workload-wasm:build")?.outcome)
verify(
"workload-wasm/build/libs/workload-wasm-wasm-js-1.0-SNAPSHOT.klib",
listOf(
"default/ir/types.knt"
)
)
Assert.assertFalse(it.output.contains("kotlin scripting plugin:"))
Assert.assertTrue(it.output.contains("w: [ksp] platforms: [wasm-js"))
Assert.assertTrue(it.output.contains("w: [ksp] List has superTypes: true"))
checkExecutionOptimizations(it.output)
}
}

@Test
fun testJsErrorLog() {
Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows", ignoreCase = true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ kotlin {
browser()
nodejs()
}
wasmJs {
browser()
binaries.executable()
}
linuxX64() {
}
androidNativeX64() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include(":annotations")
include(":workload")
include(":workload-jvm")
include(":workload-js")
include(":workload-wasm")
include(":workload-linuxX64")
include(":workload-androidNative")
include(":test-processor")
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
plugins {
kotlin("multiplatform")
id("com.google.devtools.ksp")
}

version = "1.0-SNAPSHOT"

kotlin {
wasmJs {
binaries.executable()
browser()
}
sourceSets {
val wasmJsMain by getting {
dependencies {
implementation(project(":annotations"))
}
}
}
}

dependencies {
add("kspCommonMainMetadata", project(":test-processor"))
add("kspWasmJs", project(":test-processor"))
add("kspWasmJsTest", project(":test-processor"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example

class Bar {
val baz = Foo().baz
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example

class Baz {
val bar = Foo().bar
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example

// https://github.com/google/ksp/issues/632
@MyAnnotation
@ExperimentalMultiplatform
class ToBeValidated {
// https://github.com/google/ksp/issues/574
val ToBeInferred = listOf("string")
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ kotlin {
browser()
nodejs()
}
wasmJs {
browser()
binaries.executable()
}
linuxX64() {
binaries {
executable()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example

class Bar {
val baz = Foo().baz
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example

class Baz {
val bar = Foo().bar
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class KotlinSymbolProcessing(
JvmPlatforms.jvmPlatformByTargetVersion(jvmTarget)
}
is KSPJsConfig -> when (kspConfig.backend) {
"WASM" -> WasmPlatforms.Default
"WASM" -> WasmPlatforms.wasmJs
"JS" -> JsPlatforms.defaultJsPlatform
else -> throw IllegalArgumentException("Unknown JS backend: ${kspConfig.backend}")
}
Expand Down

0 comments on commit 51c8e7b

Please sign in to comment.