Prebuild Busybox

Prebuild with tools in ndk-box-kitchen
This commit is contained in:
topjohnwu 2024-07-17 02:58:31 -07:00
parent 7c0b25cad9
commit ef81cdab4f
9 changed files with 38 additions and 142 deletions

6
.gitmodules vendored
View File

@ -1,9 +1,6 @@
[submodule "selinux"] [submodule "selinux"]
path = native/src/external/selinux path = native/src/external/selinux
url = https://github.com/topjohnwu/selinux.git url = https://github.com/topjohnwu/selinux.git
[submodule "busybox"]
path = native/src/external/busybox
url = https://github.com/topjohnwu/ndk-busybox.git
[submodule "lz4"] [submodule "lz4"]
path = native/src/external/lz4 path = native/src/external/lz4
url = https://github.com/lz4/lz4.git url = https://github.com/lz4/lz4.git
@ -13,9 +10,6 @@
[submodule "xz"] [submodule "xz"]
path = native/src/external/xz path = native/src/external/xz
url = https://github.com/xz-mirror/xz.git url = https://github.com/xz-mirror/xz.git
[submodule "pcre"]
path = native/src/external/pcre
url = https://android.googlesource.com/platform/external/pcre
[submodule "libcxx"] [submodule "libcxx"]
path = native/src/external/libcxx path = native/src/external/libcxx
url = https://github.com/topjohnwu/libcxx.git url = https://github.com/topjohnwu/libcxx.git

View File

@ -76,7 +76,7 @@ triples = [
"x86_64-linux-android", "x86_64-linux-android",
"riscv64-linux-android", "riscv64-linux-android",
] ]
default_targets = ["magisk", "magiskinit", "magiskboot", "magiskpolicy", "busybox"] default_targets = ["magisk", "magiskinit", "magiskboot", "magiskpolicy"]
support_targets = default_targets + ["resetprop"] support_targets = default_targets + ["resetprop"]
rust_targets = ["magisk", "magiskinit", "magiskboot", "magiskpolicy"] rust_targets = ["magisk", "magiskinit", "magiskboot", "magiskpolicy"]
@ -246,7 +246,7 @@ def run_ndk_build(args, flags):
mv(source, target) mv(source, target)
def run_cargo(cmds, triple="aarch64-linux-android"): def run_cargo(cmds):
env = os.environ.copy() env = os.environ.copy()
env["PATH"] = f'{rust_bin}{os.pathsep}{env["PATH"]}' env["PATH"] = f'{rust_bin}{os.pathsep}{env["PATH"]}'
env["CARGO_BUILD_RUSTC"] = str(rust_bin / f"rustc{EXE_EXT}") env["CARGO_BUILD_RUSTC"] = str(rust_bin / f"rustc{EXE_EXT}")
@ -287,7 +287,7 @@ def run_cargo_build(args):
for target in targets: for target in targets:
cmds[2] = target cmds[2] = target
proc = run_cargo(cmds, triple) proc = run_cargo(cmds)
if proc.returncode != 0: if proc.returncode != 0:
error("Build binary failed!") error("Build binary failed!")

View File

