Skip to content

Commit

Permalink
Support WASM (#275)
Browse files Browse the repository at this point in the history
* Add WASM support
* Add implicit casts to `contentDeepEquals` (etc.) call arguments
* Node.js 21.0.0-v8-canary20231024d0ddc81258

WASM requires a canary Node.js version until nodejs/node#50115 lands. This uses the last v21 canary, which has both darwin-arm64 and darwin-x64 artifacts.

---------

Co-authored-by: Jake Wharton <[email protected]>
  • Loading branch information
drewhamilton and JakeWharton authored Dec 15, 2023
1 parent fc5ebe3 commit 942d194
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
16 changes: 16 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import dev.drewhamilton.poko.build.setUpLocalSigning
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand All @@ -11,6 +14,19 @@ plugins {
alias(libs.plugins.ksp) apply false
}

plugins.withType<NodeJsRootPlugin> {
extensions.getByType<NodeJsRootExtension>().apply {
// WASM requires a canary Node.js version. This is the last v21 canary, and has both
// darwin-arm64 and darwin-x64 artifacts:
nodeVersion = "21.0.0-v8-canary20231024d0ddc81258"
nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
}
}

tasks.withType<KotlinNpmInstallTask>().configureEach {
args.add("--ignore-engines")
}

allprojects {
group = rootProject.property("GROUP")!!
version = rootProject.property("VERSION_NAME")!!
Expand Down
2 changes: 2 additions & 0 deletions poko-annotations/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ kotlin {
tvosX64()
tvosSimulatorArm64()

wasmJs().nodejs()

watchosArm32()
watchosArm64()
watchosDeviceArm64()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ private fun IrBuilderWithScope.irArrayTypeCheckAndContentDeepEqualsBranch(
condition = irIs(argument, type),
thenPart = irCallContentDeepEquals(
classifier = classSymbol,
receiver = receiver,
argument = argument,
receiver = irImplicitCast(receiver, type),
argument = irImplicitCast(argument, type),
),
elsePart = irFalse(),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.ir.builders.irElseBranch
import org.jetbrains.kotlin.ir.builders.irGet
import org.jetbrains.kotlin.ir.builders.irGetField
import org.jetbrains.kotlin.ir.builders.irIfNull
import org.jetbrains.kotlin.ir.builders.irImplicitCast
import org.jetbrains.kotlin.ir.builders.irInt
import org.jetbrains.kotlin.ir.builders.irIs
import org.jetbrains.kotlin.ir.builders.irReturn
Expand Down Expand Up @@ -232,7 +233,7 @@ private fun IrBlockBodyBuilder.irArrayTypeCheckAndContentDeepHashCodeBranch(
callee = findArrayContentDeepHashCodeFunction(classSymbol),
type = context.irBuiltIns.intType,
).apply {
extensionReceiver = value
extensionReceiver = irImplicitCast(value, type)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.ir.builders.irCall
import org.jetbrains.kotlin.ir.builders.irConcat
import org.jetbrains.kotlin.ir.builders.irElseBranch
import org.jetbrains.kotlin.ir.builders.irGetField
import org.jetbrains.kotlin.ir.builders.irImplicitCast
import org.jetbrains.kotlin.ir.builders.irIs
import org.jetbrains.kotlin.ir.builders.irReturn
import org.jetbrains.kotlin.ir.builders.irString
Expand Down Expand Up @@ -175,7 +176,7 @@ private fun IrBlockBodyBuilder.irArrayTypeCheckAndContentDeepToStringBranch(
condition = irIs(value, type),
result = irCallToStringFunction(
toStringFunctionSymbol = findContentDeepToStringFunctionSymbol(classSymbol),
value = value,
value = irImplicitCast(value, type),
),
)
}
Expand Down
3 changes: 3 additions & 0 deletions poko-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ kotlin {
tvosSimulatorArm64()
tvosSimulatorArm64("tvosSimulatorArm64K2").applyK2()

wasmJs().nodejs()
wasmJs("wasmJsK2").applyK2().nodejs()

watchosArm32()
watchosArm32("watchosArm32K2").applyK2()
watchosArm64()
Expand Down

0 comments on commit 942d194

Please sign in to comment.