From 1a479706e2e1bc30cfe252b5928505cfe16bcf50 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 20 Oct 2023 22:07:14 +0600 Subject: [PATCH] update version of microutils and add arm platform target --- gradle/libs.versions.toml | 2 +- mppProjectWithSerialization.gradle | 1 + .../ActualDefaultCoroutineScopeProvider.kt | 6 +++++ tgbotapi.core/build.gradle | 6 +++++ .../src/linuxArm64Main/kotlin/PackageInfo.kt | 1 + .../kotlin/bot/ktor/KtorRequestsExecutor.kt | 5 +++++ .../bot/ktor/base/ActualPlatformClientCopy.kt | 22 +++++++++++++++++++ .../abstracts/ActualMPPFileAsMultipartFile.kt | 9 ++++++++ .../utils/ActualByteReadChannelAsInput.kt | 7 ++++++ .../kotlin/utils/ActualMimeType.kt | 12 ++++++++++ 10 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tgbotapi.behaviour_builder/src/linuxArm64Main/kotlin/ActualDefaultCoroutineScopeProvider.kt create mode 100644 tgbotapi.core/src/linuxArm64Main/kotlin/PackageInfo.kt create mode 100644 tgbotapi.core/src/linuxArm64Main/kotlin/bot/ktor/KtorRequestsExecutor.kt create mode 100644 tgbotapi.core/src/linuxArm64Main/kotlin/bot/ktor/base/ActualPlatformClientCopy.kt create mode 100644 tgbotapi.core/src/linuxArm64Main/kotlin/requests/abstracts/ActualMPPFileAsMultipartFile.kt create mode 100644 tgbotapi.core/src/linuxArm64Main/kotlin/utils/ActualByteReadChannelAsInput.kt create mode 100644 tgbotapi.core/src/linuxArm64Main/kotlin/utils/ActualMimeType.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4db3ade5c1..3b327da7f7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,7 +13,7 @@ ktor = "2.3.5" ksp = "1.9.20-RC-1.0.13" kotlin-poet = "1.14.2" -microutils = "0.20.8" +microutils = "0.20.9" github-release-plugin = "2.4.1" dokka = "1.9.10" diff --git a/mppProjectWithSerialization.gradle b/mppProjectWithSerialization.gradle index e9ddf4b451..2f44259eef 100644 --- a/mppProjectWithSerialization.gradle +++ b/mppProjectWithSerialization.gradle @@ -15,6 +15,7 @@ kotlin { } linuxX64() mingwX64() + linuxArm64() sourceSets { commonMain { diff --git a/tgbotapi.behaviour_builder/src/linuxArm64Main/kotlin/ActualDefaultCoroutineScopeProvider.kt b/tgbotapi.behaviour_builder/src/linuxArm64Main/kotlin/ActualDefaultCoroutineScopeProvider.kt new file mode 100644 index 0000000000..57f3662698 --- /dev/null +++ b/tgbotapi.behaviour_builder/src/linuxArm64Main/kotlin/ActualDefaultCoroutineScopeProvider.kt @@ -0,0 +1,6 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers + +actual var defaultCoroutineScopeProvider: () -> CoroutineScope = { CoroutineScope(Dispatchers.Default) } diff --git a/tgbotapi.core/build.gradle b/tgbotapi.core/build.gradle index e6eb4c507c..f5269f1187 100644 --- a/tgbotapi.core/build.gradle +++ b/tgbotapi.core/build.gradle @@ -55,6 +55,12 @@ kotlin { } } + linuxArm64Main { + dependencies { + api libs.ktor.client.cio + } + } + mingwX64Main { dependencies { api libs.ktor.client.winhttp diff --git a/tgbotapi.core/src/linuxArm64Main/kotlin/PackageInfo.kt b/tgbotapi.core/src/linuxArm64Main/kotlin/PackageInfo.kt new file mode 100644 index 0000000000..20be3dda7a --- /dev/null +++ b/tgbotapi.core/src/linuxArm64Main/kotlin/PackageInfo.kt @@ -0,0 +1 @@ +package dev.inmo.tgbotapi diff --git a/tgbotapi.core/src/linuxArm64Main/kotlin/bot/ktor/KtorRequestsExecutor.kt b/tgbotapi.core/src/linuxArm64Main/kotlin/bot/ktor/KtorRequestsExecutor.kt new file mode 100644 index 0000000000..2f49bfc213 --- /dev/null +++ b/tgbotapi.core/src/linuxArm64Main/kotlin/bot/ktor/KtorRequestsExecutor.kt @@ -0,0 +1,5 @@ +package dev.inmo.tgbotapi.bot.ktor + +import dev.inmo.tgbotapi.bot.ktor.base.MultipleClientKtorRequestsExecutor + +actual typealias KtorRequestsExecutor = MultipleClientKtorRequestsExecutor diff --git a/tgbotapi.core/src/linuxArm64Main/kotlin/bot/ktor/base/ActualPlatformClientCopy.kt b/tgbotapi.core/src/linuxArm64Main/kotlin/bot/ktor/base/ActualPlatformClientCopy.kt new file mode 100644 index 0000000000..ad3e4e5dce --- /dev/null +++ b/tgbotapi.core/src/linuxArm64Main/kotlin/bot/ktor/base/ActualPlatformClientCopy.kt @@ -0,0 +1,22 @@ +package dev.inmo.tgbotapi.bot.ktor.base + +import io.ktor.client.* +import io.ktor.client.engine.cio.* + +/** + * This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native + * platforms and MingwX64 should return [client] + * + * On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl + * + * @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64 + */ +internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = (client.engineConfig as? CIOEngineConfig) ?.let { + lateinit var config: HttpClientConfig + client.config { + config = this as HttpClientConfig + }.close() + HttpClient(CIO) { + this.plusAssign(config) + } +} ?: throw IllegalArgumentException("On LinuxX64 TelegramBotAPI currently support only Curl Ktor HttpClient engine") diff --git a/tgbotapi.core/src/linuxArm64Main/kotlin/requests/abstracts/ActualMPPFileAsMultipartFile.kt b/tgbotapi.core/src/linuxArm64Main/kotlin/requests/abstracts/ActualMPPFileAsMultipartFile.kt new file mode 100644 index 0000000000..942cbfddf2 --- /dev/null +++ b/tgbotapi.core/src/linuxArm64Main/kotlin/requests/abstracts/ActualMPPFileAsMultipartFile.kt @@ -0,0 +1,9 @@ +package dev.inmo.tgbotapi.requests.abstracts + +import dev.inmo.micro_utils.common.MPPFile +import dev.inmo.micro_utils.ktor.common.input +import dev.inmo.tgbotapi.requests.abstracts.MultipartFile + +actual fun MPPFile.asMultipartFile(): MultipartFile = MultipartFile(this.name) { + input() +} diff --git a/tgbotapi.core/src/linuxArm64Main/kotlin/utils/ActualByteReadChannelAsInput.kt b/tgbotapi.core/src/linuxArm64Main/kotlin/utils/ActualByteReadChannelAsInput.kt new file mode 100644 index 0000000000..8f52f52a4e --- /dev/null +++ b/tgbotapi.core/src/linuxArm64Main/kotlin/utils/ActualByteReadChannelAsInput.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.utils + +import io.ktor.utils.io.ByteReadChannel +import io.ktor.utils.io.core.Input +import io.ktor.utils.io.readRemaining + +actual suspend fun ByteReadChannel.asInput(): Input = readRemaining() diff --git a/tgbotapi.core/src/linuxArm64Main/kotlin/utils/ActualMimeType.kt b/tgbotapi.core/src/linuxArm64Main/kotlin/utils/ActualMimeType.kt new file mode 100644 index 0000000000..18ea512429 --- /dev/null +++ b/tgbotapi.core/src/linuxArm64Main/kotlin/utils/ActualMimeType.kt @@ -0,0 +1,12 @@ +package dev.inmo.tgbotapi.utils + +import kotlinx.serialization.Serializable + +//actual typealias MimeType = MimeType + +@OptIn(RiskFeature::class) +@Serializable(MimeTypeSerializer::class) +actual data class MimeType( + actual val raw: String +) +internal actual fun createMimeType(raw: String): MimeType = MimeType(raw)