Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/ksuinit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ jobs:

- name: Build ksuinit
Comment on lines 26 to 27
Copy link

Copilot AI Mar 23, 2026

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.

Suggested change
- name: Build ksuinit
- name: Set up Android SDK and NDK
uses: android-actions/setup-android@v3
with:
ndk-version: 25.2.9519653
- name: Build ksuinit
env:
ANDROID_NDK_HOME: ${{ env.ANDROID_NDK_ROOT }}

Copilot uses AI. Check for mistakes.
run: |
LLVM_BIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER="$LLVM_BIN/aarch64-linux-android26-clang"
export RUSTFLAGS="-C link-arg=-no-pie"
cd userspace/ksuinit
cargo build --target=aarch64-unknown-linux-musl --release
cd userspace
cargo build-ksuinit

- name: Upload ksuinit artifact
uses: actions/upload-artifact@v6
Expand Down
2 changes: 2 additions & 0 deletions userspace/.cargo/config.toml
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 --"
3 changes: 3 additions & 0 deletions userspace/ksuinit/.cargo/config.example.toml
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"
2 changes: 1 addition & 1 deletion userspace/ksuinit/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/target
/.idea
.cargo
.cargo/config.toml
1 change: 1 addition & 0 deletions userspace/tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the other Rust userspace crates (e.g., userspace/ksuinit/.gitignore and userspace/ksud/.gitignore), consider using /target here instead of target so the rule only applies to the crate root and doesn't accidentally ignore any nested target directories.

Suggested change
target
/target

Copilot uses AI. Check for mistakes.
7 changes: 7 additions & 0 deletions userspace/tools/Cargo.lock

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

10 changes: 10 additions & 0 deletions userspace/tools/Cargo.toml
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]
91 changes: 91 additions & 0 deletions userspace/tools/src/bin/build-ksuinit.rs
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)
}
}
Loading