Skip to content

Commit 478abe6

Browse files
committed
chore: wasi support
1 parent 01b8b88 commit 478abe6

File tree

3 files changed

+114
-12
lines changed

3 files changed

+114
-12
lines changed

README.md

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
[![Kotlin release][kt_img]][kt_url]
88

99
Gradle project and settings [plugins](https://docs.gradle.org/current/samples/sample_convention_plugins.html) to
10-
simplify the bootstrapping of `Kotlin/Java` projects targeting JVM, Multiplatform (Native/JS/Wasm), and GraalVM
10+
simplify the bootstrapping of `Kotlin/Java` projects targeting JVM, Multiplatform (Native/JS/Wasm/Wasi), and GraalVM
1111
native-image. The plugin will take care of configuring most common build tasks, including:
1212

1313
* `Maven Central` & `GHCR` publishing for artifacts & Container image (`Jib`)
14-
* Code coverage supporting JVM, Kotlin Multiplatform projects
15-
* Project Versioning (`SemVer`) based on Git tags
14+
* Code coverage supporting `JVM`, `Kotlin Multiplatform` projects
15+
* Project Versioning (`SemVer`) based on `Git tags`
1616
* Code Formatting to enforce a consistent code style
1717
* Artifact Signing
1818
* Java/Kotlin Toolchains configuration
19-
* Target platforms (`JVM`, `JS`, `WASM`, `Native`) configuration
19+
* Target platforms (`JVM`, `JS`, `WASM`, `WASI`, `Native`) configuration
2020
* Testing & Reports
2121
* `KSP` & Annotation processors
22-
* GraalVM Native Image
22+
* `GraalVM Native` Image
2323
* Documentation (`JavaDoc`, `Dokka`)
2424
* Benchmarking (`JMH`)
2525
* API binary compatibility validation
@@ -59,7 +59,7 @@ Kotlin/Java projects, handling the boilerplate and common tasks so you can get s
5959
> For a better, faster experience, use the latest version of [IntelliJ IDEA](https://www.jetbrains.com/idea/download).
6060
> Upgrade now!
6161
62-
### Build & Testing
62+
## Build & Testing
6363

6464
```bash
6565
$ ./gradlew build
@@ -77,7 +77,7 @@ For testing, a separate [sandbox project](/sandbox) is available with the plugin
7777
$ ./gradlew -p sandbox :dependencyUpdates --no-configuration-cache
7878
```
7979

80-
### Publishing
80+
## Publishing
8181

8282
Push a new tag to trigger the release workflow and publish the plugin
8383
to [maven central](https://repo1.maven.org/maven2/dev/suresh/build/). That's it 🎉.
@@ -91,9 +91,13 @@ The next version will be based on the semantic version scope (`major`, `minor`,
9191

9292
# Print the new version
9393
# ./gradlew printSemver "-Psemver.scope=patch"
94+
95+
# For a specific version
96+
# git tag -am "v1.2.3 release" v1.2.3
97+
# git push origin --tags
9498
```
9599

96-
### Published Plugins
100+
## Published Plugins
97101

98102
| **Gradle Plugin ID** | **Version** |
99103
|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -108,7 +112,65 @@ The next version will be based on the semantic version scope (`major`, `minor`,
108112
| `dev.suresh.plugin.repos` | [![](https://img.shields.io/maven-central/v/dev.suresh.plugin.repos/dev.suresh.plugin.repos.gradle.plugin?logo=gradle&logoColor=white&color=00B4E6)][plugins_url] |
109113
| `dev.suresh.plugin.catalog` | [![](https://img.shields.io/maven-central/v/dev.suresh.plugin.catalog/dev.suresh.plugin.catalog.gradle.plugin?logo=gradle&logoColor=white&color=00B4E6)][plugins_url] |
110114

111-
### Verifying Artifacts
115+
## How to use it?
116+
117+
- Apply the following config to `settings.gradle.kts` of your project
118+
119+
```kotlin
120+
pluginManagement {
121+
resolutionStrategy {
122+
eachPlugin {
123+
if (requested.id.id.startsWith("dev.suresh.plugin")) {
124+
useVersion("<plugin version>")
125+
}
126+
}
127+
}
128+
129+
repositories {
130+
gradlePluginPortal()
131+
mavenCentral()
132+
}
133+
}
134+
135+
plugins { id("dev.suresh.plugin.repos") }
136+
```
137+
138+
- Apply the required plugins to `root` or `sub` project `build.gradle.kts`
139+
140+
```kotlin
141+
// Kotlin JVM
142+
plugins {
143+
id("dev.suresh.plugin.root")
144+
id("dev.suresh.plugin.kotlin.jvm")
145+
id("dev.suresh.plugin.publishing")
146+
// id("dev.suresh.plugin.graalvm")
147+
application
148+
}
149+
150+
// Kotlin Multiplatform
151+
plugins {
152+
id("dev.suresh.plugin.root")
153+
id("dev.suresh.plugin.kotlin.mpp")
154+
id("dev.suresh.plugin.publishing")
155+
application
156+
}
157+
158+
kotlin {
159+
jvmTarget(project)
160+
jsTarget(project)
161+
wasmJsTarget(project)
162+
wasmWasiTarget(project)
163+
nativeTargets(project) {}
164+
}
165+
```
166+
167+
- Use the version catalog by copying [gradle/libs.versions.toml](gradle/libs.versions.toml) and change the
168+
project-related metadata like `group`, `app-mainclass` etc.
169+
170+
> [!IMPORTANT]
171+
> **Don't change** the existing version names in the catalog as it's being referenced in the plugins.
172+
173+
## Verifying Artifacts
112174

113175
The published artifacts are signed using this [key][signing_key]. The best way to verify artifacts
114176
is [automatically with Gradle][gradle_verification].
@@ -146,7 +208,7 @@ is [automatically with Gradle][gradle_verification].
146208

147209
</details>
148210

149-
### References
211+
## References
150212

151213
- [Kotlin DSL Plugin](https://docs.gradle.org/current/userguide/kotlin_dsl.html#sec:kotlin-dsl_plugin)
152214
- [Pre-compiled Script Plugins](https://docs.gradle.org/current/userguide/implementing_gradle_plugins_precompiled.html#sec:applying_external_plugins)

gradle/libs.versions.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ sslcontext-kickstart = "9.0.0"
6868
ksp-auto-service = "1.2.0"
6969
gradle-kotlin-dsl = "4.3.1"
7070
zip-prefixer = "0.3.1"
71-
ajalt-mordant = "3.0.1"
71+
ajalt-mordant = "3.0.2"
7272
ajalt-clikt = "5.0.3"
7373
ajalt-colormath = "3.6.1"
7474
classgraph = "4.8.179"
@@ -86,7 +86,7 @@ koin = "4.1.0-Beta5"
8686
koin-annotations = "2.0.0-RC1"
8787
kotest = "6.0.0.M2"
8888
mockk = "1.13.16"
89-
mokkery = "2.6.1"
89+
mokkery = "2.7.0"
9090
wiremock = "3.12.0"
9191
wiremock-kotlin = "2.1.1"
9292
okhttp = "5.0.0-alpha.14"
@@ -177,6 +177,7 @@ mcp4k = "0.3.4"
177177
dflib = "2.0.0-M2"
178178
ldaptive = "2.4.0"
179179
chicory = "1.0.0"
180+
weh-bindings = "0.2"
180181
log4k = "0.30.0"
181182
rwmutex = "1.0.0"
182183
bluesky-ozone = "0.3.1"
@@ -656,9 +657,16 @@ rwmutex = { module = "com.mayakapps.rwmutex:rwmutex
656657

657658
# Wasm
658659
chicory = { module = "com.dylibso.chicory:runtime" , version.ref = "chicory" }
660+
chicory-bom = { module = "com.dylibso.chicory:bom" , version.ref = "chicory" }
659661
chicory-aot = { module = "com.dylibso.chicory:aot-experimental" , version.ref = "chicory" }
660662
chicory-hostmodule-annproc = { module = "com.dylibso.chicory:host-module-annotations-experimental" , version.ref = "chicory" }
663+
chicory-wasi = { module = "com.dylibso.chicory:wasi" , version.ref = "chicory" }
664+
chicory-simd = { module = "com.dylibso.chicory:simd-experimental" , version.ref = "chicory" }
661665
chasm = { module = "io.github.charlietap.chasm:chasm" , version.ref = "chasm" }
666+
weh-chasm-wasip1 = { module = "at.released.weh:bindings-chasm-wasip1" , version.ref = "weh-bindings" }
667+
weh-chasm-emscripten = { module = "at.released.weh:bindings-chasm-emscripten" , version.ref = "weh-bindings" }
668+
weh-chicory-wasip1 = { module = "at.released.weh:bindings-chicory-wasip1" , version.ref = "weh-bindings" }
669+
weh-chicory-emscripten = { module = "at.released.weh:bindings-chicory-emscripten" , version.ref = "weh-bindings" }
662670

663671
# AI/ML
664672
langchain4j = { module = "dev.langchain4j:langchain4j" , version.ref = "langchain4j" }

plugins/project/src/main/kotlin/common/Multiplatform.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.gradle.kotlin.dsl.*
77
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
88
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
99
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
10+
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode
1011
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
1112

1213
fun KotlinMultiplatformExtension.commonTarget(project: Project) =
@@ -256,6 +257,37 @@ fun KotlinMultiplatformExtension.wasmJsTarget(project: Project) =
256257
}
257258
}
258259

260+
fun KotlinMultiplatformExtension.wasmWasiTarget(project: Project) =
261+
with(project) {
262+
wasmWasi {
263+
nodejs()
264+
if (isSharedProject.not()) {
265+
binaries
266+
.executable()
267+
.filter { it.mode == KotlinJsBinaryMode.PRODUCTION }
268+
.forEach { binary ->
269+
val wasmFilename = binary.mainFileName.map { it.replaceAfterLast(".", "wasm") }
270+
val wasmFile =
271+
binary.linkTask.flatMap { it.destinationDirectory.file(wasmFilename) }
272+
// Add generated WASM binary as maven publication
273+
mavenPublication { artifact(wasmFile) { classifier = targetName } }
274+
}
275+
}
276+
277+
compilations.all {
278+
compileTaskProvider.configure {
279+
compilerOptions.freeCompilerArgs.addAll(
280+
listOf("-Xwasm-use-traps-instead-of-exceptions"))
281+
}
282+
}
283+
}
284+
285+
sourceSets {
286+
wasmWasiMain { dependencies {} }
287+
wasmWasiTest { kotlin {} }
288+
}
289+
}
290+
259291
fun KotlinMultiplatformExtension.hostNativeTarget(configure: KotlinNativeTarget.() -> Unit = {}) =
260292
when {
261293
Platform.isMac -> {

0 commit comments

Comments
 (0)