build.gradle.kts 6.7 KB

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