build.gradle.kts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. `maven-publish`
  20. }
  21. description = "Mirai Protocol implementation for QQ Android"
  22. kotlin {
  23. explicitApi()
  24. configureJvmTargetsHierarchical()
  25. configureNativeTargetsHierarchical(project)
  26. sourceSets.apply {
  27. val commonMain by getting {
  28. dependencies {
  29. api(project(":mirai-core-api"))
  30. api(`kotlinx-serialization-core`)
  31. api(`kotlinx-serialization-json`)
  32. api(`kotlinx-coroutines-core`)
  33. implementation(project(":mirai-core-utils"))
  34. implementation(`kotlinx-serialization-protobuf`)
  35. implementation(`kotlinx-atomicfu`)
  36. implementation(`ktor-io`)
  37. implementation(`ktor-client-core`)
  38. }
  39. }
  40. commonTest {
  41. dependencies {
  42. implementation(kotlin("script-runtime"))
  43. api(yamlkt)
  44. }
  45. }
  46. val jvmBaseMain by getting {
  47. dependencies {
  48. implementation(bouncycastle)
  49. implementation(`log4j-api`)
  50. implementation(`netty-all`)
  51. implementation(`ktor-client-okhttp`)
  52. api(`kotlinx-coroutines-core`)
  53. }
  54. }
  55. val jvmBaseTest by getting {
  56. dependencies {
  57. implementation(`kotlinx-coroutines-debug`)
  58. }
  59. }
  60. if (isAndroidSDKAvailable) {
  61. val androidMain by getting {
  62. dependsOn(commonMain)
  63. dependencies {
  64. compileOnly(`android-runtime`)
  65. }
  66. }
  67. val androidTest by getting {
  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("org.bouncycastle:bcprov-jdk15on:1.64")
  74. }
  75. }
  76. }
  77. val jvmMain by getting {
  78. dependencies {
  79. //implementation("org.bouncycastle:bcprov-jdk15on:1.64")
  80. // api(kotlinx("coroutines-debug", Versions.coroutines))
  81. }
  82. }
  83. val jvmTest by getting {
  84. dependencies {
  85. api(`kotlinx-coroutines-debug`)
  86. // implementation("net.mamoe:mirai-login-solver-selenium:1.0-dev-14")
  87. }
  88. }
  89. val nativeMain by getting {
  90. dependencies {
  91. }
  92. }
  93. NATIVE_TARGETS.forEach { targetName ->
  94. val defFile = projectDir.resolve("src/nativeMain/cinterop/OpenSSL.def")
  95. val target = targets.getByName(targetName) as KotlinNativeTarget
  96. target.compilations.getByName("main").cinterops.create("OpenSSL")
  97. .apply {
  98. this.defFile = defFile
  99. packageName("openssl")
  100. }
  101. configure(target.binaries.filterIsInstance<AbstractNativeLibrary>()) {
  102. export(project(":mirai-core-api"))
  103. export(project(":mirai-core-utils"))
  104. }
  105. }
  106. UNIX_LIKE_TARGETS.forEach { target ->
  107. (targets.getByName(target) as KotlinNativeTarget).compilations.getByName("main").cinterops.create("Socket")
  108. .apply {
  109. defFile = projectDir.resolve("src/unixMain/cinterop/Socket.def")
  110. packageName("sockets")
  111. }
  112. }
  113. WIN_TARGETS.forEach { target ->
  114. (targets.getByName(target) as KotlinNativeTarget).compilations.getByName("main").cinterops.create("Socket")
  115. .apply {
  116. defFile = projectDir.resolve("src/mingwX64Main/cinterop/Socket.def")
  117. packageName("sockets")
  118. }
  119. }
  120. configure(WIN_TARGETS.map { getByName(it + "Main") }) {
  121. dependencies {
  122. implementation(`ktor-client-curl`)
  123. }
  124. }
  125. configure(LINUX_TARGETS.map { getByName(it + "Main") }) {
  126. dependencies {
  127. implementation(`ktor-client-cio`)
  128. }
  129. }
  130. val darwinMain by getting {
  131. dependencies {
  132. implementation(`ktor-client-darwin`)
  133. }
  134. }
  135. disableCrossCompile()
  136. // val unixMain by getting {
  137. // dependencies {
  138. // implementation(`ktor-client-cio`)
  139. // }
  140. // }
  141. }
  142. }
  143. afterEvaluate {
  144. val main = projectDir.resolve("src/nativeTest/kotlin/local/TestMain.kt")
  145. if (!main.exists()) {
  146. main.writeText(
  147. """
  148. /*
  149. * Copyright 2019-2022 Mamoe Technologies and contributors.
  150. *
  151. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  152. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  153. *
  154. * https://github.com/mamoe/mirai/blob/dev/LICENSE
  155. */
  156. package net.mamoe.mirai.internal.local
  157. fun main() {}
  158. """.trimIndent()
  159. )
  160. }
  161. }
  162. if (isAndroidSDKAvailable) {
  163. tasks.register("checkAndroidApiLevel") {
  164. doFirst {
  165. analyzes.AndroidApiLevelCheck.check(
  166. buildDir.resolve("classes/kotlin/android/main"),
  167. project.property("mirai.android.target.api.level")!!.toString().toInt(),
  168. project
  169. )
  170. }
  171. group = "verification"
  172. this.mustRunAfter("androidMainClasses")
  173. }
  174. tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
  175. }
  176. configureMppPublishing()
  177. configureBinaryValidators("jvm", "android")