build.gradle.kts 7.7 KB

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