Skip to content

Commit

Permalink
Use libcxx prefab (LSPosed#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvb2060 authored Apr 23, 2021
1 parent 02b3bbf commit 12c2876
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 45 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
[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/LSPosed/Dobby.git
37 changes: 1 addition & 36 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.apache.tools.ant.filters.FixCrLfFilter
import org.gradle.internal.os.OperatingSystem
import org.jetbrains.kotlin.daemon.common.toHexString
import java.io.PrintStream
import java.nio.file.Paths
import java.security.MessageDigest

plugins {
Expand Down Expand Up @@ -65,6 +64,7 @@ val verName: String by rootProject.extra

dependencies {
implementation("dev.rikka.ndk:riru:${moduleMinRiruVersionName}")
implementation("dev.rikka.ndk.thirdparty:cxx:1.1.0")
implementation("com.android.tools.build:apksig:4.1.3")
implementation("org.apache.commons:commons-lang3:3.12.0")
implementation("de.upb.cs.swt:axml:2.1.1")
Expand Down Expand Up @@ -186,41 +186,6 @@ android {
}
}

fun findInPath(executable: String): String? {
val pathEnv = System.getenv("PATH")
return pathEnv.split(File.pathSeparator).map { folder ->
Paths.get("${folder}${File.separator}${executable}${if (isWindows) ".exe" else ""}")
.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")
} ?: 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")

android.applicationVariants.all {
val variantCapped = name.capitalize()
val variantLowered = name.toLowerCase()
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ if (CCACHE)
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
endif ()

include_directories(external/libcxx/include)
find_package(cxx REQUIRED CONFIG)
link_libraries(cxx::cxx)

add_subdirectory(main)
add_subdirectory(external)
3 changes: 0 additions & 3 deletions core/src/main/cpp/external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@ if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
endif (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
add_subdirectory(Dobby)
target_include_directories(dobby PUBLIC Dobby/include)

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 change: 0 additions & 1 deletion core/src/main/cpp/external/libcxx
Submodule libcxx deleted from f61fce
2 changes: 1 addition & 1 deletion core/src/main/cpp/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ add_library(lspd SHARED ${SRC_LIST} ${SRC_JNI_LIST} ${CMAKE_CURRENT_BINARY_DIR}/

find_package(riru REQUIRED CONFIG)
find_library(log-lib log)
target_link_libraries(lspd yahfa riru::riru android dobby dex_builder libcxx ${log-lib})
target_link_libraries(lspd yahfa riru::riru android dobby dex_builder ${log-lib})

add_custom_command(TARGET lspd POST_BUILD
COMMAND ${CMAKE_STRIP} --remove-section=.comment -g "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/liblspd.so")

0 comments on commit 12c2876

Please sign in to comment.