Repository navigation
343 lines (308 loc) · 12.8 KB
/
Copy pathbuild.yml
File metadata and controls
343 lines (308 loc) · 12.8 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
name: Build OpenCode for Android/Termux
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
opencode_version:
description: 'OpenCode version to build'
required: false
default: '1.3.13'
env:
BUN_VERSION: "1.2.13"
OPENCODE_VERSION: "1.3.13"
ANDROID_API: "24"
ANDROID_NDK_VERSION: "28.1.13356709"
WEBKIT_COMMIT: "017930ebf915121f8f593bef61cbbca82d78132d"
TINYCC_COMMIT: "b91835d8701523e895a2b447713630069514e291"
ICU_VERSION: "75.1"
ZIG_VERSION: "0.15.2"
# golem10 has 15GB RAM — limit parallelism to avoid OOM during WebKit link
JOBS: "4"
# Use the large spindle drive for working directory
WORK_DIR: "/mnt/spindrive/opencode-build"
jobs:
build:
name: Build Android aarch64
runs-on: self-hosted
timeout-minutes: 360 # 6 hours for full build
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Override OpenCode version from input
if: github.event.inputs.opencode_version
run: echo "OPENCODE_VERSION=${{ github.event.inputs.opencode_version }}" >> $GITHUB_ENV
- name: Create work directory
run: |
mkdir -p "$WORK_DIR"
echo "Work directory: $WORK_DIR"
df -h /mnt/spindrive
# =============================================
# Install build dependencies
# =============================================
- name: Install system packages
run: |
sudo apt-get update
sudo apt-get install -y \
ninja-build python3 ruby perl \
git curl wget unzip xz-utils zip \
build-essential pkg-config \
libxml2-dev libxslt1-dev \
golang-go \
autoconf automake libtool
- name: Install CMake 3.28+
run: |
# Ubuntu 22.04 ships CMake 3.22 but Bun needs 3.24+
CMAKE_VER="3.28.6"
if cmake --version 2>/dev/null | grep -q "3\.2[89]\|3\.[3-9]"; then
echo "CMake already new enough: $(cmake --version | head -1)"
else
echo "Installing CMake ${CMAKE_VER}..."
cd /tmp
wget -q "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-linux-x86_64.tar.gz" -O cmake.tar.gz
sudo tar xzf cmake.tar.gz -C /opt/
sudo ln -sf "/opt/cmake-${CMAKE_VER}-linux-x86_64/bin/cmake" /usr/local/bin/cmake
sudo ln -sf "/opt/cmake-${CMAKE_VER}-linux-x86_64/bin/ctest" /usr/local/bin/ctest
sudo ln -sf "/opt/cmake-${CMAKE_VER}-linux-x86_64/bin/cpack" /usr/local/bin/cpack
rm cmake.tar.gz
fi
cmake --version
- name: Install Android NDK r28b
run: |
NDK_DIR="/opt/android-ndk"
if [ -d "$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64" ]; then
echo "NDK already installed at $NDK_DIR"
else
echo "Downloading Android NDK r28b..."
cd /tmp
wget -q "https://dl.google.com/android/repository/android-ndk-r28b-linux.zip" -O ndk.zip
sudo mkdir -p /opt
sudo unzip -q ndk.zip -d /opt/
sudo mv /opt/android-ndk-r28b "$NDK_DIR"
rm ndk.zip
fi
echo "ANDROID_NDK_HOME=$NDK_DIR" >> $GITHUB_ENV
echo "$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
- name: Install Rust with Android target
run: |
if ! command -v rustup &>/dev/null; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
source "$HOME/.cargo/env"
fi
rustup target add aarch64-linux-android
- name: Install Zig 0.15.2
run: |
ZIG_DIR="$WORK_DIR/zig-${ZIG_VERSION}"
if [ -x "$ZIG_DIR/zig" ]; then
echo "Zig already installed at $ZIG_DIR"
else
echo "Downloading Zig ${ZIG_VERSION}..."
cd /tmp
wget -q "https://ziglang.org/download/${ZIG_VERSION}/zig-x86_64-linux-${ZIG_VERSION}.tar.xz" -O zig.tar.xz
mkdir -p "$ZIG_DIR"
tar xf zig.tar.xz -C "$ZIG_DIR" --strip-components=1
rm zig.tar.xz
fi
echo "ZIG_BIN=$ZIG_DIR/zig" >> $GITHUB_ENV
echo "$ZIG_DIR" >> $GITHUB_PATH
- name: Install Bun (host, pinned for module graph compatibility)
run: |
# CRITICAL: The host Bun version must produce a module graph format
# compatible with the target Bun (v1.2.13).
#
# The standalone binary's CompiledModuleGraphFile struct changed:
# - Bun <= 1.3.2: 36-byte stride (compatible with 1.2.x target)
# - Bun >= 1.3.11: 52-byte stride (INCOMPATIBLE — causes OOM)
#
# We can't use 1.2.13 as host because it lacks catalog: workspace
# protocol support needed by OpenCode's monorepo. Pin to 1.3.2.
HOST_BUN_VERSION="1.3.2"
GOT="$(bun --version 2>/dev/null || true)"
if [ "$GOT" != "$HOST_BUN_VERSION" ]; then
echo "Installing Bun v${HOST_BUN_VERSION} (current: ${GOT:-none})..."
curl -fsSL https://bun.sh/install | bash -s "bun-v${HOST_BUN_VERSION}"
echo "$HOME/.bun/bin" >> $GITHUB_PATH
export PATH="$HOME/.bun/bin:$PATH"
fi
echo "Host Bun version: $(bun --version)"
echo "Target Bun version: $BUN_VERSION"
# =============================================
# Cache expensive build artifacts
# =============================================
- name: Compute patch hashes
id: hashes
run: |
BUN_PATCH_HASH=$(sha256sum patches/bun/android-support.patch | cut -c1-16)
WEBKIT_PATCH_HASH=$(sha256sum patches/webkit/android-support.patch | cut -c1-16)
ZIG_PATCH_HASH=$(sha256sum patches/zig/posix-android-sigaction.patch | cut -c1-16)
echo "bun_patch_hash=$BUN_PATCH_HASH" >> $GITHUB_OUTPUT
echo "webkit_patch_hash=$WEBKIT_PATCH_HASH" >> $GITHUB_OUTPUT
echo "zig_patch_hash=$ZIG_PATCH_HASH" >> $GITHUB_OUTPUT
- name: Cache ICU build
id: cache-icu
uses: actions/cache@v4
with:
path: ${{ env.WORK_DIR }}/deps-android/prefix
key: icu-android-${{ env.ICU_VERSION }}-${{ env.ANDROID_API }}
- name: Cache WebKit build
id: cache-webkit
uses: actions/cache@v4
with:
path: ${{ env.WORK_DIR }}/webkit-android
key: webkit-android-${{ env.WEBKIT_COMMIT }}-${{ steps.hashes.outputs.webkit_patch_hash }}
- name: Cache Bun binary
id: cache-bun
uses: actions/cache@v4
with:
path: ${{ env.WORK_DIR }}/bun-build/bun
key: bun-android-${{ env.BUN_VERSION }}-${{ steps.hashes.outputs.bun_patch_hash }}-${{ steps.hashes.outputs.zig_patch_hash }}
# =============================================
# Clone and patch sources
# =============================================
- name: Clone and patch Bun + WebKit
if: steps.cache-bun.outputs.cache-hit != 'true' || steps.cache-webkit.outputs.cache-hit != 'true'
run: |
source scripts/env.sh
./scripts/apply-patches.sh
# =============================================
# Build ICU
# =============================================
- name: Build ICU 75.1
if: steps.cache-icu.outputs.cache-hit != 'true'
run: |
source scripts/env.sh
./scripts/build-icu.sh
# =============================================
# Build WebKit/JSC
# =============================================
- name: Build WebKit/JSC
if: steps.cache-webkit.outputs.cache-hit != 'true'
run: |
source scripts/env.sh
./scripts/build-webkit.sh
# =============================================
# Build TinyCC (libtcc.a)
# =============================================
- name: Build TinyCC
if: steps.cache-bun.outputs.cache-hit != 'true'
run: |
source scripts/env.sh
./scripts/build-tinycc.sh
# =============================================
# Build Bun
# =============================================
- name: Build Bun
if: steps.cache-bun.outputs.cache-hit != 'true'
run: |
source scripts/env.sh
# Need to clone + patch if only bun cache missed but webkit didn't
if [ ! -d "$BUN_SRC/.git" ]; then
./scripts/apply-patches.sh
fi
./scripts/build-bun.sh
- name: Verify Bun binary
run: |
BUN_BINARY="${WORK_DIR}/bun-build/bun"
echo "Bun binary: $BUN_BINARY"
ls -lh "$BUN_BINARY"
file "$BUN_BINARY"
readelf -h "$BUN_BINARY" | grep -E "Machine|Class"
# =============================================
# Build libopentui.so
# =============================================
- name: Build libopentui.so
run: |
source scripts/env.sh
./scripts/build-opentui.sh
# =============================================
# Build OpenCode standalone binary
# =============================================
- name: Build OpenCode standalone binary
run: |
source scripts/env.sh
./scripts/build-opencode.sh
- name: Verify OpenCode binary
run: |
OPENCODE_BINARY="${WORK_DIR}/dist/opencode"
echo "OpenCode binary: $OPENCODE_BINARY"
ls -lh "$OPENCODE_BINARY"
file "$OPENCODE_BINARY"
readelf -h "$OPENCODE_BINARY" | grep -E "Machine|Class"
# =============================================
# Create packages
# =============================================
- name: Create distribution packages
run: |
source scripts/env.sh
./scripts/make-packages.sh
- name: List packages
run: |
echo "=== Built packages ==="
ls -lh "${WORK_DIR}/packages/"
# =============================================
# Upload artifacts
# =============================================
- name: Upload packages as artifacts
uses: actions/upload-artifact@v4
with:
name: opencode-termux-${{ env.OPENCODE_VERSION }}
path: |
${{ env.WORK_DIR }}/packages/*.zip
${{ env.WORK_DIR }}/packages/*.pkg.tar.xz
${{ env.WORK_DIR }}/packages/*.deb
# =============================================
# Release (only on tag push)
# =============================================
- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v2
with:
files: |
${{ env.WORK_DIR }}/packages/*.zip
${{ env.WORK_DIR }}/packages/*.pkg.tar.xz
${{ env.WORK_DIR }}/packages/*.deb
body: |
## OpenCode ${{ env.OPENCODE_VERSION }} for Android/Termux (aarch64)
### Installation
**Termux (pacman):**
```bash
# Download the .pkg.tar.xz file, then:
pacman -U opencode-${{ env.OPENCODE_VERSION }}-1-aarch64.pkg.tar.xz
```
**Termux (dpkg):**
```bash
# Download the .deb file, then:
dpkg -i opencode_${{ env.OPENCODE_VERSION }}_aarch64.deb
```
**Standalone binary:**
```bash
# Download and extract the .zip, then:
chmod +x opencode
mv opencode $PREFIX/bin/
```
### Build info
- Bun: v${{ env.BUN_VERSION }} (cross-compiled for Android aarch64)
- WebKit/JSC: ${{ env.WEBKIT_COMMIT }}
- ICU: ${{ env.ICU_VERSION }}
- Android API level: ${{ env.ANDROID_API }}
- NDK: r28b (${{ env.ANDROID_NDK_VERSION }})
draft: false
prerelease: false
# =============================================
# Cleanup (keep cache, remove intermediates)
# =============================================
- name: Cleanup intermediate files
if: always()
run: |
# Remove source trees (they can be re-cloned) but keep cached artifacts
rm -rf "${WORK_DIR}/bun-src" "${WORK_DIR}/webkit-src" "${WORK_DIR}/opentui-src" "${WORK_DIR}/opencode-src"
rm -rf "${WORK_DIR}/icu-src" "${WORK_DIR}/icu-host-build" "${WORK_DIR}/icu-android-build"
rm -rf "${WORK_DIR}/webkit-build"
# Clear Zig cache when bun-src is removed — the cache references files
# in vendor/zig/ which lives inside bun-src. Stale references cause
# FileNotFound errors in the translate-c output cache.
rm -rf "${WORK_DIR}/bun-build/cache/zig"
echo "Cleaned up intermediate files"
df -h /mnt/spindrive