-
Notifications
You must be signed in to change notification settings - Fork 196
222 lines (199 loc) · 9.04 KB
/
build-android-static.yml
File metadata and controls
222 lines (199 loc) · 9.04 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
name: Build Android Musl Static
# One-off workflow to build and upload android musl static binaries
# for multiple architectures to an existing release.
#
# Supported architectures:
# aarch64 - native on ARM runner (existing)
# x86_64 - native on x86_64 runner
# armv7 - cross-compiled on x86_64 using musl.cc armv7l-linux-musleabihf toolchain
# x86 - cross-compiled on x86_64 using musl.cc i686-linux-musl toolchain
on:
workflow_dispatch:
inputs:
version:
description: 'Release tag (e.g., v1.0.0)'
required: true
ref:
description: 'Git ref to build from (default: tag)'
required: false
default: ''
permissions:
contents: write
jobs:
build-android:
name: build-${{ matrix.arch }}-android-static
runs-on: ${{ matrix.runner }}
container:
image: rust:alpine
strategy:
fail-fast: false
matrix:
include:
- arch: aarch64
runner: ubuntu-24.04-arm
artifact: aarch64-linux-android-musl
outline-atomics: true
- arch: x86_64
runner: ubuntu-latest
artifact: x86_64-linux-android-musl
outline-atomics: false
- arch: armv7
runner: ubuntu-latest
artifact: armv7-linux-android-musl
outline-atomics: true
- arch: x86
runner: ubuntu-latest
artifact: i686-linux-android-musl
outline-atomics: false
steps:
# aarch64: JS actions don't work in Alpine containers on ARM runners
- name: Checkout repository (aarch64 workaround)
if: matrix.arch == 'aarch64'
run: |
apk add --no-cache git
git config --global --add safe.directory /__w/rustnet/rustnet
git clone --depth 1 https://github.com/${{ github.repository }}.git .
git fetch --depth 1 origin tag "${{ inputs.version }}"
git checkout "${{ inputs.version }}"
- name: Checkout repository
if: matrix.arch != 'aarch64'
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
ref: ${{ inputs.version }}
- name: Install common dependencies
run: |
apk add --no-cache \
musl-dev pkgconfig build-base perl \
zlib-dev zlib-static \
clang llvm linux-headers github-cli curl
rustup component add rustfmt
# aarch64/x86_64: libpcap-dev provides a native static libpcap.
# zstd-static is required because Alpine's libpcap-dev links against zstd.
- name: Install libpcap (native)
if: matrix.arch == 'aarch64' || matrix.arch == 'x86_64'
run: apk add --no-cache libpcap-dev elfutils-dev zstd-dev zstd-static
# armv7: use zig cc as the cross-compiler (no external toolchain download needed).
# zig bundles musl libc for all targets, so no -l:libzstd.a needed.
- name: Install cross-compiler and libpcap (armv7)
if: matrix.arch == 'armv7'
run: |
rustup target add armv7-unknown-linux-musleabihf
apk add zig flex bison bash
# zig cc wrapper: cc-rs detects it as clang and passes --target=armv7-*
# which zig rejects (zig uses 'arm' not 'armv7'). Filter those args out.
printf '%s\n' \
'#!/bin/bash' \
'args=()' \
'for arg in "$@"; do' \
' case "$arg" in --target=*) ;; *) args+=("$arg") ;; esac' \
'done' \
'exec zig cc -target arm-linux-musleabihf "${args[@]}"' \
> /usr/local/bin/arm-linux-musleabihf-gcc
chmod +x /usr/local/bin/arm-linux-musleabihf-gcc
# libpcap is pinned by version + sha256 (Dependabot does not track
# tarballs fetched in run steps, so bump the URL and the hash together).
curl -fsSL --retry 3 --retry-delay 5 \
-o libpcap.tar.gz https://www.tcpdump.org/release/libpcap-1.10.5.tar.gz
echo "37ced90a19a302a7f32e458224a00c365c117905c2cd35ac544b6880a81488f0 libpcap.tar.gz" | sha256sum -c -
tar xzf libpcap.tar.gz
cd libpcap-1.10.5
CC=arm-linux-musleabihf-gcc \
./configure --host=arm-linux-musleabihf \
--disable-shared --enable-static \
--disable-usb --disable-dbus --disable-bluetooth --disable-remote \
--prefix=/arm-sysroot
make -j$(nproc) && make install
cd ..
# x86: use zig cc as the cross-compiler (no external toolchain download needed).
# zig bundles musl libc for all targets, so no -l:libzstd.a needed.
- name: Install cross-compiler and libpcap (x86/i686)
if: matrix.arch == 'x86'
run: |
rustup target add i686-unknown-linux-musl
apk add zig flex bison bash
# zig cc wrapper: cc-rs passes --target=i686-* which zig doesn't accept;
# filter those args and use -target x86-linux-musl instead.
printf '%s\n' \
'#!/bin/bash' \
'args=()' \
'for arg in "$@"; do' \
' case "$arg" in --target=*) ;; *) args+=("$arg") ;; esac' \
'done' \
'exec zig cc -target x86-linux-musl "${args[@]}"' \
> /usr/local/bin/i686-linux-musl-gcc
chmod +x /usr/local/bin/i686-linux-musl-gcc
# libpcap is pinned by version + sha256 (Dependabot does not track
# tarballs fetched in run steps, so bump the URL and the hash together).
curl -fsSL --retry 3 --retry-delay 5 \
-o libpcap.tar.gz https://www.tcpdump.org/release/libpcap-1.10.5.tar.gz
echo "37ced90a19a302a7f32e458224a00c365c117905c2cd35ac544b6880a81488f0 libpcap.tar.gz" | sha256sum -c -
tar xzf libpcap.tar.gz
cd libpcap-1.10.5
CC=i686-linux-musl-gcc \
./configure --host=i686-linux-musl \
--disable-shared --enable-static \
--disable-usb --disable-dbus --disable-bluetooth --disable-remote \
--prefix=/x86-sysroot
make -j$(nproc) && make install
cd ..
- name: Build static binary (aarch64)
if: matrix.arch == 'aarch64'
env:
CFLAGS: "-mno-outline-atomics"
CXXFLAGS: "-mno-outline-atomics"
RUSTFLAGS: "-C strip=symbols -C link-arg=-l:libzstd.a"
run: cargo build --release --no-default-features
- name: Build static binary (x86_64)
if: matrix.arch == 'x86_64'
env:
RUSTFLAGS: "-C strip=symbols -C link-arg=-l:libzstd.a"
run: cargo build --release --no-default-features
- name: Build static binary (armv7)
if: matrix.arch == 'armv7'
env:
# link-self-contained=no: let zig provide musl CRT (avoid duplicate _start
# when both Rust's self-contained crt1.o and zig's crt1.o are linked)
RUSTFLAGS: "-C strip=symbols -C link-self-contained=no"
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER: arm-linux-musleabihf-gcc
PKG_CONFIG_PATH: /arm-sysroot/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR: /arm-sysroot
PKG_CONFIG_ALLOW_CROSS: "1"
run: cargo build --release --target armv7-unknown-linux-musleabihf --no-default-features
- name: Build static binary (x86/i686)
if: matrix.arch == 'x86'
env:
RUSTFLAGS: "-C strip=symbols -C link-self-contained=no"
CARGO_TARGET_I686_UNKNOWN_LINUX_MUSL_LINKER: i686-linux-musl-gcc
PKG_CONFIG_PATH: /x86-sysroot/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR: /x86-sysroot
PKG_CONFIG_ALLOW_CROSS: "1"
run: cargo build --release --target i686-unknown-linux-musl --no-default-features
- name: Verify static linking
run: |
BIN="${{ (matrix.arch == 'armv7' && 'target/armv7-unknown-linux-musleabihf/release/rustnet') || (matrix.arch == 'x86' && 'target/i686-unknown-linux-musl/release/rustnet') || 'target/release/rustnet' }}"
file "$BIN"
file "$BIN" | grep -q "static.* linked" || \
(echo "ERROR: Binary is not statically linked" && exit 1)
- name: Create release archive
run: |
VERSION="${{ inputs.version }}"
ARTIFACT="${{ matrix.artifact }}"
case "${{ matrix.arch }}" in
armv7) BIN="target/armv7-unknown-linux-musleabihf/release/rustnet" ;;
x86) BIN="target/i686-unknown-linux-musl/release/rustnet" ;;
*) BIN="target/release/rustnet" ;;
esac
staging="rustnet-${VERSION}-${ARTIFACT}"
mkdir -p "$staging/assets"
cp "$BIN" "$staging/rustnet"
cp crates/rustnet-core/assets/services "$staging/assets/" 2>/dev/null || true
cp README.md "$staging/"
cp LICENSE "$staging/" 2>/dev/null || true
tar czf "$staging.tar.gz" "$staging"
- name: Upload to release
run: |
VERSION="${{ inputs.version }}"
ARCHIVE="rustnet-${VERSION}-${{ matrix.artifact }}.tar.gz"
gh release upload "$VERSION" "$ARCHIVE" --repo "${{ github.repository }}" --clobber
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}