mirror of
https://github.com/mamoe/mirai.git
synced 2026-08-22 22:23:32 +08:00
Produce shared libraries and static libraries
This commit is contained in:
@@ -8,10 +8,10 @@
|
||||
*/
|
||||
|
||||
import com.google.gradle.osdetector.OsDetector
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.attributes.Attribute
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.gradle.kotlin.dsl.getByName
|
||||
import org.gradle.kotlin.dsl.getting
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
|
||||
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
|
||||
import java.io.File
|
||||
|
||||
private val miraiPlatform = Attribute.of(
|
||||
@@ -299,6 +300,42 @@ fun KotlinMultiplatformExtension.configureNativeTargetsHierarchical(
|
||||
)
|
||||
}
|
||||
|
||||
// NATIVE_TARGETS.forEach { targetName ->
|
||||
// val target = targets.getByName(targetName) as KotlinNativeTarget
|
||||
// if (!IDEA_ACTIVE && HOST_KIND == HostKind.WINDOWS) {
|
||||
// target.binaries.test(listOf(NativeBuildType.RELEASE)) {
|
||||
// // add release test to run on CI
|
||||
// project.afterEvaluate {
|
||||
// // use linkReleaseTestMingwX64 for mingwX64Test to save memory
|
||||
// tasks.getByName("mingwX64Test", KotlinNativeTest::class)
|
||||
// .executable(linkTask) { linkTask.binary.outputFile }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
NATIVE_TARGETS.forEach { targetName ->
|
||||
val target = targets.getByName(targetName) as KotlinNativeTarget
|
||||
target.binaries {
|
||||
sharedLib(listOf(NativeBuildType.DEBUG, NativeBuildType.RELEASE)) {
|
||||
baseName = project.name.toLowerCase().replace("-", "")
|
||||
}
|
||||
staticLib(listOf(NativeBuildType.DEBUG, NativeBuildType.RELEASE)) {
|
||||
baseName = project.name.toLowerCase().replace("-", "")
|
||||
}
|
||||
}
|
||||
if (!IDEA_ACTIVE && HOST_KIND == HostKind.WINDOWS && targetName == "mingwX64") {
|
||||
target.binaries.test(listOf(NativeBuildType.RELEASE)) {
|
||||
// add release test to run on CI
|
||||
project.afterEvaluate {
|
||||
// use linkReleaseTestMingwX64 for mingwX64Test to save memory
|
||||
tasks.getByName("mingwX64Test", KotlinNativeTest::class)
|
||||
.executable(linkTask) { linkTask.binary.outputFile }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jvmBaseMain.dependsOn(commonMain)
|
||||
jvmBaseTest.dependsOn(commonTest)
|
||||
|
||||
@@ -336,6 +373,11 @@ fun Project.disableCrossCompile() {
|
||||
|
||||
private fun disableTargetLink(project: Project, target: String) {
|
||||
project.tasks.getByName("linkDebugTest${target.titlecase()}").enabled = false
|
||||
project.tasks.findByName("linkReleaseTest${target.titlecase()}")?.enabled = false
|
||||
project.tasks.findByName("linkDebugShared${target.titlecase()}")?.enabled = false
|
||||
project.tasks.findByName("linkReleaseShared${target.titlecase()}")?.enabled = false
|
||||
project.tasks.findByName("linkDebugStatic${target.titlecase()}")?.enabled = false
|
||||
project.tasks.findByName("linkReleaseStatic${target.titlecase()}")?.enabled = false
|
||||
project.tasks.getByName("${target}Test").enabled = false
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import kotlin.contracts.contract
|
||||
import kotlin.jvm.JvmOverloads
|
||||
import kotlin.jvm.JvmStatic
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
import kotlin.native.CName
|
||||
|
||||
/**
|
||||
* 表示在本地构建的 [Announcement].
|
||||
@@ -94,6 +95,7 @@ public sealed interface OfflineAnnouncement : Announcement {
|
||||
* 依据 [from] 创建 [OfflineAnnouncement]. 若 [from] 类型为 [OfflineAnnouncement] 则直接返回 [from].
|
||||
* @since 2.7
|
||||
*/
|
||||
@CName("", "OfflineAnnouncement_new")
|
||||
public inline fun OfflineAnnouncement(from: Announcement): OfflineAnnouncement =
|
||||
OfflineAnnouncement.from(from)
|
||||
|
||||
@@ -103,6 +105,7 @@ public inline fun OfflineAnnouncement(from: Announcement): OfflineAnnouncement =
|
||||
* @param parameters 可选的附加参数
|
||||
* @since 2.7
|
||||
*/
|
||||
@CName("", "OfflineAnnouncement_new2")
|
||||
public inline fun OfflineAnnouncement(
|
||||
content: String,
|
||||
parameters: AnnouncementParameters = AnnouncementParameters.DEFAULT
|
||||
@@ -115,6 +118,7 @@ public inline fun OfflineAnnouncement(
|
||||
* @see AnnouncementParametersBuilder
|
||||
* @since 2.7
|
||||
*/
|
||||
@CName("", "OfflineAnnouncement_new3")
|
||||
public inline fun OfflineAnnouncement(
|
||||
content: String,
|
||||
parameters: AnnouncementParametersBuilder.() -> Unit
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
package net.mamoe.mirai.internal.utils
|
||||
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.native.CName
|
||||
|
||||
/**
|
||||
* 内部添加 [Marker] 支持, 并兼容旧 [MiraiLogger] API.
|
||||
@@ -42,6 +44,8 @@ internal val MiraiLogger.markerOrNull get() = (this as? MarkedMiraiLogger)?.mark
|
||||
*
|
||||
* Calling [MarkedMiraiLogger.subLogger] if possible, and creating [MiraiLoggerMarkedWrapper] otherwise.
|
||||
*/
|
||||
@JvmName("subLoggerImpl2")
|
||||
@CName("", "subLogger2")
|
||||
internal fun MiraiLogger.subLogger(name: String): MiraiLogger {
|
||||
return subLoggerImpl(this, name)
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.mamoe.mirai.utils.MiraiInternalApi
|
||||
import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
import kotlin.native.CName
|
||||
|
||||
|
||||
/**
|
||||
@@ -87,6 +88,7 @@ public data class At(
|
||||
* @see Member.at
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@CName("", "At_new")
|
||||
public inline fun At(user: UserOrBot): At = At(user.id)
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,7 @@ import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.jvm.JvmStatic
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
import kotlin.native.CName
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
@@ -231,6 +232,7 @@ public interface OfflineAudio : Audio {
|
||||
* @since 2.7
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@CName("", "OfflineAudio_new")
|
||||
public inline fun OfflineAudio(
|
||||
filename: String,
|
||||
fileMd5: ByteArray,
|
||||
@@ -244,6 +246,7 @@ public inline fun OfflineAudio(
|
||||
* @since 2.7
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@CName("", "OfflineAudio_new2")
|
||||
public inline fun OfflineAudio(
|
||||
onlineAudio: OnlineAudio
|
||||
): OfflineAudio = OfflineAudio.Factory.from(onlineAudio)
|
||||
|
||||
@@ -31,6 +31,7 @@ import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.jvm.JvmStatic
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
import kotlin.native.CName
|
||||
|
||||
/**
|
||||
* 文件消息.
|
||||
@@ -132,5 +133,6 @@ internal open class FallbackFileMessageSerializer constructor(serialName: String
|
||||
* @since 2.5
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@CName("", "FileMessage_new")
|
||||
public inline fun FileMessage(id: String, internalId: Int, name: String, size: Long): FileMessage =
|
||||
FileMessage.create(id, internalId, name, size)
|
||||
@@ -20,6 +20,7 @@ import net.mamoe.mirai.utils.MiraiInternalApi
|
||||
import net.mamoe.mirai.utils.safeCast
|
||||
import kotlin.jvm.JvmStatic
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
import kotlin.native.CName
|
||||
|
||||
/**
|
||||
* 闪照. 闪照的内容取决于 [image] 代表的图片.
|
||||
@@ -95,6 +96,7 @@ public data class FlashImage(
|
||||
* 将普通图片转换为闪照.
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@CName("", "FlashImage_new")
|
||||
public inline fun FlashImage(imageId: String): FlashImage = FlashImage.from(imageId)
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,6 +45,7 @@ import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.jvm.JvmStatic
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
import kotlin.native.CName
|
||||
|
||||
/**
|
||||
* 自定义表情 (收藏的表情) 和普通图片.
|
||||
@@ -400,6 +401,7 @@ public interface Image : Message, MessageContent, CodableMessage {
|
||||
* @see IMirai.createImage
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@CName("", "Image_new")
|
||||
public inline fun Image(imageId: String): Image = Builder.newBuilder(imageId).build()
|
||||
|
||||
/**
|
||||
@@ -409,6 +411,7 @@ public inline fun Image(imageId: String): Image = Builder.newBuilder(imageId).bu
|
||||
* @since 2.9.0
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@CName("", "Image_new2")
|
||||
public inline fun Image(imageId: String, builderAction: Builder.() -> Unit = {}): Image =
|
||||
Builder.newBuilder(imageId).apply(builderAction).build()
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.jvm.JvmStatic
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
import kotlin.native.CName
|
||||
|
||||
/**
|
||||
* mirai 尚未支持的消息类型.
|
||||
@@ -80,4 +81,5 @@ public interface UnsupportedMessage : MessageContent {
|
||||
* @see UnsupportedMessage.create
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@CName("", "UnsupportedMessage_new")
|
||||
public inline fun UnsupportedMessage(struct: ByteArray): UnsupportedMessage = UnsupportedMessage.create(struct)
|
||||
@@ -23,6 +23,7 @@ import net.mamoe.mirai.event.events.BotOfflineEvent
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.coroutineContext
|
||||
import kotlin.jvm.*
|
||||
import kotlin.native.CName
|
||||
import kotlin.time.Duration
|
||||
|
||||
/**
|
||||
@@ -483,6 +484,7 @@ public expect open class BotConfiguration() { // open for Java
|
||||
* @since 2.3
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@CName("", "BotConfiguration_new2")
|
||||
public inline fun BotConfiguration(block: BotConfiguration.() -> Unit): BotConfiguration {
|
||||
return BotConfiguration().apply(block)
|
||||
}
|
||||
|
||||
@@ -10,9 +10,8 @@
|
||||
@file:Suppress("UNUSED_VARIABLE")
|
||||
|
||||
import BinaryCompatibilityConfigurator.configureBinaryValidators
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractNativeLibrary
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
|
||||
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
@@ -117,15 +116,9 @@ kotlin {
|
||||
packageName("openssl")
|
||||
}
|
||||
|
||||
if (!IDEA_ACTIVE && HOST_KIND == HostKind.WINDOWS) {
|
||||
target.binaries.test(listOf(NativeBuildType.RELEASE)) {
|
||||
// add release test to run on CI
|
||||
afterEvaluate {
|
||||
// use linkReleaseTestMingwX64 for mingwX64Test to save memory
|
||||
tasks.getByName("mingwX64Test", KotlinNativeTest::class)
|
||||
.executable(linkTask) { linkTask.binary.outputFile }
|
||||
}
|
||||
}
|
||||
configure(target.binaries.filterIsInstance<AbstractNativeLibrary>()) {
|
||||
export(project(":mirai-core-api"))
|
||||
export(project(":mirai-core-utils"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,9 @@ import net.mamoe.mirai.internal.utils.MiraiCoreServices
|
||||
/**
|
||||
* 初始化 Mirai Native 平台. 必须先调用此 API, 其他 API 才能正常工作.
|
||||
*/
|
||||
@CName("mirai_init")
|
||||
public fun initMirai() {
|
||||
initRuntimeIfNeeded()
|
||||
_MiraiImpl_static_init()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user