Skip to content

Commit

Permalink
Adapt latest change
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoxindada <2245062854@qq.com>
  • Loading branch information
xiaoxindada committed Dec 14, 2024
1 parent e205cad commit b8a6663
Show file tree
Hide file tree
Showing 44 changed files with 2,138 additions and 22 deletions.
41 changes: 19 additions & 22 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ def system(cmd):
return subprocess.run(cmd, shell=True, stdout=sys.stdout)


def cmd_out(cmd, env=None):
def cmd_out(cmd):
return (
subprocess.run(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=env
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL
)
.stdout.strip()
.decode("utf-8")
Expand All @@ -115,7 +115,7 @@ def cmd_out(cmd, env=None):

LOCALDIR = op.realpath(".")
cpu_count = multiprocessing.cpu_count()
os_name = platform.system().lower()
os_name = "linux"
release = True

# Common constants
Expand Down Expand Up @@ -202,9 +202,8 @@ def dump_flag_header():
write_if_diff(op.join(native_gen_path, "flags.h"), flag_txt)



def build_native():
targets = default_targets
targets = support_targets
print("* Building: " + " ".join(targets))

if sccache := shutil.which("sccache"):
Expand All @@ -218,7 +217,6 @@ def build_native():
build_cpp_src(targets)



def run_cargo(cmds, triple="aarch64-linux-android"):
llvm_bin = op.join(
ndk_root, "toolchains", "llvm", "prebuilt", f"{os_name}-x86_64", "bin"
Expand All @@ -236,8 +234,6 @@ def build_rust_src(targets: set):
if "resetprop" in targets:
targets.add("magisk")
targets = targets & rust_targets
if not targets:
return

os.chdir(Path(LOCALDIR, "src"))

Expand Down Expand Up @@ -317,13 +313,14 @@ def run_cargo_build():

# Start building the actual build commands
cmds = ["build", "-p", ""]
rust_out = "debug"
if release:
cmds.append("-r")
rust_out = "release"
profile = "release"
else:
profile = "debug"

cmds.append("--target")
cmds.append("")
for triple in build_abis.values():
cmds.append("--target")
cmds.append(triple)

for arch, triple in zip(archs, triples):
rust_triple = (
Expand All @@ -340,23 +337,26 @@ def run_cargo_build():
arch_out = op.join(native_gen_path, arch)
mkdir_p(arch_out)
for tgt in targets:
source = op.join("target", rust_triple, rust_out, f"lib{tgt}.a")
source = rust_out / triple / profile / f"lib{tgt}.a"
target = op.join(arch_out, f"lib{tgt}-rs.a")
mv(source, target)


def setup_ndk():
os_name = platform.system().lower()
ndk_ver = config["ondkVersion"]
url = f"https://github.com/topjohnwu/ondk/releases/download/{config['ondkVersion']}/ondk-{config['ondkVersion']}-{os_name}.tar.xz"
ndk_archive = url.split("/")[-1]
print(f"Downloading {ndk_archive}")
wget.download(url, ndk_archive)
ondk_path = Path(LOCALDIR, f"ondk-{ndk_ver}")

if not os.path.isfile(ndk_archive):
print(f"Downloading {ndk_archive}")
wget.download(url, ndk_archive)
print(f"Extracting {ndk_archive}")
with tarfile.open(ndk_archive, mode="r|xz") as tar:
tar.extractall(LOCALDIR)
if op.exists(f"ondk-{config['ondkVersion']}"):
if op.exists(ondk_path):
rm_rf(ndk_root)
mv(f"ondk-{config['ondkVersion']}", ndk_root)
mv(ondk_path, ndk_root)


def run_ndk_build(cmds: list):
Expand Down Expand Up @@ -454,9 +454,6 @@ def update_code():
f"tail -n 4 <Magisk/gradle.properties >magisk_config.prop && echo 'magisk.version={magisk_version}' >>magisk_config.prop"
)

# Fix busybox git push missing header file
system("rm -rf Magisk/native/src/external/busybox/include/.gitignore")

# Fix path defined
system(
r"sed -i 's|\.\./\.\./\.\./tools/keys/|\.\./\.\./tools/keys/|g' Magisk/native/src/boot/sign.rs"
Expand Down
32 changes: 32 additions & 0 deletions tools/bootctl.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# How to build the bootctl bundled within the Magisk app:
#
# 1. Checkout and sync the AOSP tree:
# https://source.android.com/setup/build/downloading
# 2. Build for arm64:
# lunch aosp_arm64-eng
# 3. Apply patches:
# cd system/extras; patch -p1 < bootctl.patch
# 4. Build the executable:
# m bootctl

diff --git a/bootctl/Android.bp b/bootctl/Android.bp
index f63871cf..8a551bbe 100644
--- a/bootctl/Android.bp
+++ b/bootctl/Android.bp
@@ -26,11 +26,15 @@ cc_binary {
"-Werror",
],

- shared_libs: [
+ static_libs: [
"android.hardware.boot@1.0",
"android.hardware.boot@1.1",
"android.hardware.boot@1.2",
+ ],
+ shared_libs: [
"libhidlbase",
"libutils",
+ "libcutils",
+ "liblog",
],
}
1 change: 1 addition & 0 deletions tools/rustup_wrapper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
92 changes: 92 additions & 0 deletions tools/rustup_wrapper/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tools/rustup_wrapper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "rustup_wrapper"
version = "0.0.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
home = "0.5"
43 changes: 43 additions & 0 deletions tools/rustup_wrapper/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use std::env;
use std::process::{Command, Stdio};

use home::cargo_home;

/********************************
* Why do we need this wrapper?
********************************
*
* The command `rustup component list` does not work with custom toolchains:
* > error: toolchain 'magisk' does not support components
*
* However, this command is used by several IDEs to determine available
* components that can be used, such as clippy, rustfmt etc.
* In this script, we simply redirect the output when using the nightly
* channel if any `component` command failed.
*/

fn main() -> std::io::Result<()> {
let rustup = cargo_home()?.join("bin").join("rustup");
let argv: Vec<String> = env::args().skip(1).collect();

if argv.iter().any(|s| s == "component") {
let status = Command::new(&rustup)
.args(&argv)
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()?;
if !status.success() {
let mut cmd = Command::new(&rustup);
cmd.arg("+nightly");
if argv[0].starts_with('+') {
cmd.args(argv.iter().skip(1));
} else {
cmd.args(&argv);
}
return cmd.status().map(|_| ());
}
}

// Simply pass through
Command::new(&rustup).args(argv.iter()).status().map(|_| ())
}
6 changes: 6 additions & 0 deletions tools/termux-elf-cleaner/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Attach CI-built termux-elf-cleaner to release

on:
release:
types:
- published

jobs:
attach-program:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.TERMUXBOT2_TOKEN }}
steps:
- name: Clone repository
uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_REF }}
- name: Check version
run: |
RELEASE_VERSION_NAME="${GITHUB_REF/refs\/tags\//}"
if ! printf "%s" "${RELEASE_VERSION_NAME/v/}" | grep -qP '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'; then
echo "The versionName '${RELEASE_VERSION_NAME/v/}' is not a valid version as per semantic version '2.0.0' spec in the format 'major.minor.patch(-prerelease)(+buildmetadata)'. https://semver.org/spec/v2.0.0.html."
exit 1
fi
- name: Build
run: |
autoreconf -vfi
mkdir build && cd build
../configure
make
- name: Attach termux-elf-cleaner to release
run: >-
hub release edit
-m ""
-a "./build/termux-elf-cleaner"
"${GITHUB_REF/refs\/tags\//}"
33 changes: 33 additions & 0 deletions tools/termux-elf-cleaner/.github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build and test termux-elf-cleaner

on:
push:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_REF }}

- name: Prepare
run: |
autoreconf -vfi
mkdir build
- name: Configure
run: |
cd build
../configure
- name: Make
run: |
cd build
make
- name: Test
run: |
cd build
make check
15 changes: 15 additions & 0 deletions tools/termux-elf-cleaner/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# In case of in-src build:
elf-cleaner
# In case of out-of-src build in a directory build/:
build/

*~

Makefile.in
aclocal.m4
autom4te.cache/
compile
configure
depcomp
install-sh
missing
Loading

0 comments on commit b8a6663

Please sign in to comment.