Skip to content

Commit

Permalink
Prebuild Busybox
Browse files Browse the repository at this point in the history
Prebuild with tools in ndk-box-kitchen
  • Loading branch information
1q23lyc45 committed Jan 4, 2025
1 parent 173458e commit ab05a02
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 143 deletions.
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "selinux"]
path = native/src/external/selinux
url = https://github.com/LSPosed/selinux.git
[submodule "busybox"]
path = native/src/external/busybox
url = https://github.com/topjohnwu/ndk-busybox.git
[submodule "lz4"]
path = native/src/external/lz4
url = https://github.com/lz4/lz4.git
Expand All @@ -13,9 +10,6 @@
[submodule "xz"]
path = native/src/external/xz
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"]
path = native/src/external/libcxx
url = https://github.com/topjohnwu/libcxx.git
Expand Down
6 changes: 3 additions & 3 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def vprint(str):
"aarch64-linux-android",
"x86_64-linux-android",
]
default_targets = ["magisk", "magiskinit", "magiskboot", "magiskpolicy", "busybox"]
default_targets = ["magisk", "magiskinit", "magiskboot", "magiskpolicy"]
support_targets = default_targets + ["resetprop"]
rust_targets = ["magisk", "magiskinit", "magiskboot", "magiskpolicy"]

Expand Down Expand Up @@ -252,7 +252,7 @@ def run_ndk_build(flags):
mv(source, target)


def run_cargo(cmds, triple="aarch64-linux-android"):
def run_cargo(cmds):
env = os.environ.copy()
env["PATH"] = f'{rust_bin}{os.pathsep}{env["PATH"]}'
env["CARGO_BUILD_RUSTC"] = op.join(rust_bin, "rustc" + EXE_EXT)
Expand Down Expand Up @@ -291,7 +291,7 @@ def run_cargo_build(args):

for target in targets:
cmds[2] = target
proc = run_cargo(cmds, triple)
proc = run_cargo(cmds)
if proc.returncode != 0:
error("Build binary failed!")

Expand Down
43 changes: 38 additions & 5 deletions buildSrc/src/main/java/Setup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.gradle.api.Project
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
Expand All @@ -36,9 +37,12 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import java.io.ByteArrayOutputStream
import java.io.File
import java.net.URI
import java.security.KeyStore
import java.security.MessageDigest
import java.security.cert.X509Certificate
import java.util.jar.JarFile
import java.util.HexFormat
import java.util.zip.Deflater
import java.util.zip.DeflaterOutputStream
import java.util.zip.ZipEntry
Expand Down Expand Up @@ -94,6 +98,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"

private fun ApkSigningConfig.getPrivateKey(): KeyStore.PrivateKeyEntry {
val keyStore = KeyStore.getInstance(storeType ?: KeyStore.getDefaultType())
storeFile!!.inputStream().use {
Expand Down Expand Up @@ -230,25 +239,25 @@ fun Project.setupApp() {
into("src/main/jniLibs")
into("armeabi-v7a") {
from(rootProject.file("native/out/armeabi-v7a")) {
include("busybox", "magiskboot", "magiskinit", "magiskpolicy", "magisk")
include("magiskboot", "magiskinit", "magiskpolicy", "magisk")
rename { if (it == "magisk") "libmagisk32.so" else "lib$it.so" }
}
}
into("x86") {
from(rootProject.file("native/out/x86")) {
include("busybox", "magiskboot", "magiskinit", "magiskpolicy", "magisk")
include("magiskboot", "magiskinit", "magiskpolicy", "magisk")
rename { if (it == "magisk") "libmagisk32.so" else "lib$it.so" }
}
}
into("arm64-v8a") {
from(rootProject.file("native/out/arm64-v8a")) {
include("busybox", "magiskboot", "magiskinit", "magiskpolicy", "magisk")
include("magiskboot", "magiskinit", "magiskpolicy", "magisk")
rename { if (it == "magisk") "libmagisk64.so" else "lib$it.so" }
}
}
into("x86_64") {
from(rootProject.file("native/out/x86_64")) {
include("busybox", "magiskboot", "magiskinit", "magiskpolicy", "magisk")
include("magiskboot", "magiskinit", "magiskpolicy", "magisk")
rename { if (it == "magisk") "libmagisk64.so" else "lib$it.so" }
}
}
Expand All @@ -259,6 +268,30 @@ fun Project.setupApp() {
}
}

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) {
into("src/main/resources/META-INF/com/google/android")
from(rootProject.file("scripts/update_binary.sh")) {
Expand All @@ -272,7 +305,7 @@ fun Project.setupApp() {
android.applicationVariants.all {
val variantCapped = name.replaceFirstChar { it.uppercase() }

tasks.getByPath("merge${variantCapped}JniLibFolders").dependsOn(syncLibs)
tasks.getByPath("merge${variantCapped}JniLibFolders").dependsOn(downloadBusybox)
processJavaResourcesProvider.configure { dependsOn(syncResources) }

val stubTask = tasks.getByPath(":stub:comment$variantCapped")
Expand Down
6 changes: 0 additions & 6 deletions native/src/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,3 @@ include $(BUILD_STATIC_LIBRARY)
include src/Android-rs.mk
include src/base/Android.mk
include src/external/Android.mk

ifdef B_BB

include src/external/busybox/Android.mk

endif
7 changes: 0 additions & 7 deletions native/src/Application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,3 @@ APP_THIN_ARCHIVE := true
APP_STRIP_MODE := none
APP_SUPPORT_FLEXIBLE_PAGE_SIZES := true

# Busybox should use stock libc.a
ifdef B_BB
APP_PLATFORM := android-26
ifeq ($(OS),Windows_NT)
APP_SHORT_COMMANDS := true
endif
endif
110 changes: 0 additions & 110 deletions native/src/external/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -223,116 +223,6 @@ LOCAL_SRC_FILES := \
LOCAL_CFLAGS := -Wno-unused-but-set-variable
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
include $(CLEAR_VARS)
LOCAL_MODULE:= liblsplt
Expand Down
1 change: 0 additions & 1 deletion native/src/external/busybox
Submodule busybox deleted from b0f643
1 change: 0 additions & 1 deletion native/src/external/pcre
Submodule pcre deleted from 8e1268
4 changes: 0 additions & 4 deletions native/src/external/pcre2_workaround.c

This file was deleted.

0 comments on commit ab05a02

Please sign in to comment.