[core] Build libc++ ourselves (#406)
This commit is contained in:
parent
40c43fea56
commit
e5d61affdd
|
|
@ -4,3 +4,9 @@
|
||||||
[submodule "core/src/main/cpp/external/DexBuilder"]
|
[submodule "core/src/main/cpp/external/DexBuilder"]
|
||||||
path = core/src/main/cpp/external/DexBuilder
|
path = core/src/main/cpp/external/DexBuilder
|
||||||
url = https://github.com/LSPosed/DexBuilder.git
|
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
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
import org.apache.tools.ant.filters.FixCrLfFilter
|
import org.apache.tools.ant.filters.FixCrLfFilter
|
||||||
import org.gradle.internal.os.OperatingSystem
|
import org.gradle.internal.os.OperatingSystem
|
||||||
import org.jetbrains.kotlin.daemon.common.toHexString
|
import org.jetbrains.kotlin.daemon.common.toHexString
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
|
|
||||||
|
|
@ -64,7 +65,7 @@ val verName: String by rootProject.extra
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("dev.rikka.ndk:riru:${moduleMinRiruVersionName}")
|
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")
|
implementation("com.android.tools.build:apksig:4.1.3")
|
||||||
compileOnly(project(":hiddenapi-stubs"))
|
compileOnly(project(":hiddenapi-stubs"))
|
||||||
compileOnly("androidx.annotation:annotation:1.2.0")
|
compileOnly("androidx.annotation:annotation:1.2.0")
|
||||||
|
|
@ -93,10 +94,13 @@ android {
|
||||||
abiFilters("arm64-v8a", "armeabi-v7a", "x86", "x86_64")
|
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")
|
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")
|
cFlags("-std=c11 -ffixed-x18 -Qunused-arguments -fno-rtti -fno-exceptions -fomit-frame-pointer -fpie -fPIC")
|
||||||
arguments("-DRIRU_MODULE_API_VERSION=$moduleMaxRiruApiVersion",
|
arguments(
|
||||||
|
"-DRIRU_MODULE_API_VERSION=$moduleMaxRiruApiVersion",
|
||||||
"-DRIRU_MODULE_VERSION=$verCode",
|
"-DRIRU_MODULE_VERSION=$verCode",
|
||||||
"-DRIRU_MODULE_VERSION_NAME:STRING=\"$verName\"",
|
"-DRIRU_MODULE_VERSION_NAME:STRING=\"$verName\"",
|
||||||
"-DMODULE_NAME:STRING=riru_$riruModuleId")
|
"-DMODULE_NAME:STRING=riru_$riruModuleId",
|
||||||
|
"-DANDROID_STL=none"
|
||||||
|
)
|
||||||
targets("lspd")
|
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 {
|
afterEvaluate {
|
||||||
|
|
||||||
android.applicationVariants.forEach { variant ->
|
android.applicationVariants.forEach { variant ->
|
||||||
|
|
@ -162,12 +201,17 @@ afterEvaluate {
|
||||||
from("$projectDir/tpl/module.prop.tpl")
|
from("$projectDir/tpl/module.prop.tpl")
|
||||||
into(zipPathMagiskReleasePath)
|
into(zipPathMagiskReleasePath)
|
||||||
rename("module.prop.tpl", "module.prop")
|
rename("module.prop.tpl", "module.prop")
|
||||||
expand("moduleId" to moduleId,
|
expand(
|
||||||
|
"moduleId" to moduleId,
|
||||||
"versionName" to verName,
|
"versionName" to verName,
|
||||||
"versionCode" to verCode,
|
"versionCode" to verCode,
|
||||||
"authorList" to authors,
|
"authorList" to authors,
|
||||||
"minRiruVersionName" to moduleMinRiruVersionName)
|
"minRiruVersionName" to moduleMinRiruVersionName
|
||||||
filter(mapOf("eol" to FixCrLfFilter.CrLf.newInstance("lf")), FixCrLfFilter::class.java)
|
)
|
||||||
|
filter(
|
||||||
|
mapOf("eol" to FixCrLfFilter.CrLf.newInstance("lf")),
|
||||||
|
FixCrLfFilter::class.java
|
||||||
|
)
|
||||||
}
|
}
|
||||||
copy {
|
copy {
|
||||||
from("${rootProject.projectDir}/README.md")
|
from("${rootProject.projectDir}/README.md")
|
||||||
|
|
@ -196,11 +240,23 @@ afterEvaluate {
|
||||||
include("riru.sh")
|
include("riru.sh")
|
||||||
filter { line ->
|
filter { line ->
|
||||||
line.replace("%%%RIRU_MODULE_ID%%%", riruModuleId)
|
line.replace("%%%RIRU_MODULE_ID%%%", riruModuleId)
|
||||||
.replace("%%%RIRU_MODULE_API_VERSION%%%", moduleMaxRiruApiVersion.toString())
|
.replace(
|
||||||
.replace("%%%RIRU_MODULE_MIN_API_VERSION%%%", moduleMinRiruApiVersion.toString())
|
"%%%RIRU_MODULE_API_VERSION%%%",
|
||||||
.replace("%%%RIRU_MODULE_MIN_RIRU_VERSION_NAME%%%", moduleMinRiruVersionName)
|
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 {
|
copy {
|
||||||
include("lspd")
|
include("lspd")
|
||||||
|
|
@ -252,9 +308,11 @@ afterEvaluate {
|
||||||
task("push${variantCapped}", Exec::class) {
|
task("push${variantCapped}", Exec::class) {
|
||||||
dependsOn(zipTask)
|
dependsOn(zipTask)
|
||||||
workingDir("${projectDir}/release")
|
workingDir("${projectDir}/release")
|
||||||
val commands = arrayOf(android.adbExecutable, "push",
|
val commands = arrayOf(
|
||||||
|
android.adbExecutable, "push",
|
||||||
zipFileName,
|
zipFileName,
|
||||||
"/data/local/tmp/")
|
"/data/local/tmp/"
|
||||||
|
)
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
commandLine("cmd", "/c", commands.joinToString(" "))
|
commandLine("cmd", "/c", commands.joinToString(" "))
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -264,8 +322,10 @@ afterEvaluate {
|
||||||
task("flash${variantCapped}", Exec::class) {
|
task("flash${variantCapped}", Exec::class) {
|
||||||
dependsOn(tasks.getByPath("push${variantCapped}"))
|
dependsOn(tasks.getByPath("push${variantCapped}"))
|
||||||
workingDir("${projectDir}/release")
|
workingDir("${projectDir}/release")
|
||||||
val commands = arrayOf(android.adbExecutable, "shell", "su", "-c",
|
val commands = arrayOf(
|
||||||
"magisk --install-module /data/local/tmp/${zipFileName}")
|
android.adbExecutable, "shell", "su", "-c",
|
||||||
|
"magisk --install-module /data/local/tmp/${zipFileName}"
|
||||||
|
)
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
commandLine("cmd", "/c", commands.joinToString(" "))
|
commandLine("cmd", "/c", commands.joinToString(" "))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -37,5 +37,7 @@ add_definitions(-DRIRU_MODULE_VERSION=${RIRU_MODULE_VERSION})
|
||||||
add_definitions(-DRIRU_MODULE_VERSION_NAME=${RIRU_MODULE_VERSION_NAME})
|
add_definitions(-DRIRU_MODULE_VERSION_NAME=${RIRU_MODULE_VERSION_NAME})
|
||||||
add_definitions(-DMODULE_NAME=${MODULE_NAME})
|
add_definitions(-DMODULE_NAME=${MODULE_NAME})
|
||||||
|
|
||||||
|
include_directories(external/libcxx/include)
|
||||||
|
|
||||||
add_subdirectory(main)
|
add_subdirectory(main)
|
||||||
add_subdirectory(external)
|
add_subdirectory(external)
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,19 @@ add_subdirectory(yahfa)
|
||||||
|
|
||||||
add_subdirectory(DexBuilder)
|
add_subdirectory(DexBuilder)
|
||||||
target_include_directories(dex_builder PUBLIC 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)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 1e3acde39590f365c1fe489ecbd43f7ee8a5e20d
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit cca5298bc3fbb19b607008925b10acd0ee06e03d
|
||||||
|
|
@ -25,9 +25,10 @@ aux_source_directory(src/jni SRC_JNI_LIST)
|
||||||
include_directories(include src)
|
include_directories(include src)
|
||||||
add_executable(lspd ${SRC_LIST} ${SRC_JNI_LIST})
|
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")
|
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--dynamic-list=${CMAKE_SOURCE_DIR}/dynamic_list")
|
||||||
|
|
||||||
find_package(riru REQUIRED CONFIG)
|
find_package(riru REQUIRED CONFIG)
|
||||||
find_package(dobby REQUIRED CONFIG)
|
|
||||||
find_library(log-lib log)
|
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})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue