You've already forked ReZygisk
mirror of
https://github.com/PerformanC/ReZygisk.git
synced 2025-09-06 06:37:01 +00:00
fix: zygiskd c99 building process
This commit fixes building process of new zygiskd.
This commit is contained in:
127
zygiskd/build.gradle.kts
Normal file
127
zygiskd/build.gradle.kts
Normal file
@@ -0,0 +1,127 @@
|
||||
import java.nio.file.Paths
|
||||
import org.gradle.internal.os.OperatingSystem
|
||||
|
||||
fun getLatestNDKPath(): String {
|
||||
val android_home = System.getenv("ANDROID_HOME")
|
||||
if (android_home == null) {
|
||||
throw Exception("ANDROID_HOME not set")
|
||||
}
|
||||
|
||||
val ndkPath = android_home + "/ndk"
|
||||
|
||||
val ndkDir = Paths.get(ndkPath)
|
||||
if (!ndkDir.toFile().exists()) {
|
||||
throw Exception("NDK not found at $ndkPath")
|
||||
}
|
||||
|
||||
val ndkVersion = ndkDir.toFile().listFiles().filter { it.isDirectory }.map { it.name }.sorted().last()
|
||||
return ndkPath + "/" + ndkVersion
|
||||
}
|
||||
|
||||
val minAPatchVersion: Int by rootProject.extra
|
||||
val minKsuVersion: Int by rootProject.extra
|
||||
val maxKsuVersion: Int by rootProject.extra
|
||||
val minMagiskVersion: Int by rootProject.extra
|
||||
val verCode: Int by rootProject.extra
|
||||
val verName: String by rootProject.extra
|
||||
val commitHash: String by rootProject.extra
|
||||
|
||||
val CFlagsRelease = arrayOf(
|
||||
"-D_GNU_SOURCE", "-std=c99", "-Wpedantic", "-Wall", "-Wextra", "-Werror",
|
||||
"-Wformat", "-Wuninitialized", "-Wshadow", "-Wno-zero-length-array",
|
||||
"-Wno-fixed-enum-extension", "-Iroot_impl", "-llog"
|
||||
)
|
||||
|
||||
val CFlagsDebug = arrayOf(
|
||||
"-D_GNU_SOURCE", "-std=c99", "-Wpedantic", "-Wall", "-Wextra", "-Werror",
|
||||
"-Wformat", "-Wuninitialized", "-Wshadow", "-Wno-zero-length-array",
|
||||
"-Wno-fixed-enum-extension", "-Iroot_impl", "-llog", "-g"
|
||||
)
|
||||
|
||||
val Files = arrayOf(
|
||||
"root_impl/common.c",
|
||||
"root_impl/kernelsu.c",
|
||||
"companion.c",
|
||||
"dl.c",
|
||||
"main.c",
|
||||
"utils.c",
|
||||
"zygiskd.c"
|
||||
)
|
||||
|
||||
task<Task>("buildAndStrip") {
|
||||
group = "build"
|
||||
description = "Build the native library and strip the debug symbols."
|
||||
|
||||
val isDebug = gradle.startParameter.taskNames.any { it.lowercase().contains("debug") }
|
||||
doLast {
|
||||
val ndkPath = getLatestNDKPath()
|
||||
|
||||
val aarch64Compiler = Paths.get(ndkPath, "toolchains", "llvm", "prebuilt", "linux-x86_64", "bin", "aarch64-linux-android34-clang").toString()
|
||||
val armv7aCompiler = Paths.get(ndkPath, "toolchains", "llvm", "prebuilt", "linux-x86_64", "bin", "armv7a-linux-androideabi34-clang").toString()
|
||||
|
||||
if (!Paths.get(aarch64Compiler).toFile().exists()) {
|
||||
throw Exception("aarch64 compiler not found at $aarch64Compiler")
|
||||
}
|
||||
|
||||
if (!Paths.get(armv7aCompiler).toFile().exists()) {
|
||||
throw Exception("armv7a compiler not found at $armv7aCompiler")
|
||||
}
|
||||
|
||||
val Files = Files.map { Paths.get(project.projectDir.toString(), "src", it).toString() }.toTypedArray()
|
||||
|
||||
val buildDir = getLayout().getBuildDirectory().getAsFile().get()
|
||||
buildDir.mkdirs()
|
||||
|
||||
val compileArgs = if (isDebug) CFlagsDebug else CFlagsRelease
|
||||
|
||||
val execFile = { command: Array<String> ->
|
||||
val process = Runtime.getRuntime().exec(command)
|
||||
val output = process.inputStream.bufferedReader().readText()
|
||||
process.waitFor()
|
||||
output
|
||||
}
|
||||
|
||||
val aarch64OutputDir = Paths.get(buildDir.toString(), "arm64-v8a").toFile()
|
||||
aarch64OutputDir.mkdirs()
|
||||
|
||||
/* INFO: Compile for aarch64 */
|
||||
val aarch64Command = arrayOf(aarch64Compiler, "-o", Paths.get(aarch64OutputDir.toString(), "zygiskd").toString(), *compileArgs, *Files)
|
||||
val aarch64CommandResult = execFile(aarch64Command)
|
||||
if (aarch64CommandResult.isNotEmpty()) {
|
||||
println(aarch64CommandResult)
|
||||
}
|
||||
|
||||
val armv7aOutputDir = Paths.get(buildDir.toString(), "armeabi-v7a").toFile()
|
||||
armv7aOutputDir.mkdirs()
|
||||
|
||||
/* INFO: Compile for armv7a */
|
||||
val armv7aCommand = arrayOf(armv7aCompiler, "-o", Paths.get(armv7aOutputDir.toString(), "zygiskd").toString(), *compileArgs, *Files)
|
||||
val armv7aCommandResult = execFile(armv7aCommand)
|
||||
if (armv7aCommandResult.isNotEmpty()) {
|
||||
println(armv7aCommandResult)
|
||||
}
|
||||
|
||||
val x86OutputDir = Paths.get(buildDir.toString(), "x86").toFile()
|
||||
x86OutputDir.mkdirs()
|
||||
|
||||
/* INFO: Compile for x86 */
|
||||
val x86Compiler = Paths.get(ndkPath, "toolchains", "llvm", "prebuilt", "linux-x86_64", "bin", "i686-linux-android34-clang").toString()
|
||||
val x86Command = arrayOf(x86Compiler, "-o", Paths.get(x86OutputDir.toString(), "zygiskd").toString(), *compileArgs, *Files)
|
||||
val x86CommandResult = execFile(x86Command)
|
||||
if (x86CommandResult.isNotEmpty()) {
|
||||
println(x86CommandResult)
|
||||
}
|
||||
|
||||
val x86_64OutputDir = Paths.get(buildDir.toString(), "x86_64").toFile()
|
||||
x86_64OutputDir.mkdirs()
|
||||
|
||||
/* INFO: Compile for x86_64 */
|
||||
val x86_64Compiler = Paths.get(ndkPath, "toolchains", "llvm", "prebuilt", "linux-x86_64", "bin", "x86_64-linux-android34-clang").toString()
|
||||
val x86_64Command = arrayOf(x86_64Compiler, "-o", Paths.get(x86_64OutputDir.toString(), "zygiskd").toString(), *compileArgs, *Files)
|
||||
val x86_64CommandResult = execFile(x86_64Command)
|
||||
if (x86_64CommandResult.isNotEmpty()) {
|
||||
println(x86_64CommandResult)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
import java.nio.file.Paths
|
||||
import org.gradle.internal.os.OperatingSystem
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.agp.lib)
|
||||
}
|
||||
|
||||
val verCode: Int by rootProject.extra
|
||||
val verName: String by rootProject.extra
|
||||
val commitHash: String by rootProject.extra
|
||||
|
||||
fun Project.findInPath(executable: String, property: String): String? {
|
||||
val pathEnv = System.getenv("PATH")
|
||||
return pathEnv.split(File.pathSeparator).map { folder ->
|
||||
Paths.get("${folder}${File.separator}${executable}${if (OperatingSystem.current().isWindows) ".exe" else ""}")
|
||||
.toFile()
|
||||
}.firstOrNull { path ->
|
||||
path.exists()
|
||||
}?.absolutePath ?: properties.getOrDefault(property, null) as? String?
|
||||
}
|
||||
|
||||
val ccachePath by lazy {
|
||||
project.findInPath("ccache", "ccache.path")?.also {
|
||||
println("loader: Use ccache: $it")
|
||||
}
|
||||
}
|
||||
|
||||
val defaultCFlags = arrayOf(
|
||||
"-Wall", "-Wextra",
|
||||
"-fno-rtti", "-fno-exceptions",
|
||||
"-fno-stack-protector", "-fomit-frame-pointer",
|
||||
"-Wno-builtin-macro-redefined", "-D__FILE__=__FILE_NAME__",
|
||||
"-O0", "-g"
|
||||
)
|
||||
|
||||
val releaseFlags = arrayOf(
|
||||
"-Oz", "-flto",
|
||||
"-Wno-unused", "-Wno-unused-parameter",
|
||||
"-fvisibility=hidden", "-fvisibility-inlines-hidden",
|
||||
"-fno-unwind-tables", "-fno-asynchronous-unwind-tables",
|
||||
"-Wl,--exclude-libs,ALL", "-Wl,--gc-sections", "-Wl,--strip-all"
|
||||
)
|
||||
|
||||
android {
|
||||
buildFeatures {
|
||||
androidResources = false
|
||||
buildConfig = false
|
||||
prefab = true
|
||||
}
|
||||
|
||||
externalNativeBuild.cmake {
|
||||
path("src/CMakeLists.txt")
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
externalNativeBuild.cmake {
|
||||
arguments += "-DANDROID_STL=none"
|
||||
arguments += "-DLSPLT_STANDALONE=ON"
|
||||
cFlags("-std=c18", *defaultCFlags)
|
||||
cppFlags("-std=c++20", *defaultCFlags)
|
||||
ccachePath?.let {
|
||||
arguments += "-DNDK_CCACHE=$it"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
externalNativeBuild.cmake {
|
||||
arguments += "-DZKSU_VERSION=$verName-$verCode-$commitHash-debug"
|
||||
}
|
||||
}
|
||||
release {
|
||||
externalNativeBuild.cmake {
|
||||
cFlags += releaseFlags
|
||||
cppFlags += releaseFlags
|
||||
arguments += "-DZKSU_VERSION=$verName-$verCode-$commitHash-release"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("dev.rikka.ndk.thirdparty:cxx:1.2.0")
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
project("zygiskd")
|
||||
|
||||
find_package(cxx REQUIRED CONFIG)
|
||||
|
||||
add_definitions(-DZKSU_VERSION=\"${ZKSU_VERSION}\")
|
||||
|
||||
aux_source_directory(common COMMON_SRC_LIST)
|
||||
add_library(common STATIC ${COMMON_SRC_LIST})
|
||||
target_include_directories(common PRIVATE include)
|
||||
target_link_libraries(log)
|
||||
|
||||
aux_source_directory(ptracer PTRACER_SRC_LIST)
|
||||
add_executable(libzygisk_ptrace.so ${PTRACER_SRC_LIST})
|
||||
target_include_directories(libzygisk_ptrace.so PRIVATE include)
|
||||
target_link_libraries(libzygisk_ptrace.so cxx::cxx log common)
|
||||
Reference in New Issue
Block a user