2
0

build.gradle.kts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * Copyright 2019-2022 Mamoe Technologies and contributors.
  3. *
  4. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  5. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  6. *
  7. * https://github.com/mamoe/mirai/blob/dev/LICENSE
  8. */
  9. @file:Suppress("UNUSED_VARIABLE")
  10. import BinaryCompatibilityConfigurator.configureBinaryValidators
  11. import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractNativeLibrary
  12. import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
  13. plugins {
  14. kotlin("multiplatform")
  15. // id("kotlinx-atomicfu")
  16. kotlin("plugin.serialization")
  17. id("me.him188.kotlin-jvm-blocking-bridge")
  18. id("me.him188.kotlin-dynamic-delegation")
  19. // id("me.him188.maven-central-publish")
  20. `maven-publish`
  21. }
  22. description = "Mirai Protocol implementation for QQ Android"
  23. kotlin {
  24. explicitApi()
  25. configureJvmTargetsHierarchical()
  26. configureNativeTargetsHierarchical(project)
  27. configureNativeTargetBinaries(project) // register native binaries for mirai-core only
  28. sourceSets.apply {
  29. val commonMain by getting {
  30. dependencies {
  31. api(project(":mirai-core-api"))
  32. api(`kotlinx-serialization-core`)
  33. api(`kotlinx-serialization-json`)
  34. api(`kotlinx-coroutines-core`)
  35. implementation(project(":mirai-core-utils"))
  36. implementation(`kotlinx-serialization-protobuf`)
  37. implementation(`kotlinx-atomicfu`)
  38. // relocateImplementation(`ktor-http_relocated`)
  39. // relocateImplementation(`ktor-serialization_relocated`)
  40. // relocateImplementation(`ktor-websocket-serialization_relocated`)
  41. }
  42. }
  43. commonTest {
  44. dependencies {
  45. implementation(kotlin("script-runtime"))
  46. implementation(`kotlinx-coroutines-test`)
  47. api(yamlkt)
  48. }
  49. }
  50. findByName("jvmBaseMain")?.apply {
  51. dependencies {
  52. implementation(`log4j-api`)
  53. implementation(`netty-handler`)
  54. api(`kotlinx-coroutines-jdk8`) // use -jvm modules for this magic target 'jvmBase'
  55. }
  56. }
  57. findByName("jvmBaseTest")?.apply {
  58. dependencies {
  59. implementation(`kotlinx-coroutines-debug`)
  60. }
  61. }
  62. findByName("androidMain")?.apply {
  63. dependencies {
  64. compileOnly(`android-runtime`)
  65. }
  66. }
  67. findByName("androidTest")?.apply {
  68. dependencies {
  69. implementation(kotlin("test", Versions.kotlinCompiler))
  70. implementation(kotlin("test-junit5", Versions.kotlinCompiler))
  71. implementation(kotlin("test-annotations-common"))
  72. implementation(kotlin("test-common"))
  73. implementation(bouncycastle)
  74. }
  75. }
  76. findByName("jvmMain")?.apply {
  77. dependencies {
  78. implementation(bouncycastle)
  79. // api(kotlinx("coroutines-debug", Versions.coroutines))
  80. }
  81. }
  82. findByName("jvmTest")?.apply {
  83. dependencies {
  84. api(`kotlinx-coroutines-debug`)
  85. // implementation("net.mamoe:mirai-login-solver-selenium:1.0-dev-14")
  86. }
  87. }
  88. findByName("nativeMain")?.apply {
  89. dependencies {
  90. }
  91. }
  92. // Ktor
  93. findByName("commonMain")?.apply {
  94. dependencies {
  95. relocateCompileOnly(`ktor-io_relocated`) // runtime from mirai-core-utils
  96. relocateImplementation(`ktor-client-core_relocated`)
  97. }
  98. }
  99. findByName("jvmBaseMain")?.apply {
  100. dependencies {
  101. relocateImplementation(`ktor-client-okhttp_relocated`)
  102. }
  103. }
  104. configure(WIN_TARGETS.map { getByName(it + "Main") }) {
  105. dependencies {
  106. implementation(`ktor-client-curl`)
  107. }
  108. }
  109. configure(LINUX_TARGETS.map { getByName(it + "Main") }) {
  110. dependencies {
  111. implementation(`ktor-client-cio`)
  112. }
  113. }
  114. findByName("darwinMain")?.apply {
  115. dependencies {
  116. implementation(`ktor-client-darwin`)
  117. }
  118. }
  119. // Linkage
  120. NATIVE_TARGETS.forEach { targetName ->
  121. val defFile = projectDir.resolve("src/nativeMain/cinterop/OpenSSL.def")
  122. val target = targets.getByName(targetName) as KotlinNativeTarget
  123. target.compilations.getByName("main").cinterops.create("OpenSSL")
  124. .apply {
  125. this.defFile = defFile
  126. packageName("openssl")
  127. }
  128. configure(target.binaries.filterIsInstance<AbstractNativeLibrary>()) {
  129. export(project(":mirai-core-api"))
  130. export(project(":mirai-core-utils"))
  131. }
  132. }
  133. UNIX_LIKE_TARGETS.forEach { target ->
  134. (targets.getByName(target) as KotlinNativeTarget).compilations.getByName("main").cinterops.create("Socket")
  135. .apply {
  136. defFile = projectDir.resolve("src/unixMain/cinterop/Socket.def")
  137. packageName("sockets")
  138. }
  139. }
  140. WIN_TARGETS.forEach { target ->
  141. (targets.getByName(target) as KotlinNativeTarget).compilations.getByName("main").cinterops.create("Socket")
  142. .apply {
  143. defFile = projectDir.resolve("src/mingwX64Main/cinterop/Socket.def")
  144. packageName("sockets")
  145. }
  146. }
  147. disableCrossCompile()
  148. // val unixMain by getting {
  149. // dependencies {
  150. // implementation(`ktor-client-cio`)
  151. // }
  152. // }
  153. }
  154. }
  155. afterEvaluate {
  156. val main = projectDir.resolve("src/nativeTest/kotlin/local/TestMain.kt")
  157. if (!main.exists()) {
  158. main.writeText(
  159. """
  160. /*
  161. * Copyright 2019-2022 Mamoe Technologies and contributors.
  162. *
  163. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  164. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  165. *
  166. * https://github.com/mamoe/mirai/blob/dev/LICENSE
  167. */
  168. package net.mamoe.mirai.internal.local
  169. fun main() {}
  170. """.trimIndent()
  171. )
  172. }
  173. }
  174. if (tasks.findByName("androidMainClasses") != null) {
  175. tasks.register("checkAndroidApiLevel") {
  176. doFirst {
  177. analyzes.AndroidApiLevelCheck.check(
  178. buildDir.resolve("classes/kotlin/android/main"),
  179. project.property("mirai.android.target.api.level")!!.toString().toInt(),
  180. project
  181. )
  182. }
  183. group = "verification"
  184. this.mustRunAfter("androidMainClasses")
  185. }
  186. tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
  187. }
  188. configureMppPublishing()
  189. configureBinaryValidators(setOf("jvm", "android").filterTargets())
  190. //mavenCentralPublish {
  191. // artifactId = "mirai-core"
  192. // githubProject("mamoe", "mirai")
  193. // developer("Mamoe Technologies", email = "[email protected]", url = "https://github.com/mamoe")
  194. // licenseFromGitHubProject("AGPLv3", "dev")
  195. // publishPlatformArtifactsInRootModule = "jvm"
  196. //}