-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
ksuinit: add build tool #3327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
ksuinit: add build tool #3327
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [alias] | ||
| build-ksuinit = "run --manifest-path tools/Cargo.toml --bin build-ksuinit --" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [build] | ||
| # uncomment below if you need rust-analyzer | ||
| # target = "aarch64-unknown-linux-musl" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| /target | ||
| /.idea | ||
| .cargo | ||
| .cargo/config.toml |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||
| target | ||||||
|
||||||
| target | |
| /target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [package] | ||
| name = "tools" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
|
|
||
| [[bin]] | ||
| name = "build-ksuinit" | ||
| path = "src/bin/build-ksuinit.rs" | ||
|
|
||
| [dependencies] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| use std::env; | ||
| use std::path::{Path, PathBuf}; | ||
| use std::process::{Command, ExitCode}; | ||
|
|
||
| const TARGET: &str = "aarch64-unknown-linux-musl"; | ||
|
|
||
| fn host_tag() -> &'static str { | ||
| match env::consts::OS { | ||
| "windows" => "windows", | ||
| "linux" => "linux", | ||
| "macos" => "darwin", | ||
| other => { | ||
| eprintln!("Unsupported host OS: {other}"); | ||
| std::process::exit(2); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn find_linker(ndk_home: &Path) -> PathBuf { | ||
| let base = ndk_home | ||
| .join("toolchains") | ||
| .join("llvm") | ||
| .join("prebuilt") | ||
| .join(format!("{}-x86_64", host_tag())) | ||
| .join("bin"); | ||
|
|
||
| let linker = if cfg!(windows) { | ||
| let cmd = base.join("aarch64-linux-android26-clang.cmd"); | ||
| if cmd.exists() { | ||
| cmd | ||
| } else { | ||
| base.join("aarch64-linux-android26-clang") | ||
| } | ||
| } else { | ||
| base.join("aarch64-linux-android26-clang") | ||
| }; | ||
|
|
||
| if !linker.exists() { | ||
| eprintln!("Linker not found: {}", linker.display()); | ||
| std::process::exit(2); | ||
| } | ||
|
|
||
| linker | ||
| } | ||
|
|
||
| fn main() -> ExitCode { | ||
| let ndk_home = match env::var("ANDROID_NDK_HOME") { | ||
| Ok(v) if !v.trim().is_empty() => v, | ||
| _ => { | ||
| eprintln!("ANDROID_NDK_HOME is required"); | ||
| return ExitCode::from(2); | ||
| } | ||
| }; | ||
|
|
||
| let linker = find_linker(Path::new(&ndk_home)); | ||
| let rustflags = match env::var("RUSTFLAGS") { | ||
| Ok(existing) if !existing.trim().is_empty() => format!("{existing} -C link-arg=-no-pie"), | ||
| _ => "-C link-arg=-no-pie".to_string(), | ||
| }; | ||
|
|
||
| let mut cmd = Command::new("cargo"); | ||
| cmd.arg("build") | ||
| .arg("--target") | ||
| .arg(TARGET) | ||
| .arg("--release") | ||
| .current_dir(Path::new(env!("CARGO_MANIFEST_DIR")).join("../ksuinit")) | ||
| .env( | ||
| "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER", | ||
| linker.as_os_str(), | ||
| ) | ||
| .env("RUSTFLAGS", rustflags); | ||
|
|
||
| // Allow users to append extra build flags after `--`. | ||
| for arg in env::args().skip(1) { | ||
| cmd.arg(arg); | ||
| } | ||
|
|
||
| let status = match cmd.status() { | ||
| Ok(s) => s, | ||
| Err(e) => { | ||
| eprintln!("Failed to execute cargo build: {e}"); | ||
| return ExitCode::from(1); | ||
| } | ||
| }; | ||
|
|
||
| if status.success() { | ||
| ExitCode::SUCCESS | ||
| } else { | ||
| ExitCode::from(1) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build tool errors out if ANDROID_NDK_HOME is unset, but this workflow doesn't install/configure the Android NDK or export ANDROID_NDK_HOME. As a result, the CI job will fail on runners where ANDROID_NDK_HOME is not preconfigured. Consider adding an Android SDK/NDK setup step (pin an NDK version) and explicitly setting ANDROID_NDK_HOME before calling
cargo build-ksuinit, or update the tool to derive the NDK path from ANDROID_SDK_ROOT/ANDROID_HOME when ANDROID_NDK_HOME is missing.