From ee2b189c09afbac37dda8d6797c3e3c4d4d8090b Mon Sep 17 00:00:00 2001 From: Suresh G Date: Tue, 14 May 2024 02:53:04 -0700 Subject: [PATCH] chore: kotlin multiplatform build config changes --- .github/workflows/build.yml | 12 ++--- backend/native/build.gradle.kts | 19 ------- gradle/build-logic/build.gradle.kts | 49 ++++++++----------- .../main/kotlin/common/MultiPlatformExtns.kt | 38 +++----------- .../src/main/kotlin/common/ProjectExtns.kt | 36 ++++++++------ .../main/kotlin/plugins/kotlin.jvm.gradle.kts | 18 +++---- .../main/kotlin/plugins/kotlin.mpp.gradle.kts | 4 +- gradle/kotlin-js-store/package-lock.json | 29 +++++++---- 8 files changed, 81 insertions(+), 124 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b15ab99c26d..23d1f75e724 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -113,12 +113,12 @@ jobs: env: GITHUB_USER: ${{ github.repository_owner }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - JOB_CONTEXT: ${{ toJSON(job) }} - STEPS_CONTEXT: ${{ toJSON(steps) }} - RUNNER_CONTEXT: ${{ toJSON(runner) }} - GITHUB_CONTEXT: ${{ toJSON(github) }} - STRATEGY_CONTEXT: ${{ toJSON(strategy) }} - MATRIX_CONTEXT: ${{ toJSON(matrix) }} + # JOB_CONTEXT: ${{ toJSON(job) }} + # STEPS_CONTEXT: ${{ toJSON(steps) }} + # RUNNER_CONTEXT: ${{ toJSON(runner) }} + # GITHUB_CONTEXT: ${{ toJSON(github) }} + # STRATEGY_CONTEXT: ${{ toJSON(strategy) }} + # MATRIX_CONTEXT: ${{ toJSON(matrix) }} - name: 📤 Uploading ${{ matrix.os }} build artifacts if: steps.gradle-build.outcome == 'success' && runner.os == 'Linux' diff --git a/backend/native/build.gradle.kts b/backend/native/build.gradle.kts index 2d401b8a691..aa5d81ad887 100644 --- a/backend/native/build.gradle.kts +++ b/backend/native/build.gradle.kts @@ -23,16 +23,8 @@ description = "Ktor native application" kotlin { targets.withType().configureEach { binaries { - - // Creates Release executable executable(setOf(RELEASE)) { entryPoint = "main" - - // Alpine(apk add gcompat) - https://youtrack.jetbrains.com/issue/KT-38876 - // linkerOpts("--as-needed", "--defsym=isnan=isnan") - // freeCompilerArgs += listOf("-Xoverride-konan-properties=linkerGccFlags=-lgcc -lgcc_eh - // -lc") - if (buildType == NativeBuildType.RELEASE) { mavenPublication { artifact(outputFile) { @@ -45,17 +37,6 @@ kotlin { // Creates test executable test(emptySet()) } - - compilations.configureEach { - compileTaskProvider.configure { - compilerOptions { - freeCompilerArgs.appendAll( - "-Xverbose-phases=Linker" - // "-Xruntime-logs=gc=info" - ) - } - } - } } sourceSets { diff --git a/gradle/build-logic/build.gradle.kts b/gradle/build-logic/build.gradle.kts index b6765cd8d0d..7b3f82e9a86 100644 --- a/gradle/build-logic/build.gradle.kts +++ b/gradle/build-logic/build.gradle.kts @@ -2,7 +2,6 @@ import org.gradle.kotlin.dsl.support.expectedKotlinDslPluginsVersion import org.jetbrains.kotlin.gradle.dsl.* -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { idea @@ -14,10 +13,7 @@ plugins { // alias(libs.plugins.kotlin.dsl) } -/** - * Java version used in Java toolchains and Kotlin compile JVM target for Gradle precompiled script - * plugins. - */ +// Java version used for Kotlin Gradle precompiled script plugins. val dslJavaVersion = libs.versions.kotlin.dsl.jvmtarget idea { @@ -27,18 +23,30 @@ idea { } } +kotlin { + compilerOptions { + jvmTarget = dslJavaVersion.map(JvmTarget::fromTarget) + freeCompilerArgs.appendAll("-Xcontext-receivers", "-Xjdk-release=${dslJavaVersion.get()}") + optIn = + listOf( + "kotlin.ExperimentalStdlibApi", + "kotlin.time.ExperimentalTime", + "kotlin.io.encoding.ExperimentalEncodingApi", + "kotlinx.validation.ExperimentalBCVApi", + "kotlinx.coroutines.ExperimentalCoroutinesApi", + "kotlinx.serialization.ExperimentalSerializationApi", + "org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi", + "org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl", + "org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalDistributionDsl", + "org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalDceDsl") + } +} + tasks { // Restrict the java release version used in Gradle kotlin DSL to avoid // accidentally using higher version JDK API in build scripts. withType().configureEach { options.release = dslJavaVersion.map { it.toInt() } } - withType().configureEach { - compilerOptions { - jvmTarget = dslJavaVersion.map(JvmTarget::fromTarget) - freeCompilerArgs.appendAll("-Xcontext-receivers", "-Xjdk-release=${dslJavaVersion.get()}") - } - } - validatePlugins { failOnWarning = true enableStricterValidation = true @@ -55,23 +63,6 @@ tasks { } } -kotlin { - sourceSets.all { - languageSettings.apply { - optIn("kotlin.ExperimentalStdlibApi") - optIn("kotlin.time.ExperimentalTime") - optIn("kotlin.io.encoding.ExperimentalEncodingApi") - optIn("kotlinx.validation.ExperimentalBCVApi") - optIn("kotlinx.coroutines.ExperimentalCoroutinesApi") - optIn("kotlinx.serialization.ExperimentalSerializationApi") - optIn("org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi") - optIn("org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl") - optIn("org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalDistributionDsl") - optIn("org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalDceDsl") - } - } -} - gradlePlugin { plugins { diff --git a/gradle/build-logic/src/main/kotlin/common/MultiPlatformExtns.kt b/gradle/build-logic/src/main/kotlin/common/MultiPlatformExtns.kt index a8e443980e3..75cbb3b7921 100644 --- a/gradle/build-logic/src/main/kotlin/common/MultiPlatformExtns.kt +++ b/gradle/build-logic/src/main/kotlin/common/MultiPlatformExtns.kt @@ -10,22 +10,17 @@ import org.gradle.kotlin.dsl.* import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig context(Project) fun KotlinMultiplatformExtension.commonTarget() { - jvmToolchain { configureJvmToolchain() } - - withSourcesJar(publish = true) - compilerOptions { configureKotlinCommon() } + withSourcesJar(publish = true) // targets.configureEach {} sourceSets { all { - languageSettings { configureKotlinLang() } // Apply multiplatform library bom to all source sets dependencies { api(project.dependencies.platform(libs.kotlin.bom)) @@ -93,11 +88,8 @@ context(Project) fun KotlinMultiplatformExtension.jvmTarget() { jvm { withJava() - // withSourcesJar(publish = false) - compilations.all { - compileJavaTaskProvider?.configure { configureJavac() } - compileTaskProvider.configure { compilerOptions { configureKotlinJvm() } } - } + compilations.configureEach { compileJavaTaskProvider?.configure { configureJavac() } } + compilerOptions { configureKotlinJvm() } // ./gradlew jvmRun mainRun { mainClass = libs.versions.app.mainclass.get() } @@ -154,7 +146,6 @@ fun KotlinMultiplatformExtension.jsTarget() { } runTask { sourceMaps = false } - testTask { enabled = true testLogging { configureLogEvents() } @@ -163,10 +154,7 @@ fun KotlinMultiplatformExtension.jsTarget() { // distribution { outputDirectory = file("$projectDir/docs") } } generateTypeScriptDefinitions() - - compilations.configureEach { - compileTaskProvider.configure { compilerOptions { configureKotlinJs() } } - } + compilerOptions { configureKotlinJs() } testRuns.configureEach { executionTask.configure { configureTestReport() } } } @@ -221,20 +209,12 @@ fun KotlinMultiplatformExtension.wasmJsTarget() { } // Generate .d.ts files generateTypeScriptDefinitions() - - compilations.configureEach { - compileTaskProvider.configure { compilerOptions { configureKotlinJs() } } - } + compilerOptions { configureKotlinJs() } testRuns.configureEach { executionTask.configure { configureTestReport() } } } sourceSets { - wasmJsMain { - dependencies { - // Webcrypto - api(libs.kotlin.cryptography.webcrypto) - } - } + wasmJsMain { dependencies { api(libs.kotlin.cryptography.webcrypto) } } wasmJsTest { kotlin {} } } } @@ -253,15 +233,13 @@ fun KotlinMultiplatformExtension.hostNativeTarget(configure: KotlinNativeTarget. } context(Project) -fun KotlinMultiplatformExtension.allNativeTargets( - configure: KotlinNativeTargetWithHostTests.() -> Unit = {} -) { +fun KotlinMultiplatformExtension.allNativeTargets(configure: KotlinNativeTarget.() -> Unit = {}) { val nativeBuild: String? by project if (nativeBuild.toBoolean()) { macosX64 { configure() } macosArm64 { configure() } linuxX64 { configure() } - linuxArm64 {} + linuxArm64 { configure() } mingwX64 { configure() } } } diff --git a/gradle/build-logic/src/main/kotlin/common/ProjectExtns.kt b/gradle/build-logic/src/main/kotlin/common/ProjectExtns.kt index fcbc0e697b7..a577675b8df 100644 --- a/gradle/build-logic/src/main/kotlin/common/ProjectExtns.kt +++ b/gradle/build-logic/src/main/kotlin/common/ProjectExtns.kt @@ -410,6 +410,21 @@ fun KotlinCommonCompilerOptions.configureKotlinCommon() { // "-P", // "plugin:...=..." ) + optIn = + listOf( + "kotlin.ExperimentalStdlibApi", + "kotlin.contracts.ExperimentalContracts", + "kotlin.ExperimentalUnsignedTypes", + "kotlin.io.encoding.ExperimentalEncodingApi", + "kotlin.time.ExperimentalTime", + "kotlinx.coroutines.ExperimentalCoroutinesApi", + "kotlinx.serialization.ExperimentalSerializationApi", + "kotlin.ExperimentalMultiplatform", + "kotlin.js.ExperimentalJsExport", + "kotlin.experimental.ExperimentalNativeApi", + "kotlinx.cinterop.ExperimentalForeignApi", + // "org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi", + ) } context(Project) @@ -462,22 +477,11 @@ fun KotlinJvmCompilerOptions.configureKotlinJvm() { } context(Project) -fun LanguageSettingsBuilder.configureKotlinLang() { - progressiveMode = true - languageVersion = kotlinLangVersion.get().version - // enableLanguageFeature("ContextReceivers") - optIn("kotlin.ExperimentalStdlibApi") - optIn("kotlin.contracts.ExperimentalContracts") - optIn("kotlin.ExperimentalUnsignedTypes") - optIn("kotlin.io.encoding.ExperimentalEncodingApi") - optIn("kotlin.time.ExperimentalTime") - optIn("kotlinx.coroutines.ExperimentalCoroutinesApi") - optIn("kotlinx.serialization.ExperimentalSerializationApi") - optIn("kotlin.ExperimentalMultiplatform") - optIn("kotlin.js.ExperimentalJsExport") - optIn("kotlin.experimental.ExperimentalNativeApi") - optIn("kotlinx.cinterop.ExperimentalForeignApi") - // optIn("org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi") +fun KotlinNativeCompilerOptions.configureKotlinNative() { + freeCompilerArgs.appendAll( + "-Xverbose-phases=Linker" + // "-Xruntime-logs=gc=info" + ) } context(Project) diff --git a/gradle/build-logic/src/main/kotlin/plugins/kotlin.jvm.gradle.kts b/gradle/build-logic/src/main/kotlin/plugins/kotlin.jvm.gradle.kts index 78ba5e4c5b5..74c816cfdc9 100644 --- a/gradle/build-logic/src/main/kotlin/plugins/kotlin.jvm.gradle.kts +++ b/gradle/build-logic/src/main/kotlin/plugins/kotlin.jvm.gradle.kts @@ -6,7 +6,6 @@ import java.util.jar.Attributes import kotlinx.kover.gradle.plugin.dsl.CoverageUnit import org.gradle.internal.os.OperatingSystem import org.gradle.kotlin.dsl.* -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import tasks.ReallyExecJar plugins { @@ -31,11 +30,12 @@ java { } kotlin { - sourceSets.all { - languageSettings { configureKotlinLang() } - // kotlin.setSrcDirs(listOf("src/kotlin")) - } jvmToolchain { configureJvmToolchain() } + compilerOptions { + configureKotlinCommon() + configureKotlinJvm() + } + // sourceSets.all { kotlin.setSrcDirs(listOf("src/kotlin")) } } @Suppress("UnstableApiUsage", "UNUSED_VARIABLE") @@ -94,15 +94,9 @@ kover { val javaAgent by configurations.creating tasks { - // Configure "compileJava" and "compileTestJava" tasks. withType().configureEach { configureJavac() } - - withType().configureEach { - compilerOptions { configureKotlinJvm() } - usePreciseJavaTracking = true - // finalizedBy("spotlessApply") - } + // withType().configureEach { finalizedBy("spotlessApply") } // Configure jvm args for JavaExec tasks except `run` withType().matching { it.name != "run" }.configureEach { jvmArgs(jvmArguments()) } diff --git a/gradle/build-logic/src/main/kotlin/plugins/kotlin.mpp.gradle.kts b/gradle/build-logic/src/main/kotlin/plugins/kotlin.mpp.gradle.kts index 597b4552cbe..de3dcfe028c 100644 --- a/gradle/build-logic/src/main/kotlin/plugins/kotlin.mpp.gradle.kts +++ b/gradle/build-logic/src/main/kotlin/plugins/kotlin.mpp.gradle.kts @@ -39,14 +39,14 @@ kotlin { sharedProjectName -> { jvmTarget() jsTarget() - allNativeTargets() + allNativeTargets { compilerOptions { configureKotlinNative() } } // wasmJsTarget() } "js", "chrome", "web" -> jsTarget() "wasm" -> wasmJsTarget() - "native" -> allNativeTargets() + "native" -> allNativeTargets { compilerOptions { configureKotlinNative() } } else -> jvmTarget() } diff --git a/gradle/kotlin-js-store/package-lock.json b/gradle/kotlin-js-store/package-lock.json index e1e0d35e181..b863e4f6a55 100644 --- a/gradle/kotlin-js-store/package-lock.json +++ b/gradle/kotlin-js-store/package-lock.json @@ -1,12 +1,12 @@ { "name": "kotlin-mpp-playground", - "version": "0.11.0.55+d36c24e", + "version": "0.12.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "kotlin-mpp-playground", - "version": "0.11.0.55+d36c24e", + "version": "0.12.0", "workspaces": [ "packages/kotlin-mpp-playground-shared", "packages/kotlin-mpp-playground-shared-test", @@ -17,7 +17,7 @@ "packages_imported/Kotlin-DateTime-library-kotlinx-datetime/0.6.0-RC.2", "packages_imported/ktor-ktor-client-ktor-client-core/3.0.0-beta-1", "packages_imported/kotlin-test-js-runner/0.0.1", - "packages_imported/kotlin-cssom-core/0.0.1-pre.739", + "packages_imported/kotlin-cssom-core/0.0.1-pre.747", "packages_imported/Kotlin-DateTime-library-kotlinx-datetime-wasm-js/0.6.0-RC.2" ], "devDependencies": {} @@ -3025,7 +3025,7 @@ } }, "node_modules/kotlin-cssom-core": { - "resolved": "packages_imported/kotlin-cssom-core/0.0.1-pre.739", + "resolved": "packages_imported/kotlin-cssom-core/0.0.1-pre.747", "link": true }, "node_modules/Kotlin-DateTime-library-kotlinx-datetime": { @@ -5970,7 +5970,16 @@ "devDependencies": {} }, "packages_imported/kotlin-cssom-core/0.0.1-pre.739": { + "name": "kotlin-cssom-core", "version": "0.0.1-pre.739", + "extraneous": true, + "dependencies": { + "format-util": "^1.0.5" + }, + "devDependencies": {} + }, + "packages_imported/kotlin-cssom-core/0.0.1-pre.747": { + "version": "0.0.1-pre.747", "dependencies": { "format-util": "^1.0.5" }, @@ -6014,7 +6023,7 @@ "devDependencies": {} }, "packages/kotlin-mpp-playground-shared": { - "version": "0.11.0-55+d36c24e", + "version": "0.12.0", "dependencies": { "@js-joda/core": "3.2.0", "abort-controller": "3.0.0", @@ -6031,7 +6040,7 @@ } }, "packages/kotlin-mpp-playground-shared-test": { - "version": "0.11.0-55+d36c24e", + "version": "0.12.0", "dependencies": { "@js-joda/core": "3.2.0", "abort-controller": "3.0.0", @@ -6055,7 +6064,7 @@ } }, "packages/kotlin-mpp-playground-web-js": { - "version": "0.11.0-55+d36c24e", + "version": "0.12.0", "dependencies": { "@js-joda/core": "3.2.0", "@xterm/xterm": "5.5.0", @@ -6074,7 +6083,7 @@ } }, "packages/kotlin-mpp-playground-web-js-test": { - "version": "0.11.0-55+d36c24e", + "version": "0.12.0", "dependencies": { "@js-joda/core": "3.2.0", "@xterm/xterm": "5.5.0", @@ -6100,7 +6109,7 @@ } }, "packages/wasm-app": { - "version": "0.11.0-55+d36c24e", + "version": "0.12.0", "dependencies": { "@js-joda/core": "3.2.0", "format-util": "^1.0.5" @@ -6114,7 +6123,7 @@ } }, "packages/wasm-app-test": { - "version": "0.11.0-55+d36c24e", + "version": "0.12.0", "dependencies": { "@js-joda/core": "3.2.0", "format-util": "^1.0.5"