-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get WASI set up enough to do a directory list
- Loading branch information
1 parent
84789c4
commit da1675b
Showing
19 changed files
with
3,436 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
WASI FileSystem | ||
=============== | ||
|
||
⚠️ This is a work in progress ⚠️ | ||
|
||
This module implements Okio's FileSystem API using the [WebAssembly System Interface (WASI)][wasi]. | ||
|
||
It currently uses the WASI [preview1] APIs and is tested on NodeJS with the | ||
`--experimental-wasi-unstable-preview1` option. | ||
|
||
[wasi]: https://wasi.dev/ | ||
[preview1]: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import com.vanniktech.maven.publish.JavadocJar.Dokka | ||
import com.vanniktech.maven.publish.KotlinMultiplatform | ||
import com.vanniktech.maven.publish.MavenPublishBaseExtension | ||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
id("org.jetbrains.dokka") | ||
id("com.vanniktech.maven.publish.base") | ||
id("build-support") | ||
id("binary-compatibility-validator") | ||
} | ||
|
||
kotlin { | ||
configureOrCreateWasmPlatform() | ||
sourceSets { | ||
val wasmMain by getting { | ||
dependencies { | ||
implementation(projects.okio) | ||
} | ||
} | ||
val wasmTest by getting { | ||
dependencies { | ||
implementation(libs.kotlin.test) | ||
} | ||
} | ||
} | ||
} | ||
|
||
configure<MavenPublishBaseExtension> { | ||
configure( | ||
KotlinMultiplatform(javadocJar = Dokka("dokkaGfm")), | ||
) | ||
} | ||
|
||
/** | ||
* Inspired by runner.mjs in kowasm, this rewrites the JavaScript bootstrap script to set up WASI. | ||
* | ||
* See also: | ||
* * https://github.com/kowasm/kowasm | ||
* * https://github.com/nodejs/node/blob/main/doc/api/wasi.md | ||
* | ||
* This task overwrites the output of `compileTestKotlinWasm` and must run after that task. It | ||
* must also run before the WASM test execution tasks that read this script. | ||
* | ||
* Note that this includes which file paths are exposed to the WASI sandbox. | ||
*/ | ||
val injectWasiInit by tasks.creating { | ||
dependsOn("compileTestKotlinWasm") | ||
val moduleName = "${rootProject.name}-${project.name}-wasm-test" | ||
|
||
val entryPointMjs = File( | ||
buildDir, | ||
"compileSync/wasm/test/testDevelopmentExecutable/kotlin/$moduleName.mjs" | ||
) | ||
|
||
outputs.file(entryPointMjs) | ||
|
||
doLast { | ||
entryPointMjs.writeText( | ||
""" | ||
import {instantiate} from './$moduleName.uninstantiated.mjs'; | ||
import {WASI} from "wasi"; | ||
export const wasi = new WASI({ | ||
version: 'preview1', | ||
preopens: { | ||
'/okio': '$rootDir' | ||
} | ||
}); | ||
const {instance, exports} = await instantiate({wasi_snapshot_preview1: wasi.wasiImport}); | ||
wasi.initialize(instance); | ||
export default exports; | ||
""".trimIndent() | ||
) | ||
} | ||
} | ||
tasks.withType<KotlinJsTest>().configureEach { | ||
nodeJsArgs += "--experimental-wasi-unstable-preview1" | ||
} | ||
tasks.named("wasmTestTestDevelopmentExecutableCompileSync").configure { | ||
dependsOn(injectWasiInit) | ||
} | ||
tasks.named("wasmTestTestProductionExecutableCompileSync").configure { | ||
dependsOn(injectWasiInit) | ||
} |
Oops, something went wrong.