Skip to content

Commit

Permalink
Support Android
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Dec 26, 2024
1 parent b1ba1c4 commit b465b79
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 273 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Anitorrent-native

TODO
A wrapper of the [](https://github.com/arvidn/libtorrent) library for Kotlin Multiplatform Mobile.

Supported targets:



# License

Expand Down
73 changes: 73 additions & 0 deletions anitorrent-native-desktop-jni/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

@file:OptIn(ExperimentalKotlinGradlePluginApi::class)

import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SonatypeHost
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi

plugins {
java
idea
alias(libs.plugins.vanniktech.mavenPublish)
}

java {
toolchain.languageVersion = JavaLanguageVersion.of(8)
}

sourceSets.main {
java.srcDirs(layout.buildDirectory.dir("generated-sources/swig"))
}

val copyGeneratedSwigJava = tasks.register("copyGeneratedSwigJava", Copy::class) {
dependsOn(projects.anitorrentNative.dependencyProject.tasks.named("generateSwigImpl"))
from(projects.anitorrentNative.dependencyProject.projectDir.resolve("gen/java"))
into(layout.buildDirectory.dir("generated-sources/swig"))
}

tasks.compileJava {
dependsOn(copyGeneratedSwigJava)
}

mavenPublishing {
configure(JavaLibrary(JavadocJar.Empty(), true))
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
signAllPublications()

pom {
name = "Anitorrent Native"
description = "Anitorrent Native"
url = "https://github.com/open-ani/anitorrent"

licenses {
license {
name = "GNU General Public License, Version 3"
url = "https://github.com/open-ani/anitorrent/blob/main/LICENSE"
distribution = "https://www.gnu.org/licenses/gpl-3.0.txt"
}
}

developers {
developer {
id = "openani"
name = "OpenAni and contributors"
email = "[email protected]"
}
}

scm {
connection = "scm:git:https://github.com/open-ani/anitorrent.git"
developerConnection = "scm:git:[email protected]:open-ani/anitorrent.git"
url = "https://github.com/open-ani/anitorrent"
}
}
}
49 changes: 38 additions & 11 deletions anitorrent-native/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,35 @@ val archs = buildList {
}

kotlin {
jvmToolchain(8)
jvm("desktop")
androidTarget()

applyDefaultHierarchyTemplate {
group("jvm") {
withJvm()
withAndroidTarget()
common {
group("jvm") {
withJvm()
withAndroidTarget()
}
}
}

sourceSets {
// androidMain {
// kotlin.srcDirs(listOf("gen/java"))
// }
getByName("jvmMain") {
dependencies {
api(projects.anitorrentNativeDesktopJni)
}
}
}
}

//kotlin.sourceSets.getByName("jvmMain") {
// java.setSrcDirs(listOf("gen/java"))
//}

android {
namespace = "org.openani.anitorrent.natives"
compileSdk = getIntProperty("android.compile.sdk")
Expand Down Expand Up @@ -117,10 +135,6 @@ android {
}
}

//sourceSets.getByName("jvmMain") {
// java.setSrcDirs(listOf("gen/java"))
//}

/// ANITORRENT

val anitorrentRootDir = projectDir
Expand All @@ -129,7 +143,7 @@ val anitorrentBuildDir = anitorrentRootDir.resolve("build-ci")
val generateSwigImpl = tasks.register("generateSwigImpl", Exec::class.java) {
group = "anitorrent"

val swig = System.getenv("SWIG") ?: "swig"
val swig = getLocalProperty("SWIG") ?: "swig"
// swig -java -c++ \
// -o ./src/anitorrent_wrap.cpp \
// -outdir ./java/me/him188/ani/app/torrent/anitorrent/binding \
Expand All @@ -143,13 +157,13 @@ val generateSwigImpl = tasks.register("generateSwigImpl", Exec::class.java) {
outputs.dir(anitorrentRootDir.resolve("gen/java"))

val cppDir = anitorrentRootDir.resolve("gen/cpp")
val javaDir = anitorrentRootDir.resolve("gen/java/me/him188/ani/app/torrent/anitorrent/binding")
val javaDir = anitorrentRootDir.resolve("gen/org/openani/anitorrent/binding/")
commandLine = listOf(
swig,
"-java", "-c++", "-directors", "-cppext", "cpp", "-addextern",
"-o", cppDir.resolve("anitorrent_wrap.cpp").absolutePath,
"-outdir", javaDir.absolutePath,
"-package", "me.him188.ani.app.torrent.anitorrent.binding",
"-package", "org.openani.anitorrent.binding",
swigI.absolutePath,
)
doFirst {
Expand Down Expand Up @@ -499,11 +513,24 @@ mavenPublishing {
}
}

tasks.matching { it.name.startsWith("publishDesktopPublicationTo") }.all {
dependsOn(copyNativeJarForCurrentPlatform)
}

tasks.getByName("signDesktopPublication") {
dependsOn(copyNativeJarForCurrentPlatform)
}

afterEvaluate {
publishing {
publications {
getByName("desktop", MavenPublication::class) {
supportedOsTriples.forEach { platform ->
val platforms = if (getLocalProperty("ani.publishing.onlyHostOS") == "true") {
listOf("macos-aarch64")
} else {
supportedOsTriples
}
platforms.forEach { platform ->
artifact(nativeJarsDir.map { it.file("${project.name}-${project.version}-$platform.jar") }) {
classifier = platform
}
Expand Down
Loading

0 comments on commit b465b79

Please sign in to comment.