diff --git a/canard/src/wasmJsMain/kotlin/org/kodein/log/timestampWasmJs.kt b/canard/src/wasmJsMain/kotlin/org/kodein/log/timestamp.wasmJs.kt similarity index 100% rename from canard/src/wasmJsMain/kotlin/org/kodein/log/timestampWasmJs.kt rename to canard/src/wasmJsMain/kotlin/org/kodein/log/timestamp.wasmJs.kt diff --git a/canard/src/wasmJsMain/kotlin/org/kodein/log/frontend/defaultWasmJs.kt b/canard/src/wasmMain/kotlin/org/kodein/log/frontend/default.wasm.kt similarity index 100% rename from canard/src/wasmJsMain/kotlin/org/kodein/log/frontend/defaultWasmJs.kt rename to canard/src/wasmMain/kotlin/org/kodein/log/frontend/default.wasm.kt diff --git a/canard/src/wasmJsMain/kotlin/org/kodein/log/frontend/printStackTraceWasmJs.kt b/canard/src/wasmMain/kotlin/org/kodein/log/frontend/printStackTrace.wasm.kt similarity index 100% rename from canard/src/wasmJsMain/kotlin/org/kodein/log/frontend/printStackTraceWasmJs.kt rename to canard/src/wasmMain/kotlin/org/kodein/log/frontend/printStackTrace.wasm.kt diff --git a/canard/src/wasmJsMain/kotlin/org/kodein/log/kclassWasmJs.kt b/canard/src/wasmMain/kotlin/org/kodein/log/kclass.wasm.kt similarity index 100% rename from canard/src/wasmJsMain/kotlin/org/kodein/log/kclassWasmJs.kt rename to canard/src/wasmMain/kotlin/org/kodein/log/kclass.wasm.kt diff --git a/canard/src/wasmWasiMain/kotlin/org/kodein/log/timestamp.wasmWasi.kt b/canard/src/wasmWasiMain/kotlin/org/kodein/log/timestamp.wasmWasi.kt new file mode 100644 index 0000000..43b3358 --- /dev/null +++ b/canard/src/wasmWasiMain/kotlin/org/kodein/log/timestamp.wasmWasi.kt @@ -0,0 +1,31 @@ +package org.kodein.log + +import kotlin.wasm.WasmImport +import kotlin.wasm.unsafe.Pointer +import kotlin.wasm.unsafe.UnsafeWasmMemoryApi +import kotlin.wasm.unsafe.withScopedMemoryAllocator + + +@WasmImport("wasi_snapshot_preview1", "clock_time_get") +private external fun wasiRawClockTimeGet(clockId: Int, precision: Long, resultPtr: Int): Int + +@OptIn(UnsafeWasmMemoryApi::class) +private fun wasiGetTime(clockId: Int): Long = withScopedMemoryAllocator { allocator -> + val rp0 = allocator.allocate(8) + val ret = wasiRawClockTimeGet( + clockId = clockId, + precision = 1, + resultPtr = rp0.address.toInt() + ) + check(ret == 0) { + "Invalid WASI return code $ret" + } + (Pointer(rp0.address.toInt().toUInt())).loadLong() +} + +public actual fun now(): Timestamp = Timestamp(wasiGetTime(0).toULong()) + +@Suppress("LocalVariableName") +public actual fun Timestamp.toLocalString(): String = + TODO("$msecSinceEpoch") + diff --git a/settings.gradle.kts b/settings.gradle.kts index 96c5809..5cee6f6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,7 +5,7 @@ buildscript { maven(url = "https://raw.githubusercontent.com/kosi-libs/kodein-internal-gradle-plugin/mvn-repo") } dependencies { - classpath("org.kodein.internal.gradle:kodein-internal-gradle-settings:8.5.1") + classpath("org.kodein.internal.gradle:kodein-internal-gradle-settings:8.5.2") } }