Skip to content

Commit d707609

Browse files
authored
chore(ci): build the Rust client for every target (#66152)
1 parent 93e3b62 commit d707609

3 files changed

Lines changed: 183 additions & 1 deletion

File tree

‎.github/workflows/check-cli-rs.yml‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: check-cli-rs
2+
3+
# Checks packages/cli-rs, the Rust client, which check-test.yml leaves out. Pull requests run it only when they change
4+
# the client. Its tests and check:drift also compare it with the TypeScript packages below, so a dev push that changes
5+
# one runs it too: a TypeScript change that breaks the client shows on dev, not on other teams' pull requests.
6+
on:
7+
pull_request:
8+
paths:
9+
- packages/cli-rs/**
10+
- .github/workflows/check-cli-rs.yml
11+
push:
12+
branches: [dev]
13+
paths:
14+
- packages/cli-rs/**
15+
- packages/cli/src/**
16+
- packages/client/**
17+
- packages/plugin/**
18+
- packages/protocol/**
19+
- packages/schema/**
20+
- packages/theme/**
21+
- packages/tui/**
22+
- packages/util/**
23+
- bun.lock
24+
- .github/workflows/check-cli-rs.yml
25+
workflow_dispatch:
26+
27+
permissions:
28+
contents: read
29+
30+
concurrency:
31+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
32+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
33+
34+
jobs:
35+
check:
36+
runs-on: blacksmith-4vcpu-ubuntu-2404
37+
timeout-minutes: 45
38+
defaults:
39+
run:
40+
working-directory: packages/cli-rs
41+
steps:
42+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
43+
# Bun and node_modules: the tests and check:drift run the TypeScript side they compare against.
44+
- uses: ./.github/actions/setup-bun
45+
# rustup reads rust-toolchain.toml; `bun run cargo` first fetches OpenTUI's native library from its release.
46+
- run: rustup toolchain install
47+
- run: bun run cargo fmt --check
48+
- run: bun run cargo clippy --locked --workspace --all-targets -- -D warnings
49+
# Every crate's tests, even after one fails, so one run shows every failure.
50+
- run: bun run cargo test --locked --workspace --no-fail-fast
51+
- run: bun run check:drift
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: cli-rs release
2+
3+
# Builds opencode-native, the Rust client in packages/cli-rs, natively on each runner below and keeps each archive as an
4+
# artifact. A cli-rs-v<version> tag also publishes them as a GitHub release. It never becomes Latest: the monorepo's
5+
# Latest release drives OpenCode's own update paths.
6+
on:
7+
push:
8+
tags:
9+
- "cli-rs-v*"
10+
pull_request:
11+
paths:
12+
- .github/workflows/release-cli-rs.yml
13+
workflow_dispatch:
14+
15+
permissions:
16+
contents: read
17+
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.ref }}
20+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
21+
22+
jobs:
23+
build:
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
include:
28+
# Zig links Linux against glibc 2.17, OpenTUI's floor. zig_sha is the archive's, from ziglang.org.
29+
- runner: ubuntu-24.04
30+
target: x86_64-unknown-linux-gnu
31+
zig: x86_64-linux-gnu.2.17
32+
zig_sha: 3581863e3cbcfd0fce0efc682ce7e9e93da96668a977791d356a26d2a7e9b17a
33+
- runner: ubuntu-24.04-arm
34+
target: aarch64-unknown-linux-gnu
35+
zig: aarch64-linux-gnu.2.17
36+
zig_sha: a1546d5646eb184437918d6635ca6b762a0e889eac09cef720ee7a1ed3fe7795
37+
- { runner: macos-15-intel, target: x86_64-apple-darwin }
38+
- { runner: macos-15, target: aarch64-apple-darwin }
39+
- { runner: windows-2025, target: x86_64-pc-windows-msvc, exe: .exe }
40+
runs-on: ${{ matrix.runner }}
41+
timeout-minutes: 60
42+
defaults:
43+
run:
44+
shell: bash
45+
working-directory: packages/cli-rs
46+
env:
47+
OPENCODE_NATIVE_COMMIT: ${{ github.sha }}
48+
CARGO_PROFILE_DIST_STRIP: symbols
49+
MACOSX_DEPLOYMENT_TARGET: "13.0"
50+
# No Visual C++ runtime to install beside the .exe.
51+
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS: -C target-feature=+crt-static
52+
steps:
53+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
54+
with:
55+
persist-credentials: false
56+
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
57+
with:
58+
bun-version-file: package.json
59+
# The version opencode-native --version prints: the tag's, or 0.0.0-<commit> for any other run.
60+
- name: Version
61+
run: |
62+
version=0.0.0-$GITHUB_SHA
63+
if [[ $GITHUB_REF == refs/tags/cli-rs-v* ]]; then version=${GITHUB_REF_NAME#cli-rs-v}; fi
64+
echo "OPENCODE_VERSION=$version" >> "$GITHUB_ENV"
65+
# Zig 0.17.1 as the C and C++ compiler and the linker. The wrapper drops flags zig rejects: cc's --target, and
66+
# rustc's Cortex-A53 erratum fix on aarch64.
67+
- if: matrix.zig
68+
working-directory: ${{ runner.temp }}
69+
run: |
70+
file=zig-$(uname -m)-linux-0.17.1
71+
curl -fsSL --retry 3 -o zig.tar.xz "https://ziglang.org/download/0.17.1/$file.tar.xz"
72+
echo "${{ matrix.zig_sha }} zig.tar.xz" | sha256sum -c
73+
tar -xJf zig.tar.xz
74+
for tool in cc c++; do
75+
cat > "zig-$tool" <<EOF
76+
#!/bin/sh
77+
for a; do shift; case \$a in --target=*|-Wl,--fix-cortex-a53-843419) ;; *) set -- "\$@" "\$a" ;; esac; done
78+
exec "$PWD/$file/zig" $tool -target ${{ matrix.zig }} "\$@"
79+
EOF
80+
chmod +x "zig-$tool"
81+
done
82+
triple=$(tr a-z- A-Z_ <<< "${{ matrix.target }}")
83+
{ echo "CARGO_TARGET_${triple}_LINKER=$PWD/zig-cc"; echo "CC_${triple,,}=$PWD/zig-cc"
84+
echo "CXX_${triple,,}=$PWD/zig-c++"; echo "CXXSTDLIB_${triple,,}=c++"; } >> "$GITHUB_ENV"
85+
# rustup reads rust-toolchain.toml; `bun run cargo` first fetches OpenTUI's native library from its release.
86+
- run: rustup toolchain install
87+
- run: bun run cargo build --locked --profile dist --bin opencode-native
88+
- name: Check glibc 2.17 and no libstdc++
89+
if: matrix.zig
90+
run: "! readelf -dV target/dist/opencode-native | grep -E 'GLIBC_2\\.(1[89]|[2-9][0-9])|libstdc\\+\\+'"
91+
- name: Package
92+
run: |
93+
name=opencode-native-$OPENCODE_VERSION-${{ matrix.target }}
94+
mkdir -p "dist/$name"
95+
cp "target/dist/opencode-native${{ matrix.exe }}" "dist/$name/"
96+
# Our licence, and OpenTUI's licences (FFmpeg's among them) from its native release zip.
97+
cp ../../LICENSE "dist/$name/"
98+
cp -r .opentui/*/host/licenses "dist/$name/"
99+
tar -C dist -czf "dist/$name.tar.gz" "$name"
100+
ls -l "dist/$name" "dist/$name.tar.gz"
101+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
102+
with:
103+
name: opencode-native-${{ matrix.target }}
104+
path: packages/cli-rs/dist/*.tar.gz
105+
if-no-files-found: error
106+
compression-level: 0
107+
108+
release:
109+
needs: build
110+
if: startsWith(github.ref, 'refs/tags/cli-rs-v')
111+
runs-on: ubuntu-24.04
112+
permissions:
113+
contents: write
114+
steps:
115+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
116+
with:
117+
pattern: opencode-native-*
118+
merge-multiple: true
119+
- name: Publish
120+
env:
121+
GH_TOKEN: ${{ github.token }}
122+
run: |
123+
sha256sum ./*.tar.gz > SHA256SUMS
124+
gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --verify-tag --latest=false \
125+
--title "opencode-native ${GITHUB_REF_NAME#cli-rs-v}" --notes "The Rust client (packages/cli-rs) at $GITHUB_SHA." \
126+
./*.tar.gz SHA256SUMS

‎packages/cli-rs/AGENTS.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ say "native"; crates, this directory, and `OPENCODE_RS_*` variables say "rs".
1414

1515
## Checks
1616

17-
Before merging, the whole package must pass:
17+
CI (`.github/workflows/check-cli-rs.yml`) runs:
1818

1919
- `bun run cargo fmt --check`
2020
- `bun run cargo clippy --locked --workspace --all-targets -- -D warnings`
2121
- `bun run cargo test --locked --workspace --no-fail-fast`
2222
- `bun run check:drift`
23+
24+
CI has no `opencode` binary, so a few tests that need one skip. Before merging, also run these locally:
25+
26+
- `OPENCODE_RS_REQUIRE_TS=1 bun run cargo test --locked --workspace --no-fail-fast`, with an `opencode` binary on
27+
`PATH`. Then the TypeScript interop tests fail instead of skipping.
2328
- `bun run parity:machines`
2429

2530
Each of `opencode-tui` and `opencode-ui` has one integration test binary, `tests/all/main.rs`, with one module per

0 commit comments

Comments
 (0)