Skip to content

Commit

Permalink
Implement WASM Support (#130)
Browse files Browse the repository at this point in the history
* Update build.gradle.kts for wasm targets

* Create runCatching.kt for wasm

* Rename runCatching.kt to RunCatching.kt

* Upgrade Kotlin to 1.9.0

* Create webpack.config.js

* Rename result/webpack.config.js to resultwebpack.config.js

* Rename resultwebpack.config.js to webpack.config.js

* Delete webpack.config.js

* Upgrade Kotlin to 1.9.20 with  applyDefaultHierarchyTemplate() and added iosX64 target.

* Update README.md

* Update README.md

* Create webpack.config.js

* Rename result/webpack.config.js to webpack.config.js

* Rename webpack.config.js to webpack.config.d/fs.js

* Update PR.yml

* Delete webpack.config.d/fs.js

* Update publication.gradle.kts

* Delete result/src/jsTest directory

* Update gradle.properties

* [Release] Update Kotlin version

* Upgrade Kotlin to 1.9.21 with wasm

* Update lint.yml

* trying to fix a lot of warnings by super linter

* trying to fix a lot of warnings by super linter round 2

* one more try

* oops, no slim in v5

* I believe that I got this time!

* Update lint.yml

* Update lint.yml

* Update lint.yml

* Update lint.yml

* Update lint.yml

* Update lint.yml

* Update Main.yml

* Update PR.yml

* Update Release.yml

* [Release] Update Kotlin version

* [Release] Update Kotlin version

* Update build.gradle.kts

* Update build.gradle.kts for wasm targets

* Create runCatching.kt for wasm

* Rename runCatching.kt to RunCatching.kt

* Upgrade Kotlin to 1.9.0

* Create webpack.config.js

* Rename result/webpack.config.js to resultwebpack.config.js

* Rename resultwebpack.config.js to webpack.config.js

* Delete webpack.config.js

* Upgrade Kotlin to 1.9.20 with  applyDefaultHierarchyTemplate() and added iosX64 target.

* Create webpack.config.js

* Rename result/webpack.config.js to webpack.config.js

* Rename webpack.config.js to webpack.config.d/fs.js

* Delete webpack.config.d/fs.js

* [Release] Update Kotlin version

* Upgrade Kotlin to 1.9.21 with wasm

* Update lint.yml

* trying to fix a lot of warnings by super linter

* trying to fix a lot of warnings by super linter round 2

* one more try

* oops, no slim in v5

* I believe that I got this time!

* Update lint.yml

* Update lint.yml

* Update lint.yml

* Update lint.yml

* Update lint.yml

* Update lint.yml

* Update Main.yml

* Update PR.yml

* Update Release.yml

* [Release] Update Kotlin version

* [Release] Update Kotlin version

* i think merge should be fine!

---------

Co-authored-by: Kittinun Vantasin <[email protected]>
  • Loading branch information
iNoles and kittinunf authored Mar 1, 2024
1 parent 231d835 commit 2f437ec
Show file tree
Hide file tree
Showing 23 changed files with 229 additions and 288 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
# These are supported funding model platforms

github: [kittinunf]
11 changes: 6 additions & 5 deletions .github/workflows/Main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
name: Run Gradle on Main
on:
push:
branches:
- master
- main

permissions: read-all
jobs:
publish:
name: Build and publish - SNAPSHOT
Expand All @@ -19,10 +20,10 @@ jobs:
- name: Publish to MavenCentral
uses: gradle/gradle-build-action@v2
env:
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
with:
arguments: publishAllPublicationsToSonatypeRepository --max-workers 1

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/PR.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: Run Gradle on PRs
on: pull_request

permissions: read-all
jobs:
gradle:
runs-on: macos-latest
Expand All @@ -16,7 +17,7 @@ jobs:
- name: Setup and execute Gradle 'build' task
uses: gradle/gradle-build-action@v2
with:
arguments: build -x jsBrowserTest
arguments: build -x wasmJsNodeTest

- name: Upload allTests results
uses: actions/[email protected]
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
name: Release

on:
release:
types: [ released ]

types: [released]
permissions: read-all
jobs:
publish:
name: Build and publish - Release
Expand Down
63 changes: 20 additions & 43 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,32 @@
---
#################################
#################################
## Super Linter GitHub Actions ##
#################################
#################################
name: Lint Code Base
name: Lint

#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#

#############################
# Start the job on all push #
#############################
on:
push:
branches-ignore: [master, main]
# Remove the line above to run when pushing to master
#pull_request:
#branches: [master, main]

###############
# Set the Job #
###############
on: # yamllint disable-line rule:truthy
push: null
pull_request: null
permissions: read-all
jobs:
build:
# Name the Job
name: Lint Code Base
# Set the agent to run on
name: Lint
runs-on: ubuntu-latest

##################
# Load all steps #
##################
permissions:
contents: read
packages: read
# To report GitHub Actions status checks
statuses: write

steps:
##########################
# Checkout the code base #
##########################
- name: Checkout Code
uses: actions/checkout@v3
- name: Checkout code
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
# super-linter needs the full git history to get the
# list of files that changed across commits
fetch-depth: 0

################################
# Run Linter against code base #
################################
- name: Lint Code Base
uses: docker://ghcr.io/github/super-linter:slim-v4
- name: Super-linter
uses: super-linter/[email protected]
env:
VALIDATE_ALL_CODEBASE: false
DEFAULT_BRANCH: master
VALIDATE_SHELL_SHFMT: false
# To report GitHub Actions status checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MIT License
<h1>MIT License</h1>

Copyright (c) 2017 Kittinun Vantasin

Expand Down
14 changes: 0 additions & 14 deletions gradle/libs.versions.toml

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ repositories {
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
15 changes: 8 additions & 7 deletions plugins/src/main/kotlin/publication.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ publishing {
repositories {
maven {
name = "sonatype"
url = uri(
if (isReleaseBuild) {
"https://oss.sonatype.org/service/local/staging/deploy/maven2"
} else {
"https://oss.sonatype.org/content/repositories/snapshots"
}
)
url =
uri(
if (isReleaseBuild) {
"https://oss.sonatype.org/service/local/staging/deploy/maven2"
} else {
"https://oss.sonatype.org/content/repositories/snapshots"
},
)

credentials {
username = getExtraString("sonatype.username")
Expand Down
84 changes: 26 additions & 58 deletions result/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import java.io.IOException

plugins {
kotlin("multiplatform")
kotlin("multiplatform") version "1.9.21"

java
jacoco
Expand All @@ -24,52 +25,26 @@ kotlin {
jvm()
iosX64()
iosArm64()
js(IR) {
browser()

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
nodejs()
binaries.executable()
}

iosSimulatorArm64()
macosArm64()
macosX64()

// Apply the default hierarchy again. It'll create, for example, the iosMain source set:
applyDefaultHierarchyTemplate()

targets.configureEach {
compilations.configureEach {
compilerOptions.configure {
freeCompilerArgs.add("-Xexpect-actual-classes")
}
}
}

sourceSets {
val commonMain by getting

val commonTest by getting {
dependencies {
implementation(libs.bundles.kotlin.test)
}
}

val jvmMain by getting

val jvmTest by getting {
dependencies {
implementation(libs.kotlin.test.junit)
}
}

val jsTest by getting {
dependencies {
implementation(libs.kotlin.test.js)
}
commonTest.dependencies {
implementation(kotlin("test"))
}
}
}

jacoco {
toolVersion = libs.versions.jacoco.get()
toolVersion = "0.8.11"
}

tasks {
Expand All @@ -94,28 +69,21 @@ tasks {
csv.required.set(false)
}
}

val copyTestResourceJs by registering(Copy::class) {
from("$projectDir/src/commonTest/resources")
into("${rootProject.buildDir}/js/packages/${rootProject.name}-${project.name}-test/src/commonTest/resources")
}

val jsTest by getting {
dependsOn(copyTestResourceJs)
}
}

fun String.runCommand(workingDir: File): String? = try {
val parts = split("\\s".toRegex())
val proc = ProcessBuilder(*parts.toTypedArray())
.directory(workingDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()

proc.waitFor(30, TimeUnit.SECONDS)
proc.inputStream.bufferedReader().readText()
} catch (e: IOException) {
e.printStackTrace()
null
}
fun String.runCommand(workingDir: File): String? =
try {
val parts = split("\\s".toRegex())
val proc =
ProcessBuilder(*parts.toTypedArray())
.directory(workingDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()

proc.waitFor(30, TimeUnit.SECONDS)
proc.inputStream.bufferedReader().readText()
} catch (e: IOException) {
e.printStackTrace()
null
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ inline fun <V> runCatching(block: () -> V?): Result<V?, Throwable> {
})
}

expect inline fun <R> doTry(work: () -> R, errorHandler: (Throwable) -> R): R
inline fun <R> doTry(
work: () -> R,
errorHandler: (Throwable) -> R,
): R {
return try {
work()
} catch (t: Throwable) {
errorHandler(t)
}
}
Loading

0 comments on commit 2f437ec

Please sign in to comment.