diff --git a/README.md b/README.md index 609b77f..9bd8672 100644 --- a/README.md +++ b/README.md @@ -31,13 +31,24 @@ property in the `gradle.properties` file to ensure that the `packageFatJar` task **Running:** -Run the `other/jsRun` gradle task like any other **Kotlin/JS** project to run in development mode. +Run the `kotlin browser/jsBrowserRun` gradle task like any other **Kotlin/JS** project to run in development mode. **Deploying:** Run the `kotlin browser/jsBrowserDistribution` gradle task to create a distribution build. This build will require a webserver in order to run. +### WASM + +**Running:** + +Run the `kotlin browser/wasmJsBrowserRun` gradle task like any other **Kotlin/Wasm** project to run in development mode. + +**Deploying:** + +Run the `kotlin browser/wasmJsBrowserDistribution` gradle task to create a distribution build. This build will require a +webserver in order to run. + ### Android **Running:** diff --git a/build.gradle.kts b/build.gradle.kts index bca0b59..423641c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,12 +1,6 @@ -buildscript { - repositories { - gradlePluginPortal() - google() - mavenCentral() - } - dependencies { - classpath(libs.bundles.plugins) - } +plugins { + alias(libs.plugins.android.application) apply false + alias(libs.plugins.kotlin.multiplatform) apply false } allprojects { diff --git a/game/build.gradle.kts b/game/build.gradle.kts index e73fc2e..2771712 100644 --- a/game/build.gradle.kts +++ b/game/build.gradle.kts @@ -1,15 +1,15 @@ import org.apache.tools.ant.taskdefs.condition.Os import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl repositories { - mavenCentral() maven(url = "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") } plugins { - kotlin("multiplatform") - id("com.android.application") + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.multiplatform) } kotlin { @@ -69,7 +69,7 @@ kotlin { } } compilations.all { - kotlinOptions.jvmTarget = "11" + kotlinOptions.jvmTarget = "17" } testRuns["test"].executionTask.configure { useJUnit() @@ -95,6 +95,23 @@ kotlin { } } + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + binaries.executable() + browser { + commonWebpackConfig(Action { + devServer = + (devServer ?: org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.DevServer()).copy( + open = mapOf( + "app" to mapOf( + "name" to "firefox" + ) + ), + ) + }) + } + } + sourceSets { val commonMain by getting { dependencies { @@ -115,11 +132,14 @@ kotlin { } } val jsTest by getting + val wasmJsMain by getting + val wasmJsTest by getting val androidMain by getting } } android { + namespace = "com.game.template" sourceSets["main"].apply { manifest.srcFile("src/androidMain/AndroidManifest.xml") assets.srcDirs("src/commonMain/resources") @@ -131,8 +151,8 @@ android { targetSdk = (findProperty("android.targetSdk") as String).toInt() } compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } } diff --git a/game/src/androidMain/AndroidManifest.xml b/game/src/androidMain/AndroidManifest.xml index c1ff7a1..a739e00 100644 --- a/game/src/androidMain/AndroidManifest.xml +++ b/game/src/androidMain/AndroidManifest.xml @@ -1,6 +1,5 @@ - + + + + + + + + + + + + + + + + LittleKt - WASM + + + +
+ ⚠️ Please make sure that your runtime environment supports the latest version of Wasm GC and Exception-Handling + proposals. + For more information, see https://kotl.in/wasm-help. +
+
+
    +
  • For Chrome and Chromium-based browsers (Edge, Brave etc.), it should just work since + version 119. +
  • +
  • For Firefox 120 it should just work.
  • +
  • For Firefox 119: +
      +
    1. Open about:config in the browser.
    2. +
    3. Enable javascript.options.wasm_gc.
    4. +
    5. Refresh this page.
    6. +
    +
  • +
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/game/src/wasmJsMain/webpack.config.d/cleanupSourcemap.js b/game/src/wasmJsMain/webpack.config.d/cleanupSourcemap.js new file mode 100644 index 0000000..b45d42b --- /dev/null +++ b/game/src/wasmJsMain/webpack.config.d/cleanupSourcemap.js @@ -0,0 +1,37 @@ +// Replace paths unavailable during compilation with `null`, so they will not be shown in devtools +; +(() => { + const fs = require("fs"); + const path = require("path"); + + const outDir = __dirname + "/kotlin/" + const projecName = path.basename(__dirname); + const mapFileLegacy = outDir + projecName + ".map" + const mapFile = outDir + projecName + ".wasm.map" + + let sourcemap + try { + sourcemap = JSON.parse(fs.readFileSync(mapFileLegacy)) + } catch (e) { + sourcemap = JSON.parse(fs.readFileSync(mapFile)) + } + const sources = sourcemap["sources"] + srcLoop: for (let i in sources) { + const srcFilePath = sources[i]; + if (srcFilePath == null) continue; + + const srcFileCandidates = [ + outDir + srcFilePath, + outDir + srcFilePath.substring("../".length), + outDir + "../" + srcFilePath, + ]; + + for (let srcFile of srcFileCandidates) { + if (fs.existsSync(srcFile)) continue srcLoop; + } + + sources[i] = null; + } + + fs.writeFileSync(mapFile, JSON.stringify(sourcemap)); +})(); \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index e713fe0..47ca4f3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,10 +11,9 @@ kotlin.js.generate.executable.default=false kotlin.mpp.androidSourceSetLayoutVersion=2 #Android -android.compileSdk=33 -android.targetSdk=33 +android.compileSdk=34 +android.targetSdk=34 android.minSdk=21 -android.disableAutomaticComponentCreation=true #JVM jvm.mainClass=com.game.template.LwjglApp diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4949f28..aa4a18f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,20 +1,16 @@ [versions] -plugin-android = "7.3.1" -plugin-kotlin = "1.9.21" - +agp = "8.2.0" +kotlin = "1.9.23" kotlinx-html = "0.9.1" -kotlinx-coroutines = "1.8.0-RC2" - -littlekt = "0.8.1" +kotlinx-coroutines = "1.8.0" +littlekt = "0.9.0" [libraries] -plugin-android = { module = "com.android.tools.build:gradle", version.ref = "plugin-android" } -plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "plugin-kotlin" } - kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } kotlinx-html-js = { module = "org.jetbrains.kotlinx:kotlinx-html-js", version.ref = "kotlinx-html" } littlekt-core = { module = "com.lehaine.littlekt:core", version.ref = "littlekt" } -[bundles] -plugins = ["plugin-android", "plugin-kotlin"] +[plugins] +android-application = { id = "com.android.application", version.ref = "agp" } +kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }