Skip to content
This repository was archived by the owner on Oct 31, 2026. It is now read-only.

Commit aeba881

Browse files
committed
Separate vendor builds: scripts/build-vendors.sh, build-vendors.yml dispatch (pick vendors, force), weekly uses it for misses
1 parent c31a890 commit aeba881

8 files changed

Lines changed: 508 additions & 83 deletions

File tree

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
name: build-vendors
2+
3+
# Standalone vendor build: (re)build the Android natives
4+
# (libopentui, opencode-pty, librust_pty), verify them, and commit the result
5+
# back to vendor/. Manual dispatch only — pick which natives to build and
6+
# whether to rebuild them even when cached.
7+
#
8+
# The release workflow (build-weekly.yml) invokes scripts/build-vendors.sh
9+
# itself for cache misses; this workflow is the manual counterpart for new
10+
# native versions and forced rebuilds.
11+
on:
12+
workflow_dispatch:
13+
inputs:
14+
vendors:
15+
description: 'Which natives to build: all, libopentui, pty (comma combos allowed)'
16+
required: false
17+
default: 'all'
18+
force:
19+
description: 'Rebuild even if the vendor files already exist'
20+
required: false
21+
default: false
22+
type: boolean
23+
upstream_tag:
24+
description: 'Upstream tag to resolve native versions from (e.g. v2.0.24). Empty = use the version inputs below.'
25+
required: false
26+
default: ''
27+
opentui_version:
28+
description: 'libopentui version (empty = resolve from upstream_tag, else 0.5.14)'
29+
required: false
30+
default: ''
31+
pty_version:
32+
description: 'opencode-pty version (empty = resolve from upstream_tag, else 0.2.0)'
33+
required: false
34+
default: ''
35+
bun_pty_version:
36+
description: 'bun-pty version (empty = resolve from upstream_tag, else 0.4.9)'
37+
required: false
38+
default: ''
39+
40+
permissions:
41+
contents: write
42+
43+
env:
44+
ZIG_VERSION: 0.16.0
45+
NDK_VERSION: r28b
46+
NDK_DIR: /opt/android-ndk
47+
REPO_UPSTREAM: anomalyco/opencode
48+
49+
jobs:
50+
resolve:
51+
runs-on: ubuntu-24.04
52+
outputs:
53+
opentui_version: ${{ steps.ver.outputs.opentui_version }}
54+
pty_version: ${{ steps.ver.outputs.pty_version }}
55+
bun_pty_version: ${{ steps.ver.outputs.bun_pty_version }}
56+
steps:
57+
- name: Resolve native versions
58+
id: ver
59+
env:
60+
GH_TOKEN: ${{ github.token }}
61+
INPUT_TAG: ${{ inputs.upstream_tag }}
62+
INPUT_OPENTUI: ${{ inputs.opentui_version }}
63+
INPUT_PTY: ${{ inputs.pty_version }}
64+
INPUT_BUN_PTY: ${{ inputs.bun_pty_version }}
65+
run: |
66+
if [ -n "$INPUT_TAG" ]; then
67+
PKG=$(curl -fsSL "https://raw.githubusercontent.com/${REPO_UPSTREAM}/${INPUT_TAG}/package.json")
68+
CORE=$(curl -fsSL "https://raw.githubusercontent.com/${REPO_UPSTREAM}/${INPUT_TAG}/packages/core/package.json")
69+
OPENTUI_V=$(echo "$PKG" | python3 -c "import json,sys; d=json.load(sys.stdin); print(d['workspaces']['catalog']['@opentui/core'])")
70+
PTY_V=$(echo "$CORE" | python3 -c "import json,sys; d=json.load(sys.stdin); print(d['dependencies']['@opencode-ai/pty'])")
71+
BUN_PTY_V=$(echo "$CORE" | python3 -c "import json,sys; d=json.load(sys.stdin); print(d['dependencies']['bun-pty'])")
72+
fi
73+
# Single grouped write (SC2129). Explicit inputs win, then the
74+
# upstream resolution, then the currently-vendored versions.
75+
{
76+
echo "opentui_version=${INPUT_OPENTUI:-${OPENTUI_V:-0.5.14}}"
77+
echo "pty_version=${INPUT_PTY:-${PTY_V:-0.2.0}}"
78+
echo "bun_pty_version=${INPUT_BUN_PTY:-${BUN_PTY_V:-0.4.9}}"
79+
} >> "$GITHUB_OUTPUT"
80+
81+
build:
82+
needs: resolve
83+
runs-on: ubuntu-24.04
84+
timeout-minutes: 120
85+
env:
86+
OPENTUI_VERSION: ${{ needs.resolve.outputs.opentui_version }}
87+
PTY_VERSION: ${{ needs.resolve.outputs.pty_version }}
88+
BUN_PTY_VERSION: ${{ needs.resolve.outputs.bun_pty_version }}
89+
VENDORS: ${{ inputs.vendors }}
90+
FORCE: ${{ inputs.force }}
91+
steps:
92+
- name: Checkout repo
93+
uses: actions/checkout@v4
94+
95+
- name: Install host deps
96+
run: sudo apt-get update && sudo apt-get install -y wget unzip xz-utils binutils
97+
98+
- name: Check vendor cache
99+
id: plan
100+
run: |
101+
mkdir -p out
102+
bash scripts/build-vendors.sh --plan >> "$GITHUB_OUTPUT"
103+
104+
- name: Free runner disk (early)
105+
# NDK + Rust toolchains + cargo target dirs are GBs.
106+
run: |
107+
df -h / /tmp
108+
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/.ghcup \
109+
/opt/hostedtoolcache/CodeQL /usr/local/share/boost \
110+
/usr/share/swift /opt/microsoft
111+
sudo docker image prune --all --force 2>/dev/null || true
112+
df -h / /tmp
113+
114+
- name: Install Zig
115+
if: steps.plan.outputs.need_libopentui == 'true'
116+
run: |
117+
cd /tmp || exit
118+
wget -q "https://ziglang.org/download/${ZIG_VERSION}/zig-x86_64-linux-${ZIG_VERSION}.tar.xz" -O zig.tar.xz
119+
tar xf zig.tar.xz
120+
echo "/tmp/zig-x86_64-linux-${ZIG_VERSION}" >> "$GITHUB_PATH"
121+
export PATH="/tmp/zig-x86_64-linux-${ZIG_VERSION}:$PATH"
122+
zig version
123+
124+
- name: Install Android NDK
125+
if: steps.plan.outputs.need_libopentui == 'true' || steps.plan.outputs.need_pty == 'true'
126+
run: |
127+
if [ ! -d "$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64" ]; then
128+
cd /tmp || exit
129+
wget -q "https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-linux.zip" -O ndk.zip
130+
sudo mkdir -p /opt
131+
sudo unzip -q ndk.zip -d /opt/
132+
sudo mv "/opt/android-ndk-${NDK_VERSION}" "$NDK_DIR"
133+
fi
134+
135+
- name: Install Rust Android target
136+
if: steps.plan.outputs.need_pty == 'true'
137+
run: |
138+
rustup target add aarch64-linux-android
139+
rustc --version
140+
cargo --version
141+
142+
- name: Build vendors (commit back to vendor/)
143+
# New files are committed straight back to vendor/ (same job, no
144+
# loop: this workflow has no push trigger). Force rebuilds land as
145+
# new commits too. Built outputs are ELF-gated inside the script.
146+
env:
147+
REPO_ROOT: ${{ github.workspace }}
148+
run: bash scripts/build-vendors.sh --commit
149+
150+
- name: Upload staged natives
151+
uses: actions/upload-artifact@v4
152+
with:
153+
name: vendors-${{ needs.resolve.outputs.opentui_version }}-${{ needs.resolve.outputs.pty_version }}-${{ needs.resolve.outputs.bun_pty_version }}
154+
path: out/*
155+
if-no-files-found: warn

‎.github/workflows/build-weekly.yml‎

Lines changed: 16 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -124,42 +124,18 @@ jobs:
124124
sudo docker image prune --all --force 2>/dev/null || true
125125
df -h / /tmp
126126
127-
- name: Select renderer lib (vendored, or build)
128-
id: lib
127+
- name: Check vendor cache (or select vendors to build)
128+
id: vendors
129129
env:
130-
REPO_ROOT: ${{ github.workspace }}
130+
OPENTUI_VERSION: ${{ needs.resolve.outputs.opentui_version }}
131+
PTY_VERSION: ${{ needs.resolve.outputs.pty_version }}
132+
BUN_PTY_VERSION: ${{ needs.resolve.outputs.bun_pty_version }}
131133
run: |
132-
VENDOR="vendor/libopentui-${OPENTUI_VERSION}-android-aarch64.so"
133134
mkdir -p out
134-
if [ -f "$VENDOR" ]; then
135-
(cd vendor && sha256sum -c "libopentui-${OPENTUI_VERSION}-android-aarch64.so.sha256")
136-
cp -v "$VENDOR" out/libopentui.so
137-
echo "mode=vendored" >> "$GITHUB_OUTPUT"
138-
else
139-
echo "mode=build" >> "$GITHUB_OUTPUT"
140-
echo "no vendored lib for opentui ${OPENTUI_VERSION}, will build from source"
141-
fi
142-
143-
- name: Select PTY natives (vendored, or build)
144-
id: pty
145-
env:
146-
REPO_ROOT: ${{ github.workspace }}
147-
run: |
148-
mkdir -p out
149-
PTY_BIN="vendor/opencode-pty-${PTY_VERSION}-android-aarch64"
150-
RUSTPTY_SO="vendor/librust_pty-${BUN_PTY_VERSION}-android-aarch64.so"
151-
if [ -f "$PTY_BIN" ] && [ -f "$RUSTPTY_SO" ]; then
152-
(cd vendor && sha256sum -c "$(basename "$PTY_BIN").sha256" "$(basename "$RUSTPTY_SO").sha256")
153-
cp -v "$PTY_BIN" out/opencode-pty
154-
cp -v "$RUSTPTY_SO" out/librust_pty_arm64.so
155-
echo "mode=vendored" >> "$GITHUB_OUTPUT"
156-
else
157-
echo "mode=build" >> "$GITHUB_OUTPUT"
158-
echo "no vendored pty natives for pty ${PTY_VERSION} / bun-pty ${BUN_PTY_VERSION}, will build from source"
159-
fi
135+
bash scripts/build-vendors.sh --plan >> "$GITHUB_OUTPUT"
160136
161137
- name: Install Zig
162-
if: steps.lib.outputs.mode == 'build' || steps.pty.outputs.mode == 'build'
138+
if: steps.vendors.outputs.need_libopentui == 'true'
163139
run: |
164140
cd /tmp || exit
165141
wget -q "https://ziglang.org/download/${ZIG_VERSION}/zig-x86_64-linux-${ZIG_VERSION}.tar.xz" -O zig.tar.xz
@@ -169,7 +145,7 @@ jobs:
169145
zig version
170146
171147
- name: Install Android NDK
172-
if: steps.lib.outputs.mode == 'build' || steps.pty.outputs.mode == 'build'
148+
if: steps.vendors.outputs.need_libopentui == 'true' || steps.vendors.outputs.need_pty == 'true'
173149
run: |
174150
if [ ! -d "$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64" ]; then
175151
cd /tmp || exit
@@ -180,7 +156,7 @@ jobs:
180156
fi
181157
182158
- name: Install Rust Android target
183-
if: steps.pty.outputs.mode == 'build'
159+
if: steps.vendors.outputs.need_pty == 'true'
184160
run: |
185161
rustup target add aarch64-linux-android
186162
rustc --version
@@ -229,55 +205,19 @@ jobs:
229205
export PATH="$HOME/.bun/bin:$PATH"
230206
python3 scripts/patch-opentui-loader.py upstream
231207
232-
- name: Build libopentui.so (android, fallback when not vendored)
233-
if: steps.lib.outputs.mode == 'build'
234-
env:
235-
REPO_ROOT: ${{ github.workspace }}
236-
run: bash scripts/build-libopentui-ci.sh
237-
238-
- name: Vendor the built lib (commit back to repo)
239-
# First build for a new opentui version lands here; every later run
240-
# (weekly or manual) reuses vendor/ and skips the source build.
241-
# No push trigger on this workflow, so this cannot self-trigger.
242-
if: steps.lib.outputs.mode == 'build'
243-
run: |
244-
VENDOR="vendor/libopentui-${OPENTUI_VERSION}-android-aarch64.so"
245-
cp -v out/libopentui.so "$VENDOR"
246-
(cd vendor && sha256sum "$(basename "$VENDOR")" > "$(basename "$VENDOR").sha256")
247-
git config user.name "opencode-android-bot"
248-
git config user.email "opencode-android-bot@users.noreply.github.com"
249-
git add "$VENDOR" "$VENDOR.sha256"
250-
git commit -m "vendor libopentui ${OPENTUI_VERSION} android-aarch64 (CI-built)" || echo "nothing to commit"
251-
git push
252-
253-
- name: Build PTY natives (android, fallback when not vendored)
254-
if: steps.pty.outputs.mode == 'build'
208+
- name: Ensure vendors (stage cached, build missing, commit back)
209+
# Always runs: verifies + stages the vendored natives into out/, builds
210+
# whatever is missing from source, ELF-gates it, and commits new files
211+
# straight back to vendor/ (same job, no loop: this workflow has no
212+
# push trigger). Every later run reuses the committed files.
255213
env:
256214
REPO_ROOT: ${{ github.workspace }}
257-
run: bash scripts/build-pty-android-ci.sh
258-
259-
- name: Vendor the built PTY natives (commit back to repo)
260-
# First build for new pty/bun-pty versions lands here; every later run
261-
# reuses vendor/ and skips the source build.
262-
# No push trigger on this workflow, so this cannot self-trigger.
263-
if: steps.pty.outputs.mode == 'build'
264-
run: |
265-
PTY_BIN="vendor/opencode-pty-${PTY_VERSION}-android-aarch64"
266-
RUSTPTY_SO="vendor/librust_pty-${BUN_PTY_VERSION}-android-aarch64.so"
267-
cp -v out/opencode-pty "$PTY_BIN"
268-
cp -v out/librust_pty_arm64.so "$RUSTPTY_SO"
269-
(cd vendor && sha256sum "$(basename "$PTY_BIN")" > "$(basename "$PTY_BIN").sha256")
270-
(cd vendor && sha256sum "$(basename "$RUSTPTY_SO")" > "$(basename "$RUSTPTY_SO").sha256")
271-
git config user.name "opencode-android-bot"
272-
git config user.email "opencode-android-bot@users.noreply.github.com"
273-
git add "$PTY_BIN" "$PTY_BIN.sha256" "$RUSTPTY_SO" "$RUSTPTY_SO.sha256"
274-
git commit -m "vendor pty ${PTY_VERSION} + rust_pty ${BUN_PTY_VERSION} android-aarch64 (CI-built)" || echo "nothing to commit"
275-
git push
215+
run: bash scripts/build-vendors.sh --commit
276216

277217
- name: Clean Rust build dirs (early, before embed install)
278218
# cargo target/ dirs are GBs; the all-platform bun install below needs
279219
# room (workerd/darwin/win prebuilds). Final cleanup repeats this.
280-
if: steps.pty.outputs.mode == 'build'
220+
if: steps.vendors.outputs.need_pty == 'true'
281221
run: |
282222
rm -rf work/opencode-pty-*/target work/bun-pty-*/rust-pty/target ~/.cargo/registry/cache
283223
rm -f /tmp/ndk.zip /tmp/zig.tar.xz

