Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Wasm WASI target #2510

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,7 @@ apply from: rootProject.file("gradle/benchmark-parsing.gradle")
tasks.named("dokkaHtmlMultiModule") {
pluginsMapConfiguration.set(["org.jetbrains.dokka.base.DokkaBase": """{ "templatesDir": "${projectDir.toString().replace('\\', '/')}/dokka-templates" }"""])
}

tasks.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask).configureEach {
args.add("--ignore-engines")
}
3 changes: 3 additions & 0 deletions formats/json/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ kotlin {
wasmJsMain {
dependsOn(sourceSets.jsWasmMain)
}
wasmWasiMain {
dependsOn(sourceSets.jsWasmMain)
}
}
}

Expand Down
49 changes: 42 additions & 7 deletions gradle/configure-source-sets.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ tasks.withType(JavaCompile).configureEach {
options.release = 8
}

// Unfortunately there is no compatible version of okio for Wasm WASI target, so we need to skip to configure WASI for json-okio and json-tests.
// json-tests uses okio with incorporate with other formatter tests so it is hard and not worth to separate it for two projects for WASI.
// So we disable WASI target in it and we hope, that WASI version of compiler and serialization plugin are identical to the WasmJS target so WASI target is being covered.
Boolean isOkIoOrFormatTests = (project.name == 'kotlinx-serialization-json-okio' || project.name == 'kotlinx-serialization-json-tests')

kotlin {
jvm {
withJava()
Expand Down Expand Up @@ -43,7 +48,13 @@ kotlin {
}

wasmJs {
d8()
nodejs()
}

if (!isOkIoOrFormatTests) {
wasmWasi {
nodejs()
}
}

sourceSets.all {
Expand Down Expand Up @@ -96,25 +107,43 @@ kotlin {
}
}

create("wasmMain") {
dependsOn(commonMain)
}
create("wasmTest") {
dependsOn(commonTest)
}

wasmJsMain {
kotlin {
srcDir 'wasmMain/src'
}
dependsOn(wasmMain)
dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-wasm-js'
}
}

wasmJsTest {
kotlin {
srcDir 'wasmTest/src'
}
dependsOn(wasmTest)
dependencies {
api 'org.jetbrains.kotlin:kotlin-test-wasm-js'
}
}

if (!isOkIoOrFormatTests) {
wasmWasiMain {
dependsOn(wasmMain)
dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-wasm-wasi'
}
}

wasmWasiTest {
dependsOn(wasmTest)
dependencies {
api 'org.jetbrains.kotlin:kotlin-test-wasm-wasi'
}
}
}

nativeMain.dependencies {
}
}
Expand Down Expand Up @@ -162,3 +191,9 @@ kotlin {
}
}
}

rootProject.extensions.findByType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension.class).with {
// canary nodejs that supports recent Wasm GC changes
it.nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2"
it.nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
}
26 changes: 24 additions & 2 deletions integration-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ kotlin {
}
}
wasmJs {
d8()
nodejs()
}
wasmWasi {
nodejs()
}
jvm {
withJava()
Expand Down Expand Up @@ -102,12 +105,21 @@ kotlin {
api 'org.jetbrains.kotlin:kotlin-stdlib-wasm-js'
}
}

wasmJsTest {
dependencies {
api 'org.jetbrains.kotlin:kotlin-test-wasm-js'
}
}
wasmWasiMain {
dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-wasm-wasi'
}
}
wasmWasiTest {
dependencies {
api 'org.jetbrains.kotlin:kotlin-test-wasm-wasi'
}
}
}

targets.all {
Expand All @@ -129,3 +141,13 @@ dependencies {
}

task run dependsOn "check"

rootProject.extensions.findByType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension.class).with {
// canary nodejs that supports recent Wasm GC changes
it.nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2"
it.nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
}

tasks.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask).configureEach {
args.add("--ignore-engines")
}
4 changes: 2 additions & 2 deletions integration-test/src/wasmJsMain/kotlin/sample/SampleWasm.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 JetBrains s.r.o.
* Copyright 2023 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,5 +17,5 @@
package sample

actual object Platform {
actual val name: String = "Wasm"
actual val name: String = "WasmJs"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import kotlin.test.assertTrue
class SampleTestsWasm {
@Test
fun testHello() {
assertTrue("Wasm" in hello())
assertTrue("WasmJs" in hello())
}
}
21 changes: 21 additions & 0 deletions integration-test/src/wasmWasiMain/kotlin/sample/SampleWasm.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2023 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package sample

actual object Platform {
actual val name: String = "WasmWasi"
}
11 changes: 11 additions & 0 deletions integration-test/src/wasmWasiTest/kotlin/sample/SampleTestsWasm.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sample

import kotlin.test.Test
import kotlin.test.assertTrue

class SampleTestsWasm {
@Test
fun testHello() {
assertTrue("WasmWasi" in hello())
}
}