Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYi0526 authored and LiuYi0526 committed Feb 17, 2024
1 parent bce98cd commit 3d17951
Show file tree
Hide file tree
Showing 38 changed files with 1,277 additions and 13,108 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@
[submodule "ssr-libev/src/main/jni/re2"]
path = ssr-libev/src/main/jni/re2
url = https://github.com/google/re2.git
[submodule "v2ray"]
path = v2ray
url = https://github.com/nekohasekai/AndroidLibV2rayLite
1 change: 1 addition & 0 deletions ss-rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
77 changes: 77 additions & 0 deletions ss-rust/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import com.android.build.gradle.internal.tasks.factory.dependsOn

plugins {
id("com.android.library")
id("org.mozilla.rust-android-gradle.rust-android")
}

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"
}
}
}

android {

ndkVersion = rootProject.extra.get("ndkVersion").toString()

compileSdk = 31
defaultConfig {
minSdk = 23
targetSdk = 31
}
buildToolsVersion = "31.0.0"
namespace = "io.nekohasekai.ss_rust"

if (targetAbi.isNotBlank()) splits.abi {
reset()
include(* when (targetAbi) {
"arm" -> arrayOf("armeabi-v7a")
"arm64" -> arrayOf("arm64-v8a")
else -> arrayOf("x86", "x86_64")
})
}

}

cargo {
module = "src/main/rust/shadowsocks-rust"
libname = "ss-local"
targets = when {
targetAbi.isBlank() -> listOf("arm", "arm64", "x86", "x86_64")
targetAbi == "arm" -> listOf("arm")
targetAbi == "arm64" -> listOf("arm64")
else -> listOf("arm", "arm64")
}
profile = findProperty("CARGO_PROFILE")?.toString() ?: "release"
extraCargoBuildArguments = listOf("--bin", "sslocal")
featureSpec.noDefaultBut(arrayOf(
"stream-cipher",
"logging",
"local-flow-stat",
"local-dns"))
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")
3 changes: 3 additions & 0 deletions ss-rust/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
18 changes: 18 additions & 0 deletions ss-rust/src/main/rust/linker-wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import absolute_import, print_function, unicode_literals

import os
import pipes
import shutil
import subprocess
import sys

args = [os.environ['RUST_ANDROID_GRADLE_CC'], os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG']] + sys.argv[1:]

# This only appears when the subprocess call fails, but it's helpful then.
printable_cmd = ' '.join(pipes.quote(arg) for arg in args)
print(printable_cmd)

code = subprocess.call(args)
if code == 0:
shutil.copyfile(sys.argv[sys.argv.index('-o') + 1], os.environ['RUST_ANDROID_GRADLE_TARGET'])
sys.exit(code)
1 change: 1 addition & 0 deletions ssr-libev/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
55 changes: 55 additions & 0 deletions ssr-libev/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
plugins {
id 'com.android.library'
}

def targetAbi = ""
if (!gradle.startParameter.taskNames.isEmpty()) {
if (gradle.startParameter.taskNames.size == 1) {
def targetTask = gradle.startParameter.taskNames[0].toLowerCase()
if (targetTask.contains("arm64")) {
targetAbi = "arm64"
} else if (targetTask.contains("arm")) {
targetAbi = "arm"
}
} else {
targetAbi = "~"
}
}


android {
compileSdkVersion 30
buildToolsVersion '30.0.3'
ndkVersion rootProject.ext.ndkVersion

defaultConfig {
minSdkVersion 19
targetSdkVersion 30

externalNativeBuild {
ndkBuild {
if (!targetAbi.isBlank()) {
if (targetAbi == "arm64") {
abiFilters 'arm64-v8a'
} else if (targetAbi == "arm") {
abiFilters 'armeabi-v7a'
} else {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
} else {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}

arguments "NDK_APPLICATION_MK:=src/main/jni/Application.mk", "APP_PLATFORM:=android-21", "--jobs=${Runtime.getRuntime().availableProcessors()}"
}
}
}

externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
namespace 'io.nekohasekai.ssr_libev'

}
3 changes: 3 additions & 0 deletions ssr-libev/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Loading

0 comments on commit 3d17951

Please sign in to comment.