Skip to content

Commit a34c260

Browse files
whyolegosipxd
andauthored
KTOR-7289: Initial support for android native targets (#4236)
* Support for android native targets * Update API dump * Hack to overcome issue with commonizer --------- Co-authored-by: Osip Fatkullin <[email protected]>
1 parent 3c8d558 commit a34c260

File tree

79 files changed

+521
-180
lines changed

Some content is hidden

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

79 files changed

+521
-180
lines changed

buildSrc/src/main/kotlin/NativeUtils.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
/*
2-
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
import org.gradle.api.*
66

77
fun Project.posixTargets(): List<String> = nixTargets() + windowsTargets()
88

9-
fun Project.nixTargets(): List<String> = darwinTargets() + linuxTargets()
9+
fun Project.nixTargets(): List<String> = darwinTargets() + linuxTargets() + androidNativeTargets()
10+
11+
fun Project.androidNativeTargets(): List<String> = with(kotlin) {
12+
if (project.targetIsEnabled("androidNative")) listOf(
13+
androidNativeArm32(),
14+
androidNativeArm64(),
15+
androidNativeX86(),
16+
androidNativeX64(),
17+
) else emptyList()
18+
}.map { it.name }
1019

1120
fun Project.linuxTargets(): List<String> = with(kotlin) {
1221
listOf(

buildSrc/src/main/kotlin/Publication.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ fun isAvailableForPublication(publication: Publication): Boolean {
4949

5050
result = result || (HOST_NAME == "macos" && name in macPublications)
5151

52+
// can be published from any host
53+
val androidNativePublication = setOf(
54+
"androidNativeArm32",
55+
"androidNativeArm64",
56+
"androidNativeX64",
57+
"androidNativeX86"
58+
)
59+
60+
result = result || name in androidNativePublication
61+
5262
return result
5363
}
5464

buildSrc/src/main/kotlin/TargetsConfig.kt

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
@file:OptIn(ExperimentalKotlinGradlePluginApi::class)
6+
57
import org.gradle.api.*
68
import org.gradle.api.tasks.testing.*
79
import org.gradle.kotlin.dsl.*
810
import org.jetbrains.kotlin.gradle.*
911
import org.jetbrains.kotlin.gradle.plugin.*
12+
import org.jetbrains.kotlin.gradle.plugin.mpp.*
13+
import org.jetbrains.kotlin.konan.target.*
1014
import org.jetbrains.kotlin.gradle.tasks.*
1115
import java.io.*
1216

@@ -19,14 +23,15 @@ val Project.hasDesktop: Boolean get() = hasPosix || files.any { it.name == "desk
1923
val Project.hasNix: Boolean get() = hasPosix || hasJvmAndNix || files.any { it.name == "nix" }
2024
val Project.hasLinux: Boolean get() = hasNix || files.any { it.name == "linux" }
2125
val Project.hasDarwin: Boolean get() = hasNix || files.any { it.name == "darwin" }
26+
val Project.hasAndroidNative: Boolean get() = hasPosix || files.any { it.name == "androidNative" }
2227
val Project.hasWindows: Boolean get() = hasPosix || files.any { it.name == "windows" }
2328
val Project.hasJsAndWasmShared: Boolean get() = files.any { it.name == "jsAndWasmShared" }
2429
val Project.hasJs: Boolean get() = hasCommon || files.any { it.name == "js" } || hasJsAndWasmShared
2530
val Project.hasWasm: Boolean get() = hasCommon || files.any { it.name == "wasmJs" } || hasJsAndWasmShared
2631
val Project.hasJvm: Boolean get() = hasCommon || hasJvmAndNix || hasJvmAndPosix || files.any { it.name == "jvm" }
2732

2833
val Project.hasExplicitNative: Boolean
29-
get() = hasNix || hasPosix || hasLinux || hasDarwin || hasDesktop || hasWindows
34+
get() = hasNix || hasPosix || hasLinux || hasAndroidNative || hasDarwin || hasDesktop || hasWindows
3035
val Project.hasNative: Boolean
3136
get() = hasCommon || hasExplicitNative
3237

@@ -43,10 +48,10 @@ fun Project.configureTargets() {
4348
if (hasNix) nixTargets()
4449
if (hasDarwin) darwinTargets()
4550
if (hasLinux) linuxTargets()
51+
if (hasAndroidNative) androidNativeTargets()
4652
if (hasDesktop) desktopTargets()
4753
if (hasWindows) windowsTargets()
4854

49-
@OptIn(ExperimentalKotlinGradlePluginApi::class)
5055
applyHierarchyTemplate(hierarchyTemplate)
5156
}
5257

@@ -75,7 +80,6 @@ fun Project.configureTargets() {
7580
}
7681
}
7782

78-
@OptIn(ExperimentalKotlinGradlePluginApi::class)
7983
private val hierarchyTemplate = KotlinHierarchyTemplate {
8084
withSourceSetTree(KotlinSourceSetTree.main, KotlinSourceSetTree.test)
8185

@@ -87,13 +91,23 @@ private val hierarchyTemplate = KotlinHierarchyTemplate {
8791
group("linux") { withLinux() }
8892

8993
group("darwin") {
90-
withApple()
91-
9294
group("ios") { withIos() }
9395
group("tvos") { withTvos() }
9496
group("watchos") { withWatchos() }
9597
group("macos") { withMacos() }
9698
}
99+
100+
group("androidNative") {
101+
group("androidNative64") {
102+
withAndroidNativeX64()
103+
withAndroidNativeArm64()
104+
}
105+
106+
group("androidNative32") {
107+
withAndroidNativeX86()
108+
withAndroidNativeArm32Fixed()
109+
}
110+
}
97111
}
98112
}
99113

@@ -128,7 +142,18 @@ private val hierarchyTemplate = KotlinHierarchyTemplate {
128142
* - `target.js.nodeJs`
129143
* - `target.js.browser`
130144
* - `target.wasmJs.browser`
145+
* - `target.androidNative`
131146
*/
132147
internal fun Project.targetIsEnabled(target: String): Boolean {
133148
return findProperty("target.$target") != "false"
134149
}
150+
151+
/**
152+
* Original `withAndroidNativeArm32` has a bug and matches to `X86` actually.
153+
* TODO: Remove after the bug is fixed
154+
* https://youtrack.jetbrains.com/issue/KT-71866/
155+
*/
156+
private fun KotlinHierarchyBuilder.withAndroidNativeArm32Fixed() = withCompilations {
157+
val target = it.target
158+
target is KotlinNativeTarget && target.konanTarget == KonanTarget.ANDROID_ARM32
159+
}

ktor-client/ktor-client-cio/api/ktor-client-cio.klib.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Klib ABI Dump
2-
// Targets: [iosArm64, iosSimulatorArm64, iosX64, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
2+
// Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
33
// Rendering settings:
44
// - Signature version: 2
55
// - Show manifest properties: true

ktor-client/ktor-client-core/api/ktor-client-core.klib.api

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Klib ABI Dump
2-
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
3-
// Alias: native => [iosArm64, iosSimulatorArm64, iosX64, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
2+
// Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
3+
// Alias: native => [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
44
// Rendering settings:
55
// - Signature version: 2
66
// - Show manifest properties: true

ktor-client/ktor-client-mock/api/ktor-client-mock.klib.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Klib ABI Dump
2-
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
2+
// Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
33
// Rendering settings:
44
// - Signature version: 2
55
// - Show manifest properties: true

ktor-client/ktor-client-plugins/ktor-client-auth/api/ktor-client-auth.klib.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Klib ABI Dump
2-
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
2+
// Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
33
// Rendering settings:
44
// - Signature version: 2
55
// - Show manifest properties: true

ktor-client/ktor-client-plugins/ktor-client-bom-remover/api/ktor-client-bom-remover.klib.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Klib ABI Dump
2-
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
2+
// Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
33
// Rendering settings:
44
// - Signature version: 2
55
// - Show manifest properties: true

ktor-client/ktor-client-plugins/ktor-client-call-id/api/ktor-client-call-id.klib.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Klib ABI Dump
2-
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
2+
// Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
33
// Rendering settings:
44
// - Signature version: 2
55
// - Show manifest properties: true

ktor-client/ktor-client-plugins/ktor-client-content-negotiation/api/ktor-client-content-negotiation.klib.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Klib ABI Dump
2-
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
2+
// Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
33
// Rendering settings:
44
// - Signature version: 2
55
// - Show manifest properties: true

0 commit comments

Comments
 (0)