Skip to content

Commit c2aec04

Browse files
committed
Implement Wasm targets
1 parent d977f55 commit c2aec04

File tree

7 files changed

+142
-36
lines changed

7 files changed

+142
-36
lines changed

benchmarks/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ kotlin {
3030
}
3131
}
3232

33+
//TODO: Add wasm benchmarks as soon as wasmJs/wasmWasi will be published
34+
3335
sourceSets.all {
3436
kotlin.setSrcDirs(listOf("$name/src"))
3537
resources.setSrcDirs(listOf("$name/resources"))

build.gradle.kts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile
2+
13
buildscript {
24
dependencies {
3-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0")
5+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21")
46
}
57
}
68

@@ -26,5 +28,13 @@ allprojects {
2628

2729
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>> {
2830
kotlinOptions.allWarningsAsErrors = true
31+
kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes"
32+
if (this is KotlinJsCompile) {
33+
kotlinOptions.freeCompilerArgs += "-Xwasm-enable-array-range-checks"
34+
}
2935
}
36+
}
37+
38+
tasks.withType<org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask>().configureEach {
39+
args.add("--ignore-engines")
3040
}

core/build.gradle.kts

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,34 @@ mavenPublicationsPom {
1414
}
1515

1616
kotlin {
17-
infra {
18-
// According to https://kotlinlang.org/docs/native-target-support.html
19-
20-
// Tier 1
21-
target("linuxX64")
22-
target("macosX64")
23-
target("macosArm64")
24-
target("iosSimulatorArm64")
25-
target("iosX64")
26-
27-
// Tier 2
28-
target("linuxArm64")
29-
target("watchosSimulatorArm64")
30-
target("watchosX64")
31-
target("watchosArm32")
32-
target("watchosArm64")
33-
target("tvosSimulatorArm64")
34-
target("tvosX64")
35-
target("tvosArm64")
36-
target("iosArm64")
37-
38-
// Tier 3
39-
target("androidNativeArm32")
40-
target("androidNativeArm64")
41-
target("androidNativeX86")
42-
target("androidNativeX64")
43-
target("mingwX64")
44-
target("watchosDeviceArm64")
45-
}
17+
applyDefaultHierarchyTemplate()
18+
19+
// According to https://kotlinlang.org/docs/native-target-support.html
20+
// Tier 1
21+
linuxX64()
22+
macosX64()
23+
macosArm64()
24+
iosSimulatorArm64()
25+
iosX64()
26+
27+
// Tier 2
28+
linuxArm64()
29+
watchosSimulatorArm64()
30+
watchosX64()
31+
watchosArm32()
32+
watchosArm64()
33+
tvosSimulatorArm64()
34+
tvosX64()
35+
tvosArm64()
36+
iosArm64()
37+
38+
// Tier 3
39+
androidNativeArm32()
40+
androidNativeArm64()
41+
androidNativeX86()
42+
androidNativeX64()
43+
mingwX64()
44+
watchosDeviceArm64()
4645

4746
jvm {
4847
compilations.all {
@@ -69,6 +68,26 @@ kotlin {
6968
}
7069
}
7170

71+
wasmJs {
72+
nodejs {
73+
testTask {
74+
useMocha {
75+
timeout = "30000"
76+
}
77+
}
78+
}
79+
}
80+
81+
wasmWasi {
82+
nodejs {
83+
testTask {
84+
useMocha {
85+
timeout = "30000"
86+
}
87+
}
88+
}
89+
}
90+
7291
sourceSets.all {
7392
kotlin.setSrcDirs(listOf("$name/src"))
7493
resources.setSrcDirs(listOf("$name/resources"))
@@ -100,6 +119,25 @@ kotlin {
100119
val jsTest by getting {
101120
}
102121

122+
val wasmMain by creating {
123+
}
124+
val wasmTest by creating {
125+
}
126+
127+
val wasmJsMain by getting {
128+
dependsOn(wasmMain)
129+
}
130+
val wasmJsTest by getting {
131+
dependsOn(wasmTest)
132+
}
133+
134+
val wasmWasiMain by getting {
135+
dependsOn(wasmMain)
136+
}
137+
val wasmWasiTest by getting {
138+
dependsOn(wasmTest)
139+
}
140+
103141
val nativeMain by getting {
104142
}
105143
val nativeTest by getting {
@@ -111,4 +149,14 @@ tasks {
111149
named("jvmTest", Test::class) {
112150
maxHeapSize = "1024m"
113151
}
152+
}
153+
154+
with(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin.apply(rootProject)) {
155+
nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2"
156+
nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
157+
}
158+
159+
// Drop this when node js version become stable
160+
tasks.withType<org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask>().configureEach {
161+
args.add("--ignore-engines")
114162
}

core/commonTest/src/contract/map/ImmutableMapTest.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,17 @@ abstract class ImmutableMapTest {
283283
}
284284

285285
@Test fun noOperation() {
286-
immutableMapOf<Int, String>().toPersistentMap().testNoOperation({ clear() }, { clear() })
286+
immutableMapOf<String, String>().toPersistentMap().testNoOperation({ clear() }, { clear() })
287287

288-
val map = immutableMapOf("x" to 1, null to "x").toPersistentMap()
288+
val instance = Any()
289+
val instance2 = Any()
290+
291+
val map = immutableMapOf("x" to instance, null to "x").toPersistentMap()
289292
with(map) {
290293
testNoOperation({ remove("y") }, { remove("y") })
291-
testNoOperation({ remove("x", 2) }, { remove("x", 2) })
292-
testNoOperation({ put("x", 1) }, { put("x", 1) }) // does not hold
293-
testNoOperation({ putAll(this) }, { putAll(this) }) // does not hold
294+
testNoOperation({ remove("x", instance2) }, { remove("x", instance2) })
295+
testNoOperation({ put("x", instance) }, { put("x", instance) })
296+
testNoOperation({ putAll(this) }, { putAll(this) })
294297
testNoOperation({ putAll(emptyMap()) }, { putAll(emptyMap()) })
295298
}
296299
}

core/commonTest/src/testUtils.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public expect fun assertTypeEquals(expected: Any?, actual: Any?)
2525
public enum class TestPlatform {
2626
JVM,
2727
JS,
28-
Native
28+
Native,
29+
Wasm,
2930
}
3031
public expect val currentPlatform: TestPlatform
3132

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright 2016-2023 JetBrains s.r.o.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package kotlinx.collections.immutable.internal
7+
8+
internal actual fun assert(condition: Boolean) {
9+
if (!condition) {
10+
throw AssertionError("Assertion failed")
11+
}
12+
}
13+
14+
internal actual var AbstractMutableList<*>.modCount: Int
15+
get() = 0
16+
set(@Suppress("UNUSED_PARAMETER") value) {}

core/wasmTest/src/testUtilsJs.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2016-2023 JetBrains s.r.o.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package tests
7+
8+
import kotlin.test.assertTrue
9+
10+
public actual fun assertTypeEquals(expected: Any?, actual: Any?) {
11+
if (expected != null && actual != null) {
12+
assertTrue(expected::class.isInstance(actual) || actual::class.isInstance(expected),
13+
"Expected: $expected, Actual: $actual")
14+
} else {
15+
assertTrue(expected == null && actual == null)
16+
}
17+
}
18+
19+
public actual val currentPlatform: TestPlatform get() = TestPlatform.Wasm
20+
21+
actual object NForAlgorithmComplexity {
22+
actual val O_N: Int = 500_000
23+
actual val O_NlogN: Int = 100_000
24+
actual val O_NN: Int = 5_000
25+
actual val O_NNlogN: Int = 1_000
26+
}

0 commit comments

Comments
 (0)