-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into bjhham/pinger-failure-fix
- Loading branch information
Showing
42 changed files
with
1,028 additions
and
498 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
* Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
import ktorbuild.KtorBuildExtension | ||
import ktorbuild.internal.resolveVersion | ||
|
||
version = resolveVersion() | ||
|
||
extensions.create<KtorBuildExtension>(KtorBuildExtension.NAME) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
import ktorbuild.internal.gradle.* | ||
import ktorbuild.internal.ktorBuild | ||
import ktorbuild.maybeNamed | ||
import ktorbuild.targets.* | ||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi | ||
|
||
plugins { | ||
id("ktorbuild.base") | ||
kotlin("multiplatform") | ||
} | ||
|
||
kotlin { | ||
@OptIn(ExperimentalKotlinGradlePluginApi::class) | ||
applyHierarchyTemplate(KtorTargets.hierarchyTemplate) | ||
addTargets(ktorBuild.targets) | ||
|
||
// Specify JVM toolchain later to prevent it from being evaluated before it was configured. | ||
// TODO: Remove `afterEvaluate` when the BCV issue triggering JVM toolchain evaluation is fixed | ||
// https://github.com/Kotlin/binary-compatibility-validator/issues/286 | ||
afterEvaluate { | ||
jvmToolchain { | ||
languageVersion = ktorBuild.jvmToolchain | ||
} | ||
} | ||
} | ||
|
||
val targets = ktorBuild.targets | ||
|
||
configureCommon() | ||
if (targets.hasJvm) configureJvm() | ||
if (targets.hasJs) configureJs() | ||
if (targets.hasWasmJs) configureWasmJs() | ||
|
||
if (targets.hasJsOrWasmJs) { | ||
tasks.configureEach { | ||
if (name == "compileJsAndWasmSharedMainKotlinMetadata") enabled = false | ||
} | ||
} | ||
|
||
// Run native tests only on matching host. | ||
// There is no need to configure `onlyIf` for Darwin targets as they're configured by KGP. | ||
@Suppress("UnstableApiUsage") | ||
if (targets.hasNative) { | ||
tasks.maybeNamed("linkDebugTestLinuxX64") { | ||
onlyIf("run only on Linux") { ktorBuild.os.get().isLinux() } | ||
} | ||
tasks.maybeNamed("linkDebugTestLinuxArm64") { | ||
onlyIf("run only on Linux") { ktorBuild.os.get().isLinux() } | ||
} | ||
tasks.maybeNamed("linkDebugTestMingwX64") { | ||
onlyIf("run only on Windows") { ktorBuild.os.get().isWindows() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package ktorbuild | ||
|
||
import ktorbuild.targets.KtorTargets | ||
import org.gradle.kotlin.dsl.assign | ||
import org.gradle.kotlin.dsl.getValue | ||
import org.gradle.kotlin.dsl.provideDelegate | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension | ||
import org.jetbrains.kotlin.gradle.plugin.mpp.DefaultCInteropSettings | ||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget | ||
|
||
/** | ||
* Creates a CInterop configuration for all Native targets using the given [sourceSet] | ||
* in a Kotlin Multiplatform project. | ||
* | ||
* The [name] defines the CInterop configuration name. Definition file is expected to be located | ||
* at `[sourceSet]/interop/[name].def` by default, but can be customized via [definitionFilePath]. | ||
* Additional configuration can be provided through [configure] block. | ||
* | ||
* Simple usage: | ||
* ``` | ||
* kotlin { | ||
* createCInterop("ssl", "posix") | ||
* } | ||
* ``` | ||
* | ||
* Advanced usage with a separate definition for each target and additional configuration: | ||
* ``` | ||
* kotlin { | ||
* createCInterop( | ||
* name = "ssl", | ||
* sourceSet = "posix", | ||
* definitionFilePath = { target -> "$target/interop/ssl.def" }, | ||
* configure = { target -> | ||
* includeDirs("$target/interop/include") | ||
* compilerOpts("-DUSE_SSL") | ||
* } | ||
* ) | ||
* } | ||
* ``` | ||
*/ | ||
@Suppress("UnstableApiUsage") | ||
fun KotlinMultiplatformExtension.createCInterop( | ||
name: String, | ||
sourceSet: String, | ||
definitionFilePath: (String) -> String = { "$sourceSet/interop/$name.def" }, | ||
configure: DefaultCInteropSettings.(String) -> Unit = {} | ||
) { | ||
val cinteropTargets = KtorTargets.resolveTargets(sourceSet) | ||
val projectDirectory = project.isolated.projectDirectory | ||
|
||
targets.named { it in cinteropTargets } | ||
.all { | ||
check(this is KotlinNativeTarget) { "Can't create cinterop for non-native target $targetName" } | ||
|
||
val main by compilations | ||
main.cinterops.create(name) { | ||
definitionFile = projectDirectory.file(definitionFilePath(targetName)) | ||
configure(targetName) | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
build-logic/src/main/kotlin/ktorbuild/KtorBuildExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package ktorbuild | ||
|
||
import ktorbuild.internal.gradle.finalizedOnRead | ||
import ktorbuild.targets.KtorTargets | ||
import org.gradle.api.JavaVersion | ||
import org.gradle.api.model.ObjectFactory | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.api.provider.ProviderFactory | ||
import org.gradle.jvm.toolchain.JavaLanguageVersion | ||
import org.gradle.kotlin.dsl.newInstance | ||
import org.gradle.kotlin.dsl.property | ||
import org.gradle.platform.BuildPlatform | ||
import org.gradle.platform.OperatingSystem | ||
import javax.inject.Inject | ||
|
||
@Suppress("UnstableApiUsage") | ||
abstract class KtorBuildExtension( | ||
objects: ObjectFactory, | ||
providers: ProviderFactory, | ||
buildPlatform: BuildPlatform, | ||
val targets: KtorTargets, | ||
) { | ||
|
||
@Inject | ||
constructor( | ||
objects: ObjectFactory, | ||
providers: ProviderFactory, | ||
buildPlatform: BuildPlatform, | ||
) : this(objects, providers, buildPlatform, targets = objects.newInstance()) | ||
|
||
/** | ||
* The JDK version to be used to build the project. | ||
* By default, the minimal supported JDK version is used. | ||
*/ | ||
val jvmToolchain: Property<JavaLanguageVersion> = | ||
objects.property<JavaLanguageVersion>() | ||
.convention(DEFAULT_JDK) | ||
.finalizedOnRead() | ||
|
||
fun jvmToolchain(version: Int) { | ||
jvmToolchain.set(JavaLanguageVersion.of(version)) | ||
} | ||
|
||
/** | ||
* The JDK version to be used for testing. | ||
* | ||
* The value is determined from the Gradle property "test.jdk". | ||
* If the property is not specified, it defaults to the current JDK used by Gradle. | ||
* | ||
* For example, to run tests against JDK 8, run a test task with flag "-Ptest.jdk=8" | ||
* or put this property to `gradle.properties`. | ||
*/ | ||
val jvmTestToolchain: Provider<JavaLanguageVersion> = | ||
providers.gradleProperty("test.jdk") | ||
.orElse(providers.provider { JavaVersion.current().majorVersion }) | ||
.map(JavaLanguageVersion::of) | ||
|
||
/** Host operating system. */ | ||
val os: Provider<OperatingSystem> = providers.provider { buildPlatform.operatingSystem } | ||
|
||
companion object { | ||
const val NAME = "ktorBuild" | ||
|
||
/** The default (minimal) JDK version used for building the project. */ | ||
private val DEFAULT_JDK = JavaLanguageVersion.of(8) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
build-logic/src/main/kotlin/ktorbuild/NamedDomainObjectCollection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package ktorbuild | ||
|
||
import org.gradle.api.NamedDomainObjectCollection | ||
|
||
internal fun <T> NamedDomainObjectCollection<T>.maybeNamed(name: String, configure: T.() -> Unit) { | ||
if (name in names) named(name).configure(configure) | ||
} |
20 changes: 20 additions & 0 deletions
20
build-logic/src/main/kotlin/ktorbuild/internal/Accessors.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package ktorbuild.internal | ||
|
||
import ktorbuild.KtorBuildExtension | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.getByType | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension | ||
|
||
/* | ||
* Gradle doesn't generate accessors for plugins defined in this module, | ||
* and we can't use generated accessors from .kt files, so we have to declare them manually. | ||
*/ | ||
|
||
internal val Project.ktorBuild: KtorBuildExtension get() = extensions.getByType() | ||
|
||
internal fun Project.kotlin(configure: KotlinMultiplatformExtension.() -> Unit) = | ||
extensions.configure("kotlin", configure) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package ktorbuild.internal | ||
|
||
internal fun String.capitalized() = replaceFirstChar { it.uppercase() } |
Oops, something went wrong.