‎Makefile‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,26 @@
99
# make test [TEST=install]
1010
# make lint
1111
# make check-vendor
12+
# make vendors [VENDORS=all|libopentui|pty] [FORCE=0|1]
1213
# make package UPSTREAM_TAG=v2.0.24 [WORKSPACE=...] [WORK=...] [OUT=...]
1314
# make clean
1415

1516
TEST ?=
1617
UPSTREAM_TAG ?=
18+
VENDORS ?= all
19+
FORCE ?= 0
1720
WORKSPACE ?= $(CURDIR)
1821
WORK ?= $(CURDIR)/work
1922
OUT ?= $(CURDIR)/out
2023

21-
.PHONY: help test lint check-vendor package clean
24+
.PHONY: help test lint check-vendor vendors package clean
2225

2326
help:
2427
@echo "Targets:"
2528
@echo " test run the bats suite (TEST=<suite> for one suite)"
2629
@echo " lint shellcheck scripts + actionlint workflows (if installed)"
2730
@echo " check-vendor golden checksum + ELF gates for vendor/ natives"
31+
@echo " vendors verify/stage vendor cache (VENDORS=..., FORCE=1 rebuilds)"
2832
@echo " package build zip/deb/pacman from a prebuilt CLI (needs UPSTREAM_TAG)"
2933
@echo " clean remove work/, out/, upstream/, dist/ (generated dirs)"
3034

