Skip to content

Commit 9c9daf7

Browse files
author
Hyper-Fumetsu
committed
➕ C/C++ & Rust Android cross-compile workflows for gh-build v2
1 parent 6bfed61 commit 9c9daf7

2 files changed

Lines changed: 249 additions & 0 deletions

File tree

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Build Android ARM64 C/C++
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
repo:
7+
description: 'GitHub repo (org/name)'
8+
required: true
9+
type: string
10+
source:
11+
description: 'Source file(s) glob or "Makefile"'
12+
required: false
13+
default: '*.c'
14+
type: string
15+
output:
16+
description: 'Output .so or binary name'
17+
required: false
18+
default: 'output.so'
19+
type: string
20+
flags:
21+
description: 'Extra CFLAGS/LDFLAGS'
22+
required: false
23+
default: '-shared -fPIC -O2'
24+
type: string
25+
version:
26+
description: 'Package version'
27+
required: false
28+
default: '1.0'
29+
type: string
30+
31+
jobs:
32+
build:
33+
runs-on: ubuntu-latest
34+
permissions:
35+
contents: write
36+
steps:
37+
- uses: actions/checkout@v4
38+
with:
39+
repository: ${{ inputs.repo }}
40+
path: src
41+
42+
- name: Setup Android NDK
43+
run: |
44+
NDK_VER="r29"
45+
curl -fsSL "https://dl.google.com/android/repository/android-ndk-${NDK_VER}-linux.zip" -o ndk.zip
46+
unzip -q ndk.zip
47+
echo "NDK_ROOT=$PWD/android-ndk-${NDK_VER}" >> $GITHUB_ENV
48+
49+
- name: Compile (aarch64-linux-android24)
50+
run: |
51+
set -e
52+
CLANG="$NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
53+
mkdir -p dist
54+
55+
cd src
56+
if echo "${{ inputs.source }}" | grep -qi makefile; then
57+
make CC="$CLANG" CFLAGS="${{ inputs.flags }}"
58+
cp "${{ inputs.output }}" ../dist/
59+
else
60+
$CLANG ${{ inputs.flags }} ${{ inputs.source }} -o ../dist/${{ inputs.output }} -ldl
61+
fi
62+
cd ..
63+
64+
file "dist/${{ inputs.output }}"
65+
ls -lh "dist/${{ inputs.output }}"
66+
67+
- name: Build .deb + push apt-repo
68+
run: |
69+
set -e
70+
SO="${{ inputs.output }}"
71+
PKG="${SO%.so}-aarch64"; PKG="${PKG//_/-}"
72+
VER="${{ inputs.version }}"
73+
74+
TMP=$(mktemp -d)
75+
DEB_ROOT="$TMP/deb"
76+
LIB_DIR="$DEB_ROOT/data/data/com.termux/files/usr/lib"
77+
mkdir -p "$LIB_DIR" "$DEB_ROOT/DEBIAN"
78+
cp "dist/$SO" "$LIB_DIR/"
79+
80+
SIZE=$(du -sk "$DEB_ROOT/data" 2>/dev/null | cut -f1)
81+
cat > "$DEB_ROOT/DEBIAN/control" << CTRL
82+
Package: $PKG
83+
Version: $VER
84+
Architecture: aarch64
85+
Maintainer: ClaudeCode-Termux
86+
Installed-Size: ${SIZE:-10}
87+
Description: $PKG (auto-built from ${{ inputs.repo }})
88+
CTRL
89+
cat "$DEB_ROOT/DEBIAN/control"
90+
91+
DEB="${PKG}_${VER}_aarch64.deb"
92+
dpkg-deb --root-owner-group -Zxz -b "$DEB_ROOT" "dist/$DEB"
93+
ls -lh "dist/$DEB"
94+
95+
# Push to apt-repo
96+
git config --global user.name "github-actions[bot]"
97+
git config --global user.email "actions@github.com"
98+
REPO_URL="https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
99+
if ! git clone --depth 1 -b apt-repo "$REPO_URL" apt_repo 2>/dev/null; then
100+
git clone --depth 1 "$REPO_URL" apt_repo
101+
cd apt_repo; git checkout --orphan apt-repo; git rm -rf .; git commit --allow-empty -m init; cd ..
102+
fi
103+
cd apt_repo; git checkout apt-repo
104+
mkdir -p pool; cp "../dist/$DEB" pool/
105+
dpkg-scanpackages --multiversion pool > Packages; gzip -9c Packages > Packages.gz
106+
git add -A
107+
if ! git diff --staged --quiet; then
108+
git commit -m "➕ $PKG v$VER"; git push origin apt-repo
109+
echo "✅ Pushed to apt-repo"
110+
else
111+
echo "⏭ Already exists"
112+
fi
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: Build Android ARM64 Rust
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
repo:
7+
description: 'GitHub repo (org/name) or crates.io name'
8+
required: true
9+
type: string
10+
binary:
11+
description: 'Binary name to install (empty = library .so)'
12+
required: false
13+
default: ''
14+
type: string
15+
features:
16+
description: 'Cargo features (comma-separated)'
17+
required: false
18+
default: ''
19+
type: string
20+
version:
21+
description: 'Package version'
22+
required: false
23+
default: '1.0'
24+
type: string
25+
26+
jobs:
27+
build:
28+
runs-on: ubuntu-latest
29+
permissions:
30+
contents: write
31+
steps:
32+
- name: Setup Rust + Android target
33+
run: |
34+
rustup default stable
35+
rustup target add aarch64-linux-android
36+
37+
- name: Setup Android NDK
38+
run: |
39+
NDK_VER="r29"
40+
curl -fsSL "https://dl.google.com/android/repository/android-ndk-${NDK_VER}-linux.zip" -o ndk.zip
41+
unzip -q ndk.zip
42+
echo "NDK_ROOT=$PWD/android-ndk-${NDK_VER}" >> $GITHUB_ENV
43+
echo "CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang" >> $GITHUB_ENV
44+
45+
- name: Checkout or cargo-install
46+
run: |
47+
REPO="${{ inputs.repo }}"
48+
# If it looks like a GitHub repo (org/name), clone it
49+
if echo "$REPO" | grep -q '/'; then
50+
git clone "https://github.com/${REPO}.git" src
51+
echo "BUILD_DIR=src" >> $GITHUB_ENV
52+
echo "PKG_NAME=$(basename $REPO)" >> $GITHUB_ENV
53+
else
54+
# It's a crate name — just note it for metadata
55+
echo "CRATE_NAME=$REPO" >> $GITHUB_ENV
56+
echo "BUILD_DIR=." >> $GITHUB_ENV
57+
echo "PKG_NAME=$REPO" >> $GITHUB_ENV
58+
fi
59+
60+
- name: Build
61+
env:
62+
CC_aarch64_linux_android: ${{ env.NDK_ROOT }}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang
63+
run: |
64+
set -e
65+
mkdir -p dist
66+
CARGO_FLAGS="--target aarch64-linux-android --release"
67+
if [ -n "${{ inputs.features }}" ]; then
68+
CARGO_FLAGS="$CARGO_FLAGS --features ${{ inputs.features }}"
69+
fi
70+
71+
cd "$BUILD_DIR"
72+
73+
if [ -n "${{ inputs.binary }}" ]; then
74+
# Build specific binary
75+
cargo build $CARGO_FLAGS --bin "${{ inputs.binary }}"
76+
cp "target/aarch64-linux-android/release/${{ inputs.binary }}" ../dist/
77+
elif [ -f Cargo.toml ] && grep -q 'cdylib\|dylib' Cargo.toml 2>/dev/null; then
78+
# Build cdylib (shared library)
79+
cargo build $CARGO_FLAGS --lib
80+
find target/aarch64-linux-android/release -name '*.so' -exec cp {} ../dist/ \;
81+
elif [ -d src ]; then
82+
# Default: try building the default binary
83+
cargo build $CARGO_FLAGS
84+
find target/aarch64-linux-android/release -maxdepth 1 -type f -executable -exec cp {} ../dist/ \;
85+
fi
86+
cd ..
87+
88+
echo "=== dist/ ==="
89+
ls -lh dist/
90+
91+
- name: Build .deb + push apt-repo
92+
run: |
93+
set -e
94+
BIN=$(ls dist/ | head -1)
95+
PKG="${{ env.PKG_NAME }}-aarch64"
96+
PKG="${PKG//_/-}"
97+
VER="${{ inputs.version }}"
98+
99+
TMP=$(mktemp -d)
100+
DEB_ROOT="$TMP/deb"
101+
BIN_DIR="$DEB_ROOT/data/data/com.termux/files/usr/bin"
102+
mkdir -p "$BIN_DIR" "$DEB_ROOT/DEBIAN"
103+
cp "dist/$BIN" "$BIN_DIR/"
104+
chmod +x "$BIN_DIR/$BIN"
105+
106+
SIZE=$(du -sk "$DEB_ROOT/data" 2>/dev/null | cut -f1)
107+
cat > "$DEB_ROOT/DEBIAN/control" << CTRL
108+
Package: $PKG
109+
Version: $VER
110+
Architecture: aarch64
111+
Maintainer: ClaudeCode-Termux
112+
Installed-Size: ${SIZE:-10}
113+
Description: $PKG (auto-built from ${{ inputs.repo }})
114+
CTRL
115+
cat "$DEB_ROOT/DEBIAN/control"
116+
117+
DEB="${PKG}_${VER}_aarch64.deb"
118+
dpkg-deb --root-owner-group -Zxz -b "$DEB_ROOT" "dist/$DEB"
119+
ls -lh "dist/$DEB"
120+
121+
git config --global user.name "github-actions[bot]"
122+
git config --global user.email "actions@github.com"
123+
REPO_URL="https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
124+
if ! git clone --depth 1 -b apt-repo "$REPO_URL" apt_repo 2>/dev/null; then
125+
git clone --depth 1 "$REPO_URL" apt_repo
126+
cd apt_repo; git checkout --orphan apt-repo; git rm -rf .; git commit --allow-empty -m init; cd ..
127+
fi
128+
cd apt_repo; git checkout apt-repo
129+
mkdir -p pool; cp "../dist/$DEB" pool/
130+
dpkg-scanpackages --multiversion pool > Packages; gzip -9c Packages > Packages.gz
131+
git add -A
132+
if ! git diff --staged --quiet; then
133+
git commit -m "➕ $PKG v$VER"; git push origin apt-repo
134+
echo "✅ Pushed to apt-repo"
135+
else
136+
echo "⏭ Already exists"
137+
fi

0 commit comments

Comments
 (0)