2020-06-25 04:14:31 +00:00
|
|
|
import com.android.build.gradle.internal.tasks.factory.dependsOn
|
|
|
|
|
|
|
|
plugins {
|
|
|
|
id("com.android.library")
|
|
|
|
id("org.mozilla.rust-android-gradle.rust-android")
|
|
|
|
}
|
|
|
|
|
2021-02-28 13:01:58 +00:00
|
|
|
var targetAbi = ""
|
|
|
|
if (gradle.startParameter.taskNames.isNotEmpty()) {
|
|
|
|
if (gradle.startParameter.taskNames.size == 1) {
|
|
|
|
val targetTask = gradle.startParameter.taskNames[0].toLowerCase()
|
|
|
|
if (targetTask.contains("arm64")) {
|
|
|
|
targetAbi = "arm64"
|
|
|
|
} else if (targetTask.contains("arm")) {
|
|
|
|
targetAbi = "arm"
|
|
|
|
}
|
|
|
|
}
|
2021-02-28 07:08:33 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 04:14:31 +00:00
|
|
|
android {
|
|
|
|
|
2021-02-18 02:32:07 +00:00
|
|
|
ndkVersion = rootProject.extra.get("ndkVersion").toString()
|
2020-06-25 04:14:31 +00:00
|
|
|
|
2021-11-15 18:04:57 +00:00
|
|
|
compileSdk = 31
|
2020-06-25 04:14:31 +00:00
|
|
|
defaultConfig {
|
2021-11-15 18:04:57 +00:00
|
|
|
minSdk = 23
|
|
|
|
targetSdk = 31
|
2020-06-25 04:14:31 +00:00
|
|
|
}
|
2021-11-15 18:04:57 +00:00
|
|
|
buildToolsVersion = "31.0.0"
|
2022-11-01 09:51:10 +00:00
|
|
|
namespace = "io.nekohasekai.ss_rust"
|
2020-06-25 04:14:31 +00:00
|
|
|
|
2021-03-31 19:29:44 +00:00
|
|
|
if (targetAbi.isNotBlank()) splits.abi {
|
|
|
|
reset()
|
|
|
|
include(* when (targetAbi) {
|
|
|
|
"arm" -> arrayOf("armeabi-v7a")
|
|
|
|
"arm64" -> arrayOf("arm64-v8a")
|
2021-02-28 13:01:58 +00:00
|
|
|
else -> arrayOf("x86", "x86_64")
|
|
|
|
})
|
2021-02-28 07:08:33 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 04:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cargo {
|
|
|
|
module = "src/main/rust/shadowsocks-rust"
|
|
|
|
libname = "ss-local"
|
2021-02-28 13:01:58 +00:00
|
|
|
targets = when {
|
|
|
|
targetAbi.isBlank() -> listOf("arm", "arm64", "x86", "x86_64")
|
|
|
|
targetAbi == "arm" -> listOf("arm")
|
|
|
|
targetAbi == "arm64" -> listOf("arm64")
|
|
|
|
else -> listOf("arm", "arm64")
|
2021-02-28 07:08:33 +00:00
|
|
|
}
|
2020-06-25 04:14:31 +00:00
|
|
|
profile = findProperty("CARGO_PROFILE")?.toString() ?: "release"
|
|
|
|
extraCargoBuildArguments = listOf("--bin", "sslocal")
|
|
|
|
featureSpec.noDefaultBut(arrayOf(
|
2021-01-12 03:13:37 +00:00
|
|
|
"stream-cipher",
|
|
|
|
"logging",
|
2020-12-30 03:43:34 +00:00
|
|
|
"local-flow-stat",
|
|
|
|
"local-dns"))
|
2020-06-25 04:14:31 +00:00
|
|
|
exec = { spec, toolchain ->
|
|
|
|
spec.environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY", "$projectDir/$module/../linker-wrapper.py")
|
|
|
|
spec.environment("RUST_ANDROID_GRADLE_TARGET", "target/${toolchain.target}/$profile/lib$libname.so")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.whenTaskAdded {
|
|
|
|
when (name) {
|
|
|
|
"mergeDebugJniLibFolders", "mergeReleaseJniLibFolders" -> dependsOn("cargoBuild")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register<Exec>("cargoClean") {
|
|
|
|
executable("cargo") // cargo.cargoCommand
|
|
|
|
args("clean")
|
|
|
|
workingDir("$projectDir/${cargo.module}")
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.clean.dependsOn("cargoClean")
|