Skip to content

Commit

Permalink
Add WasmWasi support (benasher44#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
benasher44 authored Mar 16, 2024
1 parent def028c commit f00110a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
project adheres to [Semantic Versioning](https://semver.org/).

## [0.8.3] - 2024-03-16
### Changed
- Bump kotlin to 1.9.23
- Add wasmWasi support

## [0.8.2] - 2023-11-10
### Changed
- Bump kotlin to 1.9.20
Expand Down
24 changes: 21 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
import org.jetbrains.kotlin.konan.target.HostManager

plugins {
kotlin("multiplatform") version "1.9.20"
kotlin("multiplatform") version "1.9.23"
id("org.jetbrains.dokka") version "1.8.20"
id("maven-publish")
id("signing")
Expand Down Expand Up @@ -66,9 +66,12 @@ kotlin {
binaries.findTest(DEBUG)!!.linkerOpts = mutableListOf("-Wl,--subsystem,windows")
}
}
if (HostManager.hostIsLinux || HostManager.hostIsMac) {
if (HostManager.hostIsLinux) {
linuxX64()
linuxArm64()
wasmWasi {
nodejs()
}
}
}

Expand Down Expand Up @@ -150,11 +153,12 @@ kotlin {
val mingwX64Test by getting { dependsOn(mingwTest) }
}

if (HostManager.hostIsLinux || HostManager.hostIsMac) {
if (HostManager.hostIsLinux) {
val linuxX64Main by getting { dependsOn(nix64Main) }
val linuxX64Test by getting { dependsOn(nix64Test) }
val linuxArm64Main by getting { dependsOn(nix64Main) }
val linuxArm64Test by getting { dependsOn(nix64Test) }
val wasmWasiMain by getting { dependsOn(nonJvmMain) }
}
}
}
Expand All @@ -167,6 +171,20 @@ tasks.withType<KotlinNativeCompile>().configureEach {
compilerOptions.freeCompilerArgs.add("-opt-in=kotlinx.cinterop.ExperimentalForeignApi")
}

if (HostManager.hostIsLinux) {
plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().download = true
the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeVersion =
"21.0.0-v8-canary20231024d0ddc81258"
the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeDownloadBaseUrl =
"https://nodejs.org/download/v8-canary"
}

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

val ktlintConfig by configurations.creating

dependencies {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ kotlin.code.style=official
kotlin.incremental=true

GROUP=com.benasher44
VERSION=0.8.2
VERSION=0.8.3

POM_URL=https://github.com/benasher44/uuid/
POM_SCM_URL=https://github.com/benasher44/uuid/
Expand All @@ -21,4 +21,4 @@ POM_DESCRIPTION=A Kotlin multiplatform implementation of a v4 RFC4122 UUID

org.gradle.jvmargs=-Xmx4g

kotlin.stdlib.default.dependency=false
kotlin.stdlib.default.dependency=false
1 change: 1 addition & 0 deletions publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,5 @@ tasks.register('publishWindows') {
tasks.register('publishLinux') {
dependsOn 'publishLinuxX64PublicationToMavenRepository'
dependsOn 'publishLinuxArm64PublicationToMavenRepository'
dependsOn 'publishWasmWasiPublicationToMavenRepository'
}
7 changes: 7 additions & 0 deletions src/wasmWasiMain/kotlin/platform.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.benasher44.uuid

import kotlin.random.Random

internal actual fun getRandomUuidBytes(): ByteArray = Random.Default.nextBytes(UUID_BYTES)

internal actual fun <T> T.freeze(): T = this

0 comments on commit f00110a

Please sign in to comment.