[core] Build libc++ ourselves (#406)

This commit is contained in:
LoveSy 2021-03-26 15:11:35 +08:00 committed by GitHub
parent 40c43fea56
commit e5d61affdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 109 additions and 22 deletions

6
.gitmodules vendored
View File

@ -4,3 +4,9 @@
[submodule "core/src/main/cpp/external/DexBuilder"]
path = core/src/main/cpp/external/DexBuilder
url = https://github.com/LSPosed/DexBuilder.git
[submodule "core/src/main/cpp/external/libcxx"]
path = core/src/main/cpp/external/libcxx
url = https://github.com/topjohnwu/libcxx.git
[submodule "core/src/main/cpp/external/Dobby"]
path = core/src/main/cpp/external/Dobby
url = https://github.com/jmpews/Dobby.git

View File

@ -20,6 +20,7 @@
import org.apache.tools.ant.filters.FixCrLfFilter
import org.gradle.internal.os.OperatingSystem
import org.jetbrains.kotlin.daemon.common.toHexString
import java.nio.file.Paths
import java.security.MessageDigest
@ -64,7 +65,7 @@ val verName: String by rootProject.extra
dependencies {
implementation("dev.rikka.ndk:riru:${moduleMinRiruVersionName}")
implementation(files("libs/dobby_prefab.aar"))
// implementation(files("libs/dobby_prefab.aar"))
implementation("com.android.tools.build:apksig:4.1.3")
compileOnly(project(":hiddenapi-stubs"))
compileOnly("androidx.annotation:annotation:1.2.0")
@ -93,10 +94,13 @@ android {
abiFilters("arm64-v8a", "armeabi-v7a", "x86", "x86_64")
cppFlags("-std=c++20 -ffixed-x18 -Qunused-arguments -fno-rtti -fno-exceptions -fomit-frame-pointer -fpie -fPIC")
cFlags("-std=c11 -ffixed-x18 -Qunused-arguments -fno-rtti -fno-exceptions -fomit-frame-pointer -fpie -fPIC")
arguments("-DRIRU_MODULE_API_VERSION=$moduleMaxRiruApiVersion",
"-DRIRU_MODULE_VERSION=$verCode",
"-DRIRU_MODULE_VERSION_NAME:STRING=\"$verName\"",
"-DMODULE_NAME:STRING=riru_$riruModuleId")
arguments(
"-DRIRU_MODULE_API_VERSION=$moduleMaxRiruApiVersion",
"-DRIRU_MODULE_VERSION=$verCode",
"-DRIRU_MODULE_VERSION_NAME:STRING=\"$verName\"",
"-DMODULE_NAME:STRING=riru_$riruModuleId",
"-DANDROID_STL=none"
)
targets("lspd")
}
}
@ -145,6 +149,41 @@ android {
}
}
fun findInPath(executable: String): String? {
val pathEnv = System.getenv("PATH")
return pathEnv.split(File.pathSeparator).map { folder ->
Paths.get("${folder}${File.separator}${executable}").toFile()
}.firstOrNull { path ->
path.exists()
}?.absolutePath
}
task("buildLibcxx", Exec::class) {
val ndkDir = android.ndkDirectory
executable = "$ndkDir/${if (isWindows) "ndk-build.cmd" else "ndk-build"}"
workingDir = projectDir
findInPath("ccache")?.let {
println("using ccache $it")
environment("NDK_CCACHE", it)
environment("USE_CCACHE", "1")
environment("CCACHE_COMPILERCHECK", "content")
} ?: run {
println("not using ccache")
}
setArgs(
arrayListOf(
"NDK_PROJECT_PATH=build/intermediates/ndk",
"APP_BUILD_SCRIPT=$projectDir/src/main/cpp/external/libcxx/Android.mk",
"APP_CPPFLAGS=-std=c++20",
"APP_STL=none",
"-j${Runtime.getRuntime().availableProcessors()}"
)
)
}
tasks.getByName("preBuild").dependsOn("buildLibcxx")
afterEvaluate {
android.applicationVariants.forEach { variant ->
@ -162,12 +201,17 @@ afterEvaluate {
from("$projectDir/tpl/module.prop.tpl")
into(zipPathMagiskReleasePath)
rename("module.prop.tpl", "module.prop")
expand("moduleId" to moduleId,
"versionName" to verName,
"versionCode" to verCode,
"authorList" to authors,
"minRiruVersionName" to moduleMinRiruVersionName)
filter(mapOf("eol" to FixCrLfFilter.CrLf.newInstance("lf")), FixCrLfFilter::class.java)
expand(
"moduleId" to moduleId,
"versionName" to verName,
"versionCode" to verCode,
"authorList" to authors,
"minRiruVersionName" to moduleMinRiruVersionName
)
filter(
mapOf("eol" to FixCrLfFilter.CrLf.newInstance("lf")),
FixCrLfFilter::class.java
)
}
copy {
from("${rootProject.projectDir}/README.md")
@ -196,11 +240,23 @@ afterEvaluate {
include("riru.sh")
filter { line ->
line.replace("%%%RIRU_MODULE_ID%%%", riruModuleId)
.replace("%%%RIRU_MODULE_API_VERSION%%%", moduleMaxRiruApiVersion.toString())
.replace("%%%RIRU_MODULE_MIN_API_VERSION%%%", moduleMinRiruApiVersion.toString())
.replace("%%%RIRU_MODULE_MIN_RIRU_VERSION_NAME%%%", moduleMinRiruVersionName)
.replace(
"%%%RIRU_MODULE_API_VERSION%%%",
moduleMaxRiruApiVersion.toString()
)
.replace(
"%%%RIRU_MODULE_MIN_API_VERSION%%%",
moduleMinRiruApiVersion.toString()
)
.replace(
"%%%RIRU_MODULE_MIN_RIRU_VERSION_NAME%%%",
moduleMinRiruVersionName
)
}
filter(mapOf("eol" to FixCrLfFilter.CrLf.newInstance("lf")), FixCrLfFilter::class.java)
filter(
mapOf("eol" to FixCrLfFilter.CrLf.newInstance("lf")),
FixCrLfFilter::class.java
)
}
copy {
include("lspd")
@ -252,9 +308,11 @@ afterEvaluate {
task("push${variantCapped}", Exec::class) {
dependsOn(zipTask)
workingDir("${projectDir}/release")
val commands = arrayOf(android.adbExecutable, "push",
zipFileName,
"/data/local/tmp/")
val commands = arrayOf(
android.adbExecutable, "push",
zipFileName,
"/data/local/tmp/"
)
if (isWindows) {
commandLine("cmd", "/c", commands.joinToString(" "))
} else {
@ -264,8 +322,10 @@ afterEvaluate {
task("flash${variantCapped}", Exec::class) {
dependsOn(tasks.getByPath("push${variantCapped}"))
workingDir("${projectDir}/release")
val commands = arrayOf(android.adbExecutable, "shell", "su", "-c",
"magisk --install-module /data/local/tmp/${zipFileName}")
val commands = arrayOf(
android.adbExecutable, "shell", "su", "-c",
"magisk --install-module /data/local/tmp/${zipFileName}"
)
if (isWindows) {
commandLine("cmd", "/c", commands.joinToString(" "))
} else {

Binary file not shown.

View File

@ -37,5 +37,7 @@ add_definitions(-DRIRU_MODULE_VERSION=${RIRU_MODULE_VERSION})
add_definitions(-DRIRU_MODULE_VERSION_NAME=${RIRU_MODULE_VERSION_NAME})
add_definitions(-DMODULE_NAME=${MODULE_NAME})
include_directories(external/libcxx/include)
add_subdirectory(main)
add_subdirectory(external)

View File

@ -4,3 +4,19 @@ add_subdirectory(yahfa)
add_subdirectory(DexBuilder)
target_include_directories(dex_builder PUBLIC DexBuilder)
macro(SET_OPTION option value)
set(${option} ${value} CACHE INTERNAL "" FORCE)
endmacro()
SET_OPTION(DOBBY_GENERATE_SHARED OFF)
SET_OPTION(Plugin.Android.BionicLinkerRestriction ON)
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
SET_OPTION(DOBBY_DEBUG OFF)
endif (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
add_subdirectory(Dobby)
target_include_directories(dobby PUBLIC Dobby/include)
target_include_directories(dobby PUBLIC Dobby/builtin-plugin/BionicLinkerRestriction)
add_library(libcxx STATIC IMPORTED GLOBAL)
set_property(TARGET libcxx PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../../../../build/intermediates/ndk/obj/local/${CMAKE_ANDROID_ARCH_ABI}/libcxx.a)

1
core/src/main/cpp/external/Dobby vendored Submodule

@ -0,0 +1 @@
Subproject commit 1e3acde39590f365c1fe489ecbd43f7ee8a5e20d

1
core/src/main/cpp/external/libcxx vendored Submodule

@ -0,0 +1 @@
Subproject commit cca5298bc3fbb19b607008925b10acd0ee06e03d

View File

@ -25,9 +25,10 @@ aux_source_directory(src/jni SRC_JNI_LIST)
include_directories(include src)
add_executable(lspd ${SRC_LIST} ${SRC_JNI_LIST})
set(ENV{CCACHE_COMPILERCHECK} "content")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--dynamic-list=${CMAKE_SOURCE_DIR}/dynamic_list")
find_package(riru REQUIRED CONFIG)
find_package(dobby REQUIRED CONFIG)
find_library(log-lib log)
target_link_libraries(lspd yahfa riru::riru android dobby::dobby dex_builder ${log-lib})
target_link_libraries(lspd yahfa riru::riru android dobby dex_builder libcxx ${log-lib})