@ -17,6 +17,7 @@ import org.gradle.api.JavaVersion
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property import org.gradle.api.provider.Property
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.Delete import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.Input import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.InputFiles
@ -39,8 +40,11 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.io.File import java.io.File
import java.net.URI
import java.security.KeyStore import java.security.KeyStore
import java.security.MessageDigest
import java.security.cert.X509Certificate import java.security.cert.X509Certificate
import java.util.HexFormat
import java.util.jar.JarFile import java.util.jar.JarFile
import java.util.zip.Deflater import java.util.zip.Deflater
import java.util.zip.DeflaterOutputStream import java.util.zip.DeflaterOutputStream
@ -109,6 +113,11 @@ fun Project.setupCommon() {
} }
} }
const val BUSYBOX_DOWNLOAD_URL =
"https://github.com/topjohnwu/magisk-files/releases/download/files/busybox-1.36.1.0.zip"
const val BUSYBOX_ZIP_CHECKSUM =
"ea4f3019b0087dcb68130b32ab59dc2db0ee0af11d8396124a94c4231c5ea441"
fun Project.setupCoreLib() { fun Project.setupCoreLib() {
setupCommon() setupCommon()
@ -117,18 +126,41 @@ fun Project.setupCoreLib() {
for (abi in arrayOf("armeabi-v7a", "x86", "arm64-v8a", "x86_64", "riscv64")) { for (abi in arrayOf("armeabi-v7a", "x86", "arm64-v8a", "x86_64", "riscv64")) {
into(abi) { into(abi) {
from(rootProject.file("native/out/$abi")) { from(rootProject.file("native/out/$abi")) {
include("busybox", "magiskboot", "magiskinit", "magiskpolicy", "magisk") include("magiskboot", "magiskinit", "magiskpolicy", "magisk")
rename { "lib$it.so" } rename { "lib$it.so" }
} }
} }
} }
onlyIf { onlyIf {
if (inputs.sourceFiles.files.size != 25) if (inputs.sourceFiles.files.size != 20)
throw StopExecutionException("Please build binaries first! (./build.py binary)") throw StopExecutionException("Please build binaries first! (./build.py binary)")
true true
} }
} }
val downloadBusybox by tasks.registering(Copy::class) {
dependsOn(syncLibs)
val bb = layout.buildDirectory.file(BUSYBOX_ZIP_CHECKSUM).get().asFile
if (bb.exists()) {
val md = MessageDigest.getInstance("SHA-256")
bb.inputStream().use { md.update(it.readAllBytes()) }
val hash = HexFormat.of().formatHex(md.digest())
if (hash != BUSYBOX_ZIP_CHECKSUM) {
bb.delete()
}
}
if (!bb.exists()) {
bb.parentFile.mkdirs()
URI(BUSYBOX_DOWNLOAD_URL).toURL().openStream().use { dl ->
bb.outputStream().use {
dl.copyTo(it)
}
}
}
from(zipTree(bb))
into("src/main/jniLibs")
}
val syncResources by tasks.registering(Sync::class) { val syncResources by tasks.registering(Sync::class) {
into("src/main/resources/META-INF/com/google/android") into("src/main/resources/META-INF/com/google/android")
from(rootProject.file("scripts/update_binary.sh")) { from(rootProject.file("scripts/update_binary.sh")) {
@ -142,7 +174,7 @@ fun Project.setupCoreLib() {
androidLib.libraryVariants.all { androidLib.libraryVariants.all {
val variantCapped = name.replaceFirstChar { it.uppercase() } val variantCapped = name.replaceFirstChar { it.uppercase() }
tasks.getByPath("merge${variantCapped}JniLibFolders").dependsOn(syncLibs) tasks.getByPath("merge${variantCapped}JniLibFolders").dependsOn(downloadBusybox)
processJavaResourcesProvider.configure { dependsOn(syncResources) } processJavaResourcesProvider.configure { dependsOn(syncResources) }
val stubTask = tasks.getByPath(":app:stub:comment$variantCapped") val stubTask = tasks.getByPath(":app:stub:comment$variantCapped")

View File

@ -172,9 +172,3 @@ include $(BUILD_STATIC_LIBRARY)
include src/Android-rs.mk include src/Android-rs.mk
include src/base/Android.mk include src/base/Android.mk
include src/external/Android.mk include src/external/Android.mk
ifdef B_BB
include src/external/busybox/Android.mk
endif

View File

@ -17,11 +17,3 @@ APP_CFLAGS += -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-stac
NDK_APP_OUT := ./obj/nolibc NDK_APP_OUT := ./obj/nolibc
endif endif
# Busybox should use a newer libc.a
ifdef B_BB
APP_PLATFORM := android-26
ifeq ($(OS),Windows_NT)
APP_SHORT_COMMANDS := true
endif
endif

View File

@ -220,116 +220,6 @@ LOCAL_CFLAGS += -DHAVE_REALLOCARRAY
endif endif
include $(BUILD_STATIC_LIBRARY) include $(BUILD_STATIC_LIBRARY)
# libselinux.a
include $(CLEAR_VARS)
LIBSELINUX := $(SE_PATH)/libselinux/include
LOCAL_MODULE:= libselinux
LOCAL_C_INCLUDES := $(LIBSELINUX)
LOCAL_EXPORT_C_INCLUDES := $(LIBSELINUX)
LOCAL_STATIC_LIBRARIES := libpcre2
LOCAL_CFLAGS := \
-Wno-implicit-function-declaration -Wno-int-conversion -Wno-unused-function \
-Wno-macro-redefined -Wno-unused-but-set-variable -D_GNU_SOURCE -DUSE_PCRE2 \
-DNO_PERSISTENTLY_STORED_PATTERNS -DDISABLE_SETRANS -DDISABLE_BOOL \
-DNO_MEDIA_BACKEND -DNO_X_BACKEND -DNO_DB_BACKEND -DNO_ANDROID_BACKEND \
-Dfgets_unlocked=fgets -D'__fsetlocking(...)='
LOCAL_SRC_FILES := \
selinux/libselinux/src/avc.c \
selinux/libselinux/src/avc_internal.c \
selinux/libselinux/src/avc_sidtab.c \
selinux/libselinux/src/booleans.c \
selinux/libselinux/src/callbacks.c \
selinux/libselinux/src/canonicalize_context.c \
selinux/libselinux/src/checkAccess.c \
selinux/libselinux/src/check_context.c \
selinux/libselinux/src/checkreqprot.c \
selinux/libselinux/src/compute_av.c \
selinux/libselinux/src/compute_create.c \
selinux/libselinux/src/compute_member.c \
selinux/libselinux/src/compute_relabel.c \
selinux/libselinux/src/compute_user.c \
selinux/libselinux/src/context.c \
selinux/libselinux/src/deny_unknown.c \
selinux/libselinux/src/disable.c \
selinux/libselinux/src/enabled.c \
selinux/libselinux/src/fgetfilecon.c \
selinux/libselinux/src/freecon.c \
selinux/libselinux/src/freeconary.c \
selinux/libselinux/src/fsetfilecon.c \
selinux/libselinux/src/get_context_list.c \
selinux/libselinux/src/get_default_type.c \
selinux/libselinux/src/get_initial_context.c \
selinux/libselinux/src/getenforce.c \
selinux/libselinux/src/getfilecon.c \
selinux/libselinux/src/getpeercon.c \
selinux/libselinux/src/init.c \
selinux/libselinux/src/is_customizable_type.c \
selinux/libselinux/src/label.c \
selinux/libselinux/src/label_file.c \
selinux/libselinux/src/label_support.c \
selinux/libselinux/src/lgetfilecon.c \
selinux/libselinux/src/load_policy.c \
selinux/libselinux/src/lsetfilecon.c \
selinux/libselinux/src/mapping.c \
selinux/libselinux/src/matchmediacon.c \
selinux/libselinux/src/matchpathcon.c \
selinux/libselinux/src/policyvers.c \
selinux/libselinux/src/procattr.c \
selinux/libselinux/src/query_user_context.c \
selinux/libselinux/src/regex.c \
selinux/libselinux/src/reject_unknown.c \
selinux/libselinux/src/selinux_check_securetty_context.c \
selinux/libselinux/src/selinux_config.c \
selinux/libselinux/src/selinux_restorecon.c \
selinux/libselinux/src/sestatus.c \
selinux/libselinux/src/setenforce.c \
selinux/libselinux/src/setexecfilecon.c \
selinux/libselinux/src/setfilecon.c \
selinux/libselinux/src/setrans_client.c \
selinux/libselinux/src/seusers.c \
selinux/libselinux/src/sha1.c \
selinux/libselinux/src/stringrep.c \
selinux/libselinux/src/validatetrans.c
include $(BUILD_STATIC_LIBRARY)
# libpcre2.a
include $(CLEAR_VARS)
LIBPCRE2 := $(LOCAL_PATH)/pcre/include
LOCAL_MODULE:= libpcre2
LOCAL_CFLAGS := -DHAVE_CONFIG_H -DPCRE2_CODE_UNIT_WIDTH=8
LOCAL_C_INCLUDES := $(LIBPCRE2) $(LIBPCRE2)_internal
LOCAL_EXPORT_C_INCLUDES := $(LIBPCRE2)
LOCAL_SRC_FILES := \
pcre/src/pcre2_auto_possess.c \
pcre/src/pcre2_compile.c \
pcre/src/pcre2_config.c \
pcre/src/pcre2_context.c \
pcre/src/pcre2_convert.c \
pcre/src/pcre2_dfa_match.c \
pcre/src/pcre2_error.c \
pcre/src/pcre2_extuni.c \
pcre/src/pcre2_find_bracket.c \
pcre/src/pcre2_fuzzsupport.c \
pcre/src/pcre2_maketables.c \
pcre/src/pcre2_match.c \
pcre/src/pcre2_match_data.c \
pcre/src/pcre2_jit_compile.c \
pcre/src/pcre2_newline.c \
pcre/src/pcre2_ord2utf.c \
pcre/src/pcre2_pattern_info.c \
pcre/src/pcre2_script_run.c \
pcre/src/pcre2_serialize.c \
pcre/src/pcre2_string_utils.c \
pcre/src/pcre2_study.c \
pcre/src/pcre2_substitute.c \
pcre/src/pcre2_substring.c \
pcre/src/pcre2_tables.c \
pcre/src/pcre2_ucd.c \
pcre/src/pcre2_valid_utf.c \
pcre/src/pcre2_xclass.c \
pcre2_workaround.c
include $(BUILD_STATIC_LIBRARY)
# liblsplt.a # liblsplt.a
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE:= liblsplt LOCAL_MODULE:= liblsplt

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

@ -1 +0,0 @@
Subproject commit 8e12681a1a252fd581830b2f65d1e154a2030bb9

View File

@ -1,4 +0,0 @@
// Workaround pcre2_chartables.c symlink to pcre2_chartables.c.dist failing on Windows NDK if Cygwin git used,
// and NDK not directly accepting a .c.dist file in LOCAL_SRC_FILES list.
#include "pcre/src/pcre2_chartables.c.dist"