Skip to content

Commit 6f0c34e

Browse files
authored
Merge pull request #5069 from ktorio/zibet27/ktor-client-webrtc-android
WebRTC Client
2 parents 19e067f + cb0bca4 commit 6f0c34e

File tree

98 files changed

+21680
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+21680
-35
lines changed

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ To import into IntelliJ IDEA, just open up the `Ktor` project folder. IntelliJ I
9292
that it is a Gradle project and import it. It's important that you make sure that all building and test operations
9393
are delegated to Gradle under [Gradle Settings](https://www.jetbrains.com/help/idea/gradle-settings.html).
9494

95+
#### Working with Rust-based Modules Locally
96+
97+
The `ktor-client-webrtc-rs` module utilizes Rust components internally. To develop with this module in your local environment, you'll need to complete the following setup steps:
98+
99+
**Prerequisites:**
100+
- Install Rust and Cargo on your system
101+
- Configure your build environment by adding `ktorbuild.rustCompilation=true` to your global `gradle.properties` file
102+
> ⚠️ **Important:** This setting should remain local to your development environment—do not commit this change to version control
103+
104+
**Additional Dependencies:**
105+
Depending on your target platforms, you may need to install additional dependencies for Rust cross-compilation. For comprehensive guidance on cross-compilation requirements and troubleshooting, refer to the [Gobley cross-compilation documentation](https://gobley.dev/docs/cross-compilation-tips).
106+
95107
### Pull Requests
96108

97109
Contributions are made using Github [pull requests](https://help.github.com/en/articles/about-pull-requests):

build-logic/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies {
1515
implementation(libs.gradleDoctor)
1616
implementation(libs.kotlinter)
1717
implementation(libs.mavenPublishing)
18+
implementation(libs.android.kmp.library)
1819

1920
// A hack to make version catalogs accessible from buildSrc sources
2021
// https://github.com/gradle/gradle/issues/15383#issuecomment-779893192

build-logic/settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
pluginManagement {
66
// Add repositories required for build-settings-logic
77
repositories {
8+
google()
89
gradlePluginPortal()
910

1011
// Should be in sync with ktorsettings.kotlin-user-project

build-logic/src/main/kotlin/ktorbuild.kmp.gradle.kts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
1515
plugins {
1616
id("ktorbuild.base")
1717
kotlin("multiplatform")
18-
id("org.jetbrains.kotlinx.atomicfu")
1918
id("ktorbuild.codestyle")
2019
}
2120

21+
// atomicfu gradle plugin is not compatible with Android KMP plugin
22+
// see https://github.com/Kotlin/kotlinx-atomicfu/issues/511
23+
if (!project.hasAndroidPlugin()) {
24+
plugins {
25+
id("org.jetbrains.kotlinx.atomicfu")
26+
}
27+
}
28+
2229
kotlin {
2330
jvmToolchain(KtorBuildExtension.DEFAULT_JDK)
2431
explicitApi()
@@ -31,7 +38,7 @@ kotlin {
3138
}
3239

3340
applyHierarchyTemplate(KtorTargets.hierarchyTemplate)
34-
addTargets(ktorBuild.targets)
41+
addTargets(ktorBuild.targets, ktorBuild.isCI.get())
3542
}
3643

3744
val targets = ktorBuild.targets
@@ -40,6 +47,7 @@ configureCommon()
4047
if (targets.hasJvm) configureJvm()
4148
if (targets.hasJs) configureJs()
4249
if (targets.hasWasmJs) configureWasmJs()
50+
if (targets.hasAndroidJvm && project.hasAndroidPlugin()) configureAndroidJvm()
4351

4452
if (targets.hasJsOrWasmJs) {
4553
tasks.configureEach {
@@ -66,10 +74,10 @@ if (targets.hasNative) {
6674

6775
// A workaround for KT-70915
6876
tasks.withType<KotlinNativeLink>()
69-
.configureEach { withLimitedParallelism("native-link", maxParallelTasks = 1) }
77+
.configureEach { withLimitedParallelism("native-tools", maxParallelTasks = 3) }
7078
// A workaround for KT-77609
7179
tasks.matching { it::class.simpleName?.startsWith("CInteropCommonizerTask") == true }
72-
.configureEach { withLimitedParallelism("cinterop-commonizer", maxParallelTasks = 1) }
80+
.configureEach { withLimitedParallelism("native-tools", maxParallelTasks = 3) }
7381
}
7482

7583
if (ktorBuild.isCI.get()) configureTestTasksOnCi()

build-logic/src/main/kotlin/ktorbuild/internal/publish/PublishTasks.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import org.gradle.kotlin.dsl.withType
1717

1818
private val jvmAndCommonPublications = setOf(
1919
"jvm",
20+
"android",
2021
"androidRelease",
2122
"androidDebug",
2223
"metadata",
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package ktorbuild.targets
6+
7+
import com.android.build.api.dsl.KotlinMultiplatformAndroidLibraryTarget
8+
import org.gradle.api.Project
9+
import ktorbuild.internal.kotlin
10+
import org.gradle.kotlin.dsl.invoke
11+
import ktorbuild.internal.libs
12+
13+
internal fun Project.hasAndroidPlugin(): Boolean {
14+
return plugins.hasPlugin("com.android.kotlin.multiplatform.library")
15+
}
16+
17+
@Suppress("UnstableApiUsage")
18+
internal fun KotlinMultiplatformAndroidLibraryTarget.addTests(targets: KtorTargets, allowDeviceTest: Boolean) {
19+
if (targets.isEnabled("android.unitTest")) {
20+
withHostTest {}
21+
}
22+
if (allowDeviceTest && targets.isEnabled("android.deviceTest")) {
23+
withDeviceTestBuilder {
24+
// make it depend on a commonTest
25+
sourceSetTreeName = "test"
26+
}.configure {
27+
// androidx.test.runner should be installed
28+
instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
29+
}
30+
}
31+
}
32+
33+
internal fun Project.configureAndroidJvm() {
34+
kotlin {
35+
sourceSets {
36+
androidMain {
37+
// should be added automatically, but fails with the new Android KMP plugin
38+
dependsOn(commonMain.get())
39+
}
40+
41+
this.findByName("androidDeviceTest")?.apply {
42+
// should be added automatically, but fails with the new Android KMP plugin
43+
dependsOn(commonTest.get())
44+
dependencies {
45+
implementation(libs.androidx.core)
46+
implementation(libs.androidx.runner)
47+
}
48+
}
49+
}
50+
}
51+
}

build-logic/src/main/kotlin/ktorbuild/targets/KtorTargets.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package ktorbuild.targets
88

9+
import com.android.build.api.dsl.androidLibrary
910
import ktorbuild.internal.KotlinHierarchyTracker
1011
import ktorbuild.internal.TrackedKotlinHierarchyTemplate
1112
import ktorbuild.internal.gradle.ProjectGradleProperties
@@ -50,6 +51,12 @@ import javax.inject.Inject
5051
* target.wasmJs.browser=false
5152
* ```
5253
*
54+
* Android JVM tests could be also configured
55+
* ```properties
56+
* target.android.unitTest=false
57+
* target.android.deviceTest=false
58+
* ```
59+
*
5360
* See the full list of targets and target groups in [KtorTargets.hierarchyTemplate].
5461
*/
5562
abstract class KtorTargets internal constructor(
@@ -76,6 +83,7 @@ abstract class KtorTargets internal constructor(
7683
val hasJvm: Boolean get() = isEnabled("jvm")
7784
val hasJs: Boolean get() = isEnabled("js")
7885
val hasWasmJs: Boolean get() = isEnabled("wasmJs")
86+
val hasAndroidJvm: Boolean get() = isEnabled("android")
7987

8088
val hasJsOrWasmJs: Boolean get() = hasJs || hasWasmJs
8189
val hasNative: Boolean get() = resolveTargets("posix").any(::isEnabled)
@@ -174,6 +182,8 @@ abstract class KtorTargets internal constructor(
174182
group("linux")
175183
group("androidNative")
176184
}
185+
186+
withAndroidTarget()
177187
}
178188
}
179189

@@ -182,8 +192,12 @@ abstract class KtorTargets internal constructor(
182192
}
183193
}
184194

185-
internal fun KotlinMultiplatformExtension.addTargets(targets: KtorTargets) {
195+
internal fun KotlinMultiplatformExtension.addTargets(targets: KtorTargets, isCI: Boolean) {
186196
if (targets.hasJvm) jvm()
197+
if (targets.hasAndroidJvm && project.hasAndroidPlugin()) {
198+
// device tests are not configured on the CI yet
199+
androidLibrary { addTests(targets, allowDeviceTest = !isCI) }
200+
}
187201

188202
if (targets.hasJs) js { addSubTargets(targets) }
189203
@OptIn(ExperimentalWasmDsl::class)

build-settings-logic/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ plugins {
1414

1515
dependencies {
1616
implementation(libs.kotlin.gradlePlugin)
17+
implementation(libs.android.kmp.library)
1718
implementation(libs.develocity)
1819
implementation(libs.develocity.commonCustomUserData)
1920
}

build-settings-logic/settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencyResolutionManagement {
2121
}
2222

2323
repositories {
24+
google()
2425
gradlePluginPortal()
2526

2627
// Should be in sync with ktorsettings.kotlin-user-project

build-settings-logic/src/main/kotlin/ktorsettings.dependency-resolution-management.settings.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@ dependencyResolutionManagement {
2424

2525
downgradeTestDependencies()
2626
}
27+
28+
create("kotlinWrappers") {
29+
from("org.jetbrains.kotlin-wrappers:kotlin-wrappers-catalog:2025.7.10")
30+
}
2731
}
2832
}
2933

3034
private fun RepositoryHandler.configureRepositories() {
3135
google {
3236
content {
37+
includeGroupAndSubgroups("androidx")
3338
includeGroupAndSubgroups("com.google")
3439
includeGroupAndSubgroups("com.android")
3540
}

0 commit comments

Comments
 (0)