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 WasmWasi support #154

Merged
merged 4 commits into from
Mar 16, 2024
Merged

Add WasmWasi support #154

merged 4 commits into from
Mar 16, 2024

Conversation

benasher44
Copy link
Owner

Fixes or Changes Proposed

Fixes #153

PR Checklist

  • I have added a CHANGELOG.md entry for any noteable changes or fixes.
  • I have added test coverage for any new behavior or bug fixes.

@benasher44
Copy link
Owner Author

So I can't get past this error in the wasi test run by nodejs:

WebAssembly.Module(): supertype count of 1924 exceeds internal limit of 1 @+366

Any ideas?

@sgammon
Copy link

sgammon commented Mar 12, 2024

@benasher44 Have you tried out Node's canary versions? WASM GC is still a bit unstable. This works for me:

In build.gradle.kts:

import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin

// ...

rootProject.plugins.withType(NodeJsRootPlugin::class.java) {
  rootProject.the<NodeJsRootExtension>().download = true
  rootProject.the<NodeJsRootExtension>().nodeVersion = nodeVersion
  if (nodeVersion.contains("canary")) {
    rootProject.the<NodeJsRootExtension>().nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
  }
}

tasks.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask::class.java).configureEach {
  args.add("--ignore-engines")
}

In gradle.properties:

nodeVersion=21.0.0-v8-canary20231024d0ddc81258

This is what they do on KotlinX Serialization, for instance. The --ignore-engines flag is necessary because Yarn is a bit strict about engine matching:

> Task :kotlinNpmInstall
warning You are using Node "21.0.0-v8-canary20231024d0ddc81258" which is not supported and may encounter bugs or unexpected behavior. Yarn supports the following semver range: "^4.8.0 || ^5.7.0 || ^6.2.2 || >=8.0.0"

Applying these changes locally fixes the WASI testsuite. Based on the changes in this PR, here is a patch:

diff --git a/build.gradle.kts b/build.gradle.kts
index 9c60a63..7a38dc4 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,3 +1,5 @@
+import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
+import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
 import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompileTool
 import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
 import org.jetbrains.kotlin.konan.target.HostManager
@@ -9,6 +11,8 @@ plugins {
     id("signing")
 }
 
+val nodeVersion = properties["nodeVersion"] as String
+
 repositories {
     mavenCentral()
 }
@@ -171,8 +175,16 @@ tasks.withType<KotlinNativeCompile>().configureEach {
     compilerOptions.freeCompilerArgs.add("-opt-in=kotlinx.cinterop.ExperimentalForeignApi")
 }
 
-plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
-    the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeVersion = "20.11.1"
+rootProject.plugins.withType(NodeJsRootPlugin::class.java) {
+  rootProject.the<NodeJsRootExtension>().download = true
+  rootProject.the<NodeJsRootExtension>().nodeVersion = nodeVersion
+  if (nodeVersion.contains("canary")) {
+    rootProject.the<NodeJsRootExtension>().nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
+  }
+}
+
+tasks.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask::class.java).configureEach {
+  args.add("--ignore-engines")
 }
 
 val ktlintConfig by configurations.creating
diff --git a/gradle.properties b/gradle.properties
index b63d4fd..c0c57ba 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,3 +1,5 @@
+nodeVersion=21.0.0-v8-canary20231024d0ddc81258
+
 org.gradle.caching=true
 org.gradle.parallel=true

./gradlew allTests runs fine and I see both wasmJsD8Test and wasmWasiNodeTest in the output.

Expand for WASI test output
> Task :wasmWasiNodeTest
##teamcity[testSuiteStarted name='com.benasher44.uuid' flowId='wasmTcAdapter1801547762']
##teamcity[testSuiteStarted name='UuidTest' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='generates_a_UUID' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='generates_a_UUID' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='deprecated_parses_a_UUID_from_a_string' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='deprecated_parses_a_UUID_from_a_string' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='parses_a_UUID_from_a_string' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='parses_a_UUID_from_a_string' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='throws_when_passed_invalid_number_of_bytes' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='throws_when_passed_invalid_number_of_bytes' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='parsing_throws_when_passed_invalid_length_of_string' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='parsing_throws_when_passed_invalid_length_of_string' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='parsing_throws_when_passed_invalid_format_of_string' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='parsing_throws_when_passed_invalid_format_of_string' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='parsing_throws_when_passed_invalid_characters_in_string' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='parsing_throws_when_passed_invalid_characters_in_string' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='deprecated_parse_provides_higher_and_lower_bits' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='deprecated_parse_provides_higher_and_lower_bits' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='provides_higher_and_lower_bits' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='provides_higher_and_lower_bits' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='uuid4_generation' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='uuid4_generation' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='uuid_from_msb_and_lsb' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='uuid_from_msb_and_lsb' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='parse_variants_from_deprecated_parse' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='parse_variants_from_deprecated_parse' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='variants' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='variants' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='versions_from_deprecated_parse' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='versions_from_deprecated_parse' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='versions' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='versions' flowId='wasmTcAdapter1801547762']
##teamcity[testStarted name='test_comparison' flowId='wasmTcAdapter1801547762']
##teamcity[testFinished name='test_comparison' flowId='wasmTcAdapter1801547762']
##teamcity[testSuiteFinished name='UuidTest' flowId='wasmTcAdapter1801547762']
##teamcity[testSuiteFinished name='com.benasher44.uuid' flowId='wasmTcAdapter1801547762']
(node:73074) ExperimentalWarning: WASI is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:73076) ExperimentalWarning: WASI is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

Patch file for download:
gdiff.patch

@benasher44
Copy link
Owner Author

Neat! Will fix this week. Thanks!

@benasher44 benasher44 force-pushed the basher/wasmwasi branch 3 times, most recently from 2be3feb to 504e754 Compare March 16, 2024 23:13
@benasher44 benasher44 merged commit f00110a into master Mar 16, 2024
3 checks passed
@benasher44 benasher44 deleted the basher/wasmwasi branch March 16, 2024 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support wasmWasi target
2 participants