2
0

build.gradle.kts 6.7 KB

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