From d96641dedbd8b64ed589d7616287a7008c303f9d Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 17 May 2022 09:43:09 +0100 Subject: [PATCH] Configure HMPP project structure --- buildSrc/src/main/kotlin/HmppConfigure.kt | 151 ++++++++++++++++++ buildSrc/src/main/kotlin/ProjectConfigure.kt | 11 +- buildSrc/src/main/kotlin/Versions.kt | 37 ++--- gradle.properties | 10 +- .../backend/integration-test/build.gradle.kts | 10 +- .../backend/mirai-console/build.gradle.kts | 24 +-- .../compiler-annotations/build.gradle.kts | 20 +-- mirai-core-api/build.gradle.kts | 51 +++--- mirai-core-utils/build.gradle.kts | 51 +++--- .../src/nativeMain/kotlin/Base64.kt | 18 +++ mirai-core/build.gradle.kts | 55 +++---- mirai-dokka/build.gradle.kts | 6 +- 12 files changed, 296 insertions(+), 148 deletions(-) create mode 100644 buildSrc/src/main/kotlin/HmppConfigure.kt create mode 100644 mirai-core-utils/src/nativeMain/kotlin/Base64.kt diff --git a/buildSrc/src/main/kotlin/HmppConfigure.kt b/buildSrc/src/main/kotlin/HmppConfigure.kt new file mode 100644 index 000000000..7469cbcdb --- /dev/null +++ b/buildSrc/src/main/kotlin/HmppConfigure.kt @@ -0,0 +1,151 @@ +/* + * Copyright 2019-2022 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/dev/LICENSE + */ + +import org.apache.tools.ant.taskdefs.condition.Os +import org.gradle.api.Project +import org.gradle.api.attributes.Attribute +import org.gradle.kotlin.dsl.get +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.TEST_COMPILATION_NAME +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet + +/* + * Copyright 2019-2022 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/dev/LICENSE + */ + +private val miraiPlatform = Attribute.of( + "net.mamoe.mirai.platform", + String::class.java +) + + +fun Project.configureHMPPJvm() { + extensions.getByType(KotlinMultiplatformExtension::class.java).apply { + jvm("jvmBase") { + attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common) // avoid resolving by others +// attributes.attribute(miraiPlatform, "jvmBase") + } + + if (isAndroidSDKAvailable) { + jvm("android") { + attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm) + // publishAllLibraryVariants() + } + } else { + printAndroidNotInstalled() + } + + jvm("jvm") { + + } + + + val ideaActive = System.getProperty("idea.active") == "true" && System.getProperty("publication.test") != "true" + + val nativeMainSets = mutableListOf() + val nativeTestSets = mutableListOf() + + if (ideaActive) { + when { + Os.isFamily(Os.FAMILY_MAC) -> if (Os.isArch("aarch64")) macosArm64("native") else macosX64("native") + Os.isFamily(Os.FAMILY_WINDOWS) -> mingwX64("native") + else -> linuxX64("native") + } + } else { + // 1.6.0 + val nativeTargets: List = arrayOf( + // serialization doesn't support those commented targets +// "androidNativeArm32, androidNativeArm64, androidNativeX86, androidNativeX64", + "iosArm32, iosArm64, iosX64, iosSimulatorArm64", + "watchosArm32, watchosArm64, watchosX86, watchosX64, watchosSimulatorArm64", + "tvosArm64, tvosX64, tvosSimulatorArm64", + "macosX64, macosArm64", + "linuxMips32, linuxMipsel32, linuxX64", + "mingwX64", +// "wasm32" // linuxArm32Hfp, mingwX86 + ).flatMap { it.split(",") }.map { it.trim() } + presets.filter { it.name in nativeTargets } + .forEach { preset -> + val target = targetFromPreset(preset, preset.name) + nativeMainSets.add(target.compilations[MAIN_COMPILATION_NAME].kotlinSourceSets.first()) + nativeTestSets.add(target.compilations[TEST_COMPILATION_NAME].kotlinSourceSets.first()) + } + + if (!ideaActive) { + configure(nativeMainSets) { + dependsOn(sourceSets.maybeCreate("nativeMain")) + } + + configure(nativeTestSets) { + dependsOn(sourceSets.maybeCreate("nativeTest")) + } + } + } + +// nativeTarget.apply { +// val myrust by compilations.getByName("main").cinterops.creating { +// headers(project.projectDir.resolve("untitled/myrust.h")) +// } +// +// binaries { +// sharedLib { +// linkerOpts("-v") +// linkerOpts("-L${project.projectDir.resolve("untitled/target/debug/").absolutePath}") +//// linkerOpts("-lmyrust") +// linkerOpts("-Wl,-undefined,dynamic_lookup") // resolve symbols in runtime +// baseName = "mykotlin" +// } +// +// executable { +// +// linkerOpts("-v") +// linkerOpts("-L${project.projectDir.resolve("untitled/target/debug/").absolutePath}") +//// linkerOpts("-lmyrust") +// linkerOpts("-Wl,-undefined,dynamic_lookup") // resolve symbols in runtime +// baseName = "KotlinExecutable" +// entryPoint = "main.main" +// } +// } +// } + + + val sourceSets = kotlinSourceSets.orEmpty() + val commonMain = sourceSets.single { it.name == "commonMain" } + val commonTest = sourceSets.single { it.name == "commonTest" } + val jvmBaseMain = this.sourceSets.maybeCreate("jvmBaseMain") + val jvmBaseTest = this.sourceSets.maybeCreate("jvmBaseTest") + val jvmMain = sourceSets.single { it.name == "jvmMain" } + val jvmTest = sourceSets.single { it.name == "jvmTest" } + val androidMain = sourceSets.single { it.name == "androidMain" } + val androidTest = sourceSets.single { it.name == "androidTest" } + + val nativeMain = sourceSets.single { it.name == "nativeMain" } + val nativeTest = sourceSets.single { it.name == "nativeTest" } + + + jvmBaseMain.dependsOn(commonMain) + jvmBaseTest.dependsOn(commonTest) + + jvmMain.dependsOn(jvmBaseMain) + androidMain.dependsOn(jvmBaseMain) + + jvmTest.dependsOn(jvmBaseTest) + androidTest.dependsOn(commonTest) + + nativeMain.dependsOn(commonMain) + nativeTest.dependsOn(commonTest) + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/ProjectConfigure.kt b/buildSrc/src/main/kotlin/ProjectConfigure.kt index e93472295..2c8d7df17 100644 --- a/buildSrc/src/main/kotlin/ProjectConfigure.kt +++ b/buildSrc/src/main/kotlin/ProjectConfigure.kt @@ -19,6 +19,7 @@ import org.gradle.kotlin.dsl.* import org.jetbrains.kotlin.gradle.dsl.* import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet +import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget @@ -56,6 +57,7 @@ fun Project.preConfigureJvmTarget() { targetCompatibility = defaultVer.toString() } } + fun Project.configureJvmTarget() { val defaultVer = jvmVersion() @@ -125,7 +127,7 @@ fun Project.configureKotlinTestSettings() { when { sourceSet.name == "commonTest" -> { - if (target?.platformType == KotlinPlatformType.jvm || target?.platformType == KotlinPlatformType.androidJvm) { + if (isJvmLikePlatform(target)) { configureJvmTest(sourceSet) } else { sourceSet.dependencies { @@ -135,7 +137,9 @@ fun Project.configureKotlinTestSettings() { } } sourceSet.name.contains("test", ignoreCase = true) -> { - configureJvmTest(sourceSet) + if (isJvmLikePlatform(target)) { + configureJvmTest(sourceSet) + } } } } @@ -143,6 +147,9 @@ fun Project.configureKotlinTestSettings() { } } +private fun isJvmLikePlatform(target: KotlinTarget?) = + target?.platformType == KotlinPlatformType.jvm || target?.platformType == KotlinPlatformType.androidJvm + val testExperimentalAnnotations = arrayOf( "kotlin.ExperimentalUnsignedTypes", "kotlin.time.ExperimentalTime", diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 2e7279ba5..ae141eba0 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -58,7 +58,7 @@ object Versions { const val junit = "5.7.2" - const val yamlkt = "0.10.2" + const val yamlkt = "0.11.0" const val intellijGradlePlugin = "1.5.3" // const val kotlinIntellijPlugin = "211-1.5.20-release-284-IJ7442.40" // keep to newest as kotlinCompiler @@ -72,23 +72,20 @@ fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$v @Suppress("unused") fun ktor(id: String, version: String = Versions.ktor) = "io.ktor:ktor-$id:$version" - -// Why using `-jvm`? -// All target platforms are JVM. Root modules like 'coroutines-core' will be resolved to 'coroutines-common' for commonMain, -// which make IDE code analysis not working. - -val `kotlinx-coroutines-core-jvm` = kotlinx("coroutines-core-jvm", Versions.coroutines) +val `kotlinx-coroutines-core` = kotlinx("coroutines-core", Versions.coroutines) val `kotlinx-coroutines-jdk8` = kotlinx("coroutines-jdk8", Versions.coroutines) val `kotlinx-coroutines-swing` = kotlinx("coroutines-swing", Versions.coroutines) val `kotlinx-coroutines-debug` = kotlinx("coroutines-debug", Versions.coroutines) -val `kotlinx-serialization-core-jvm` = kotlinx("serialization-core-jvm", Versions.serialization) -val `kotlinx-serialization-json-jvm` = kotlinx("serialization-json-jvm", Versions.serialization) -val `kotlinx-serialization-protobuf-jvm` = kotlinx("serialization-protobuf-jvm", Versions.serialization) -const val `kotlinx-atomicfu-jvm` = "org.jetbrains.kotlinx:atomicfu-jvm:${Versions.atomicFU}" +val `kotlinx-serialization-core` = kotlinx("serialization-core", Versions.serialization) +val `kotlinx-serialization-json` = kotlinx("serialization-json", Versions.serialization) +val `kotlinx-serialization-protobuf` = kotlinx("serialization-protobuf", Versions.serialization) +const val `kotlinx-atomicfu` = "org.jetbrains.kotlinx:atomicfu:${Versions.atomicFU}" +val `kotlinx-io-common` = kotlinx("io", Versions.io) val `kotlinx-io-jvm` = kotlinx("io-jvm", Versions.io) +val `kotlinx-io-native` = kotlinx("io-macosx64", Versions.io) -fun KotlinDependencyHandler.implementationKotlinxIoJvm() { - implementation(`kotlinx-io-jvm`) { +fun KotlinDependencyHandler.implementationKotlinxIo(module: String) { + implementation(module) { /* | +--- org.jetbrains.kotlinx:kotlinx-io-jvm:0.1.16 | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.60 -> 1.5.30 (*) @@ -103,17 +100,17 @@ fun KotlinDependencyHandler.implementationKotlinxIoJvm() { } } -val `kotlinx-coroutines-io-jvm` = kotlinx("coroutines-io-jvm", Versions.coroutinesIo) +val `kotlinx-coroutines-io` = kotlinx("coroutines-io", Versions.coroutinesIo) val `ktor-serialization` = ktor("serialization", Versions.ktor) -val `ktor-client-core-jvm` = ktor("client-core-jvm", Versions.ktor) -val `ktor-client-cio-jvm` = ktor("client-cio-jvm", Versions.ktor) +val `ktor-client-core` = ktor("client-core-jvm", Versions.ktor) +val `ktor-client-cio` = ktor("client-cio-jvm", Versions.ktor) val `ktor-client-okhttp` = ktor("client-okhttp", Versions.ktor) val `ktor-client-android` = ktor("client-android", Versions.ktor) -val `ktor-client-logging-jvm` = ktor("client-logging-jvm", Versions.ktor) -val `ktor-network-jvm` = ktor("network-jvm", Versions.ktor) -val `ktor-client-serialization-jvm` = ktor("client-serialization-jvm", Versions.ktor) +val `ktor-client-logging` = ktor("client-logging-jvm", Versions.ktor) +val `ktor-network` = ktor("network-jvm", Versions.ktor) +val `ktor-client-serialization` = ktor("client-serialization-jvm", Versions.ktor) const val `logback-classic` = "ch.qos.logback:logback-classic:" + Versions.logback @@ -141,7 +138,7 @@ const val `kotlin-test-junit5` = "org.jetbrains.kotlin:kotlin-test-junit5:${Vers //const val `mirai-core` = "net.mamoe:mirai-core:${Versions.core}" //const val `mirai-core-utils` = "net.mamoe:mirai-core-utils:${Versions.core}" -const val `yamlkt-jvm` = "net.mamoe.yamlkt:yamlkt:${Versions.yamlkt}" +const val `yamlkt` = "net.mamoe.yamlkt:yamlkt:${Versions.yamlkt}" const val `jetbrains-annotations` = "org.jetbrains:annotations:19.0.0" diff --git a/gradle.properties b/gradle.properties index 7b10f90aa..ab45b776f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,12 +1,11 @@ # -# Copyright 2019-2021 Mamoe Technologies and contributors. +# Copyright 2019-2022 Mamoe Technologies and contributors. # -# 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. -# Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. +# 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. +# Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. # -# https://github.com/mamoe/mirai/blob/master/LICENSE +# https://github.com/mamoe/mirai/blob/dev/LICENSE # -# style guide kotlin.code.style=official # config kotlin.incremental.multiplatform=true @@ -15,6 +14,7 @@ org.gradle.parallel=true org.gradle.vfs.watch=true kotlin.mpp.enableGranularSourceSetsMetadata=true kotlin.native.enableDependencyPropagation=false +#kotlin.mpp.enableCompatibilityMetadataVariant=true #kotlin.mpp.enableGranularSourceSetsMetadata=true systemProp.org.gradle.internal.publish.checksums.insecure=true gnsp.disableApplyOnlyOnRootProjectEnforcement=true diff --git a/mirai-console/backend/integration-test/build.gradle.kts b/mirai-console/backend/integration-test/build.gradle.kts index 038a70f94..78b9d0f2b 100644 --- a/mirai-console/backend/integration-test/build.gradle.kts +++ b/mirai-console/backend/integration-test/build.gradle.kts @@ -33,15 +33,15 @@ dependencies { api(project(":mirai-console-terminal")) api(`kotlin-stdlib-jdk8`) - api(`kotlinx-atomicfu-jvm`) - api(`kotlinx-coroutines-core-jvm`) - api(`kotlinx-serialization-core-jvm`) - api(`kotlinx-serialization-json-jvm`) + api(`kotlinx-atomicfu`) + api(`kotlinx-coroutines-core`) + api(`kotlinx-serialization-core`) + api(`kotlinx-serialization-json`) api(`kotlin-reflect`) api(`kotlin-test-junit5`) - api(`yamlkt-jvm`) + api(`yamlkt`) api(`jetbrains-annotations`) api(`caller-finder`) api(`kotlinx-coroutines-jdk8`) diff --git a/mirai-console/backend/mirai-console/build.gradle.kts b/mirai-console/backend/mirai-console/build.gradle.kts index 132c704aa..d135b25e0 100644 --- a/mirai-console/backend/mirai-console/build.gradle.kts +++ b/mirai-console/backend/mirai-console/build.gradle.kts @@ -1,18 +1,18 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2022 Mamoe Technologies and contributors. * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. * - * https://github.com/mamoe/mirai/blob/master/LICENSE + * https://github.com/mamoe/mirai/blob/dev/LICENSE */ @file:Suppress("UnusedImport") import BinaryCompatibilityConfigurator.configureBinaryValidator -import BinaryCompatibilityConfigurator.configureBinaryValidators -import java.time.* -import java.time.format.* +import java.time.Instant +import java.time.ZoneId +import java.time.format.DateTimeFormatter plugins { kotlin("jvm") @@ -45,15 +45,15 @@ dependencies { compileAndTestRuntime(project(":mirai-core-utils")) compileAndTestRuntime(`kotlin-stdlib-jdk8`) - compileAndTestRuntime(`kotlinx-atomicfu-jvm`) - compileAndTestRuntime(`kotlinx-coroutines-core-jvm`) - compileAndTestRuntime(`kotlinx-serialization-core-jvm`) - compileAndTestRuntime(`kotlinx-serialization-json-jvm`) + compileAndTestRuntime(`kotlinx-atomicfu`) + compileAndTestRuntime(`kotlinx-coroutines-core`) + compileAndTestRuntime(`kotlinx-serialization-core`) + compileAndTestRuntime(`kotlinx-serialization-json`) compileAndTestRuntime(`kotlin-reflect`) implementation(project(":mirai-console-compiler-annotations")) - smartImplementation(`yamlkt-jvm`) + smartImplementation(`yamlkt`) smartImplementation(`jetbrains-annotations`) smartImplementation(`caller-finder`) smartImplementation(`maven-resolver-api`) diff --git a/mirai-console/tools/compiler-annotations/build.gradle.kts b/mirai-console/tools/compiler-annotations/build.gradle.kts index 229515489..538ab056f 100644 --- a/mirai-console/tools/compiler-annotations/build.gradle.kts +++ b/mirai-console/tools/compiler-annotations/build.gradle.kts @@ -1,16 +1,14 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2022 Mamoe Technologies and contributors. * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. * - * https://github.com/mamoe/mirai/blob/master/LICENSE + * https://github.com/mamoe/mirai/blob/dev/LICENSE */ @file:Suppress("UnusedImport") -import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType - plugins { kotlin("multiplatform") `maven-publish` @@ -22,15 +20,7 @@ description = "Mirai Console compiler annotations" kotlin { explicitApi() - jvm("android") { - attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm) - } - - jvm("common") { - attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common) - } - - jvm("jvm") + configureHMPPJvm() } configureMppPublishing() \ No newline at end of file diff --git a/mirai-core-api/build.gradle.kts b/mirai-core-api/build.gradle.kts index 6b01f1cfb..dfc72868b 100644 --- a/mirai-core-api/build.gradle.kts +++ b/mirai-core-api/build.gradle.kts @@ -9,7 +9,6 @@ @file:Suppress("UNUSED_VARIABLE") import BinaryCompatibilityConfigurator.configureBinaryValidators -import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType plugins { kotlin("multiplatform") @@ -27,41 +26,22 @@ description = "Mirai API module" kotlin { explicitApi() - - if (isAndroidSDKAvailable) { - jvm("android") { - attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm) - } - } else { - printAndroidNotInstalled() - } - - jvm("common") { - attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common) - } - - jvm("jvm") + configureHMPPJvm() sourceSets { val commonMain by getting { dependencies { api(kotlin("reflect")) - api(`kotlinx-serialization-core-jvm`) - api(`kotlinx-serialization-json-jvm`) - api(`kotlinx-coroutines-core-jvm`) // don't remove it, otherwise IDE will complain - api(`kotlinx-coroutines-jdk8`) - api(`ktor-client-okhttp`) + api(`kotlinx-serialization-core`) + api(`kotlinx-serialization-json`) + api(`kotlinx-coroutines-core`) // don't remove it, otherwise IDE will complain implementation(project(":mirai-core-utils")) implementation(project(":mirai-console-compiler-annotations")) - implementation(`kotlinx-serialization-protobuf-jvm`) - implementation(`jetbrains-annotations`) - implementation(`log4j-api`) - implementation(`kotlinx-atomicfu-jvm`) - implementationKotlinxIoJvm() - - compileOnly(`slf4j-api`) + implementation(`kotlinx-serialization-protobuf`) + implementation(`kotlinx-atomicfu`) + implementationKotlinxIo(`kotlinx-io-common`) } } @@ -71,6 +51,17 @@ kotlin { } } + val jvmBaseMain by getting { + dependencies { + api(`ktor-client-okhttp`) + api(`kotlinx-coroutines-jdk8`) + implementation(`jetbrains-annotations`) + implementation(`log4j-api`) + compileOnly(`slf4j-api`) + implementationKotlinxIo(`kotlinx-io-jvm`) + } + } + if (isAndroidSDKAvailable) { val androidMain by getting { dependsOn(commonMain) @@ -90,6 +81,12 @@ kotlin { runtimeOnly(files("build/classes/kotlin/jvm/test")) // classpath is not properly set by IDE } } + + val nativeMain by getting { + dependencies { + implementationKotlinxIo(`kotlinx-io-native`) + } + } } } diff --git a/mirai-core-utils/build.gradle.kts b/mirai-core-utils/build.gradle.kts index c26c54c6a..c08a1041e 100644 --- a/mirai-core-utils/build.gradle.kts +++ b/mirai-core-utils/build.gradle.kts @@ -1,16 +1,14 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2022 Mamoe Technologies and contributors. * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. * - * https://github.com/mamoe/mirai/blob/master/LICENSE + * https://github.com/mamoe/mirai/blob/dev/LICENSE */ @file:Suppress("UNUSED_VARIABLE") -import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType - plugins { kotlin("multiplatform") kotlin("plugin.serialization") @@ -25,38 +23,31 @@ description = "mirai-core utilities" kotlin { explicitApi() - if (isAndroidSDKAvailable) { - jvm("android") { - attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm) - // publishAllLibraryVariants() - } - } else { - printAndroidNotInstalled() - } - - jvm("common") { - attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common) - } - - jvm("jvm") + configureHMPPJvm() sourceSets { val commonMain by getting { dependencies { api(kotlin("reflect")) - api(`kotlinx-serialization-core-jvm`) - api(`kotlinx-serialization-json-jvm`) - api(`kotlinx-coroutines-core-jvm`) + api(`kotlinx-serialization-core`) + api(`kotlinx-serialization-json`) + api(`kotlinx-coroutines-core`) - implementation(`kotlinx-atomicfu-jvm`) - implementation(`kotlinx-serialization-protobuf-jvm`) - implementationKotlinxIoJvm() + implementation(`kotlinx-atomicfu`) + implementation(`kotlinx-serialization-protobuf`) + implementationKotlinxIo(`kotlinx-io-common`) } } val commonTest by getting { dependencies { - api(`yamlkt-jvm`) + api(yamlkt) + } + } + + val jvmBaseMain by getting { + dependencies { + implementationKotlinxIo(`kotlinx-io-jvm`) } } @@ -77,6 +68,12 @@ kotlin { runtimeOnly(files("build/classes/kotlin/jvm/test")) // classpath is not properly set by IDE } } + + val nativeMain by getting { + dependencies { + implementationKotlinxIo(`kotlinx-io-native`) + } + } } } diff --git a/mirai-core-utils/src/nativeMain/kotlin/Base64.kt b/mirai-core-utils/src/nativeMain/kotlin/Base64.kt new file mode 100644 index 000000000..bc4571e8c --- /dev/null +++ b/mirai-core-utils/src/nativeMain/kotlin/Base64.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2019-2022 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/dev/LICENSE + */ + +package net.mamoe.mirai.utils + +public actual fun String.decodeBase64(): ByteArray { + TODO("Not yet implemented") +} + +public actual fun ByteArray.encodeBase64(): String { + TODO("Not yet implemented") +} \ No newline at end of file diff --git a/mirai-core/build.gradle.kts b/mirai-core/build.gradle.kts index f6f86b50b..067f47b22 100644 --- a/mirai-core/build.gradle.kts +++ b/mirai-core/build.gradle.kts @@ -10,7 +10,6 @@ @file:Suppress("UNUSED_VARIABLE") import BinaryCompatibilityConfigurator.configureBinaryValidators -import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType plugins { kotlin("multiplatform") @@ -23,54 +22,40 @@ plugins { description = "Mirai Protocol implementation for QQ Android" -afterEvaluate { - tasks.getByName("compileKotlinCommon").enabled = false - tasks.getByName("compileTestKotlinCommon").enabled = false - - tasks.getByName("compileCommonMainKotlinMetadata").enabled = false - tasks.getByName("compileKotlinMetadata").enabled = false -} - kotlin { explicitApi() - if (isAndroidSDKAvailable) { - jvm("android") { - attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm) - } - } else { - printAndroidNotInstalled() - } - - jvm("common") { - attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common) - } - - jvm("jvm") + configureHMPPJvm() sourceSets.apply { val commonMain by getting { dependencies { api(project(":mirai-core-api")) - api(`kotlinx-serialization-core-jvm`) - api(`kotlinx-serialization-json-jvm`) - api(`kotlinx-coroutines-core-jvm`) + api(`kotlinx-serialization-core`) + api(`kotlinx-serialization-json`) + api(`kotlinx-coroutines-core`) implementation(project(":mirai-core-utils")) - implementation(`kotlinx-serialization-protobuf-jvm`) - implementation(`kotlinx-atomicfu-jvm`) - implementation(`netty-all`) - implementation(`log4j-api`) - implementation(bouncycastle) - implementationKotlinxIoJvm() + implementation(`kotlinx-serialization-protobuf`) + implementation(`kotlinx-atomicfu`) + implementationKotlinxIo(`kotlinx-io-common`) } } commonTest { dependencies { implementation(kotlin("script-runtime")) - api(`yamlkt-jvm`) + api(yamlkt) + } + } + + val jvmBaseMain by getting { + dependencies { + implementation(bouncycastle) + implementation(`log4j-api`) + implementation(`netty-all`) + implementationKotlinxIo(`kotlinx-io-jvm`) } } @@ -105,6 +90,12 @@ kotlin { // implementation("net.mamoe:mirai-login-solver-selenium:1.0-dev-14") } } + + val nativeMain by getting { + dependencies { + implementationKotlinxIo(`kotlinx-io-native`) + } + } } } diff --git a/mirai-dokka/build.gradle.kts b/mirai-dokka/build.gradle.kts index 18edf9608..455b2fc86 100644 --- a/mirai-dokka/build.gradle.kts +++ b/mirai-dokka/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2022 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. @@ -15,8 +15,8 @@ plugins { } dependencies { - implementation(`kotlinx-serialization-core-jvm`) - implementation(`kotlinx-serialization-json-jvm`) + implementation(`kotlinx-serialization-core`) + implementation(`kotlinx-serialization-json`) } fun Project.newExec(name: String, type: String, conf: JavaExec.() -> Unit) {