Skip to content

Commit

Permalink
Merge pull request #15 from ephemient/kt/wasmJs
Browse files Browse the repository at this point in the history
  • Loading branch information
ephemient authored Dec 2, 2024
2 parents 29bc862 + c887996 commit fbdd22c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 19 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/kt-bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
target: [ jvm, linuxX64 ]
target: [ jvm, wasmJs, linuxX64 ]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -89,6 +89,10 @@ jobs:
with:
name: jvm-benchmarks
path: benchmarks
- uses: actions/download-artifact@v4
with:
name: wasmJs-benchmarks
path: benchmarks
- uses: actions/download-artifact@v4
with:
name: linuxX64-benchmarks
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/kt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ jobs:
path: |
kt/aoc2024-exe/build/bin/*/debugExecutable/*.kexe
kt/aoc2024-exe/build/bin/*/releaseExecutable/*.kexe
- uses: actions/upload-artifact@v4
with:
name: aoc2024-wasmJs
path: kt/build/js/packages/aoc2024-aoc2024-exe-wasm-js/kotlin/*
- uses: actions/upload-artifact@v4
with:
name: aoc2024-js
Expand Down Expand Up @@ -81,6 +85,25 @@ jobs:
env:
AOC2024_DATADIR: inputs

run-wasmJs:
needs: [ get-inputs, build ]
runs-on: ubuntu-latest

steps:
- uses: actions/download-artifact@v4
with:
name: inputs
path: inputs
- uses: actions/download-artifact@v4
with:
name: aoc2024-wasmJs
- uses: actions/setup-node@v4
with:
node-version: 22.0.0
- run: node aoc2024-aoc2024-exe-wasm-js.mjs
env:
AOC2024_DATADIR: inputs

run-node:
needs: [ get-inputs, build ]
runs-on: ubuntu-latest
Expand Down
35 changes: 18 additions & 17 deletions kt/aoc2024-exe/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@ plugins {
}

kotlin {
jvm {
mainRun {
mainClass = "com.github.ephemient.aoc2024.exe.Main"
}
compilations {
create("bench") {
associateWith(getByName("main"))
@Suppress("SpreadOperator")
listOf(
jvm {
mainRun {
mainClass = "com.github.ephemient.aoc2024.exe.Main"
}
},
*arrayOf(wasmJs(), js()).onEach {
it.nodejs()
it.binaries.executable()
},
*arrayOf(linuxArm64(), linuxX64(), macosArm64(), macosX64(), mingwX64()).onEach {
it.binaries.executable {
entryPoint("com.github.ephemient.aoc2024.exe.main")
}
}
}
js {
nodejs()
binaries.executable()
}
for (target in arrayOf(linuxArm64(), linuxX64(), macosArm64(), macosX64(), mingwX64())) {
target.binaries.executable {
entryPoint("com.github.ephemient.aoc2024.exe.main")
}
target.compilations {
).onEach {
it.compilations {
create("bench") {
associateWith(getByName("main"))
}
Expand All @@ -39,6 +38,7 @@ kotlin {
withSourceSetTree(KotlinSourceSetTree("bench"))
common {
withJvm()
withWasmJs()
withNative()
}
}
Expand Down Expand Up @@ -105,6 +105,7 @@ allOpen {
benchmark {
targets {
register("jvmBench")
register("wasmJsBench")
register("linuxArm64Bench")
register("linuxX64Bench")
register("macosArm64Bench")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.ephemient.aoc2024.exe

private fun getenv(name: String): String = js("process.env[name] ?? ''")

internal actual fun getDayInput(day: Int): String {
val dataDir = getenv("AOC2024_DATADIR").ifEmpty { null } ?: "."
return readFileSync("$dataDir/day$day.txt".toJsString(), "utf8".toJsString()).toString()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@file:JsModule("fs")

package com.github.ephemient.aoc2024.exe

external fun readFileSync(path: JsAny, encoding: JsString): JsString
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.ephemient.aoc2024.exe

private fun argv(): String = js("process.argv.join(' ')")

suspend fun main() {
mainImpl(argv().split(' ').drop(2).toTypedArray())
}
4 changes: 3 additions & 1 deletion kt/aoc2024-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ kotlin {
browser()
nodejs()
}
wasmWasi { nodejs() }
wasmWasi {
nodejs()
}
js {
browser()
nodejs()
Expand Down

0 comments on commit fbdd22c

Please sign in to comment.