@@ -38,6 +42,9 @@ lint:
3842
check-vendor:
3943
bash tests/run.sh vendor
4044

45+
vendors:
46+
VENDORS="$(VENDORS)" FORCE="$(FORCE)" WORKSPACE="$(WORKSPACE)" WORK="$(WORK)" OUT="$(OUT)" bash scripts/build-vendors.sh
47+
4148
package:
4249
@if [ -z "$(UPSTREAM_TAG)" ]; then echo "usage: make package UPSTREAM_TAG=v2.0.24" >&2; exit 1; fi
4350
UPSTREAM_TAG="$(UPSTREAM_TAG)" WORKSPACE="$(WORKSPACE)" WORK="$(WORK)" OUT="$(OUT)" bash scripts/package.sh

‎README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ Fast, local stages work anywhere via `make` (`make help` lists targets):
158158
make test # bats suite (TEST=install for one suite)
159159
make lint # shellcheck (+ actionlint if installed)
160160
make check-vendor # golden checksum + ELF gates for vendor/
161+
make vendors # verify vendor cache, stage natives into out/
161162
make package UPSTREAM_TAG=v2.0.24 # zip/deb/pacman from a prebuilt CLI
162163
make clean # remove work/, out/, upstream/, dist/
163164
```
@@ -169,6 +170,20 @@ make clean # remove work/, out/, upstream/, dist/
169170
dpkg-dev xz-utils` on Debian/Ubuntu). It fails clearly when the binary or
170171
`UPSTREAM_TAG` is missing.
171172

173+
Vendor rebuilds (`scripts/build-vendors.sh`, also via `make vendors`) reuse
174+
the `vendor/` cache per native version and only build what is missing:
175+
176+
```sh
177+
make vendors VENDORS=pty FORCE=1 # rebuild pty natives (needs cargo + NDK)
178+
```
179+
180+
Rebuilding from source needs Zig 0.16 + NDK r28 (renderer) or cargo +
181+
NDK r28 (PTY); without `--commit` nothing is written back. Committing new
182+
vendor files happens in CI: the release workflow builds missing natives
183+
itself, and `.github/workflows/build-vendors.yml` (manual dispatch: pick
184+
`vendors`, set `force`, optionally resolve versions from `upstream_tag`)
185+
is the manual counterpart.
186+
172187
The full native build (upstream clone → patches → Zig/NDK renderer +
173188
cargo/NDK PTY natives → Bun compile → package → release) runs in CI on
174189
Linux x86_64 — see [`.github/workflows/build-weekly.yml`](.github/workflows/build-weekly.yml).

0 commit comments

Comments
 (0)