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