Skip to content

Commit

Permalink
Merge branch 'main' into feat/buildsrc-config-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-enko authored Jul 15, 2024
2 parents fef3a5e + 9bda7fe commit be99f33
Show file tree
Hide file tree
Showing 622 changed files with 5,748 additions and 37,694 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ hs_err_pid*.log
gradle-user-home

.fleet
.kotlin
25 changes: 4 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ apply(from = "gradle/compatibility.gradle")
plugins {
id("org.jetbrains.dokka") version "1.9.20" apply false
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.14.0"
id("kotlinx-atomicfu") version "0.23.1" apply false
id("com.osacky.doctor") version "0.9.2"
id("org.jetbrains.kotlinx.atomicfu") version "0.25.0" apply false
id("com.osacky.doctor") version "0.10.0"
}

doctor {
Expand All @@ -121,13 +121,14 @@ allprojects {
mavenCentral()
maven(url = "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlinx/dev")
}

val nonDefaultProjectStructure: List<String> by rootProject.extra
if (nonDefaultProjectStructure.contains(project.name)) return@allprojects

apply(plugin = "kotlin-multiplatform")
apply(plugin = "kotlinx-atomicfu")
apply(plugin = "org.jetbrains.kotlinx.atomicfu")

configureTargets()

Expand Down Expand Up @@ -197,11 +198,6 @@ fun Project.setupJvmToolchain() {

fun KotlinMultiplatformExtension.setCompilationOptions() {
targets.all {
if (this is KotlinJsTarget) {
irTarget?.compilations?.all {
configureCompilation()
}
}
compilations.all {
configureCompilation()
}
Expand All @@ -224,16 +220,3 @@ fun KotlinMultiplatformExtension.configureSourceSets() {
}
}
}

// Drop this configuration when the Node.JS version in KGP will support wasm gc milestone 4
// check it here:
// https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/nodejs/NodeJsRootExtension.kt
with(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin.apply(rootProject)) {
// canary nodejs that supports recent Wasm GC changes
nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2"
nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
}
// Drop this when node js version become stable
tasks.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask::class).configureEach {
args.add("--ignore-engines")
}
6 changes: 4 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ repositories {
val ktor_version = "3.0.0-eap-852"

dependencies {
implementation(kotlin("gradle-plugin", "1.9.22"))
implementation(kotlin("serialization", "1.9.22"))
implementation(kotlin("gradle-plugin", "2.0.0"))
implementation(kotlin("serialization", "2.0.0"))

val ktlint_version = libs.versions.ktlint.version.get()
implementation("org.jmailen.gradle:kotlinter-gradle:$ktlint_version")
Expand All @@ -44,6 +44,8 @@ dependencies {

implementation(libs.kotlinx.serialization.json)
implementation(libs.logback.classic)
implementation(libs.tomlj)

}

kotlin {
Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/Compilations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import org.jetbrains.kotlin.gradle.plugin.*

fun KotlinCompilation<KotlinCommonOptions>.configureCompilation() {
kotlinOptions {
if (platformType == KotlinPlatformType.jvm && !IDEA_ACTIVE) {
allWarningsAsErrors = true
}
// if (platformType == KotlinPlatformType.jvm && !IDEA_ACTIVE) {
// allWarningsAsErrors = true
// }

freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
freeCompilerArgs += "-Xexpect-actual-classes"
Expand Down
248 changes: 211 additions & 37 deletions buildSrc/src/main/kotlin/TargetsConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import org.gradle.api.*
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.*
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
import java.io.*

Expand Down Expand Up @@ -51,54 +51,228 @@ fun Project.configureTargets() {

if (hasPosix || hasLinux || hasDarwin || hasWindows) extra.set("hasNative", true)

if (hasPosix) { posixTargets() }
if (hasDesktop) { desktopTargets() }
if (hasNix) { nixTargets() }
if (hasLinux) { linuxTargets() }
if (hasDarwin) { darwinTargets() }
if (hasWindows) { windowsTargets() }

@OptIn(ExperimentalKotlinGradlePluginApi::class)
applyHierarchyTemplate {
common {
group("nix") {
group("darwin") {
group("macos") { withMacos() }
group("ios") { withIos() }
group("tvos") { withTvos() }
group("watchos") { withWatchos() }
sourceSets {
if (hasJsAndWasmShared) {
val commonMain by getting {}
val jsAndWasmSharedMain by creating {
dependsOn(commonMain)
}
val commonTest by getting {}
val jsAndWasmSharedTest by creating {
dependsOn(commonTest)
}

jsMain {
dependsOn(jsAndWasmSharedMain)
}
jsTest {
dependsOn(jsAndWasmSharedTest)
}
wasmJsMain {
dependsOn(jsAndWasmSharedMain)
}
wasmJsTest {
dependsOn(jsAndWasmSharedTest)
}
}

if (hasPosix) {
val posixMain by creating
val posixTest by creating
}

if (hasNix) {
val nixMain by creating
val nixTest by creating
}

if (hasDarwin) {
val darwinMain by creating
val darwinTest by creating {
dependencies {
implementation(kotlin("test"))
}
}

val macosMain by creating
val macosTest by creating

val watchosMain by creating
val watchosTest by creating

val tvosMain by creating
val tvosTest by creating

val iosMain by creating
val iosTest by creating
}

if (hasDesktop) {
val desktopMain by creating
val desktopTest by creating {
dependencies {
implementation(kotlin("test"))
}
group("linux") { withLinux() }
}
}

if (hasLinux) {
val linuxMain by creating
val linuxTest by creating
}

if (hasWindows) {
val windowsMain by creating
val windowsTest by creating
}

if (hasJvmAndNix) {
val jvmAndNixMain by creating {
findByName("commonMain")?.let { dependsOn(it) }
}

val jvmAndNixTest by creating {
findByName("commonTest")?.let { dependsOn(it) }
}
}

withJvm()
if (hasJvm) {
val jvmMain by getting {
findByName("jvmAndNixMain")?.let { dependsOn(it) }
}

val jvmTest by getting {
findByName("jvmAndNixTest")?.let { dependsOn(it) }
}
}

group("jsAndWasmShared") {
withJs()
withWasm()
if (hasPosix) {
val posixMain by getting {
findByName("commonMain")?.let { dependsOn(it) }
}

group("posix") {
group("nix")
group("windows") { withMingw() }
group("desktop") {
group("macos")
group("linux")
group("windows")
val posixTest by getting {
findByName("commonTest")?.let { dependsOn(it) }

dependencies {
implementation(kotlin("test"))
}
}

group("jvmAndNix") {
group("nix")
withJvm()
posixTargets().forEach {
getByName("${it}Main").dependsOn(posixMain)
getByName("${it}Test").dependsOn(posixTest)
}
}
}

sourceSets {
commonTest {
dependencies {
implementation(kotlin("test"))
if (hasNix) {
val nixMain by getting {
findByName("posixMain")?.let { dependsOn(it) }
findByName("jvmAndNixMain")?.let { dependsOn(it) }
}

val nixTest by getting {
findByName("posixTest")?.let { dependsOn(it) }
findByName("jvmAndNixTest")?.let { dependsOn(it) }
}

nixTargets().forEach {
getByName("${it}Main").dependsOn(nixMain)
getByName("${it}Test").dependsOn(nixTest)
}
}

if (hasDarwin) {
val nixMain: KotlinSourceSet? = findByName("nixMain")
val darwinMain by getting
val darwinTest by getting
val macosMain by getting
val macosTest by getting
val iosMain by getting
val iosTest by getting
val watchosMain by getting
val watchosTest by getting
val tvosMain by getting
val tvosTest by getting

nixMain?.let { darwinMain.dependsOn(it) }
macosMain.dependsOn(darwinMain)
tvosMain.dependsOn(darwinMain)
iosMain.dependsOn(darwinMain)
watchosMain.dependsOn(darwinMain)

macosTargets().forEach {
getByName("${it}Main").dependsOn(macosMain)
getByName("${it}Test").dependsOn(macosTest)
}

iosTargets().forEach {
getByName("${it}Main").dependsOn(iosMain)
getByName("${it}Test").dependsOn(iosTest)
}

watchosTargets().forEach {
getByName("${it}Main").dependsOn(watchosMain)
getByName("${it}Test").dependsOn(watchosTest)
}

tvosTargets().forEach {
getByName("${it}Main").dependsOn(tvosMain)
getByName("${it}Test").dependsOn(tvosTest)
}

darwinTargets().forEach {
getByName("${it}Main").dependsOn(darwinMain)
getByName("${it}Test").dependsOn(darwinTest)
}
}

if (hasLinux) {
val linuxMain by getting {
findByName("nixMain")?.let { dependsOn(it) }
}

val linuxTest by getting {
findByName("nixTest")?.let { dependsOn(it) }

dependencies {
implementation(kotlin("test"))
}
}

linuxTargets().forEach {
getByName("${it}Main").dependsOn(linuxMain)
getByName("${it}Test").dependsOn(linuxTest)
}
}

if (hasDesktop) {
val desktopMain by getting {
findByName("posixMain")?.let { dependsOn(it) }
}

val desktopTest by getting

desktopTargets().forEach {
getByName("${it}Main").dependsOn(desktopMain)
getByName("${it}Test").dependsOn(desktopTest)
}
}

if (hasWindows) {
val windowsMain by getting {
findByName("posixMain")?.let { dependsOn(it) }
}

val windowsTest by getting {
dependencies {
implementation(kotlin("test"))
}
}

windowsTargets().forEach {
getByName("${it}Main").dependsOn(windowsMain)
getByName("${it}Test").dependsOn(windowsTest)
}
}

Expand Down
Loading

0 comments on commit be99f33

Please sign in to comment.