Skip to content

Commit f54743f

Browse files
author
Marvin Zhang
committed
feat: Add GitHub Actions workflow for building Rust binaries and update README status to in-progress
1 parent 9ccf7f8 commit f54743f

File tree

2 files changed

+270
-3
lines changed

2 files changed

+270
-3
lines changed
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
name: Build Rust Binaries
2+
3+
on:
4+
# Trigger on version tags
5+
push:
6+
tags:
7+
- 'v*.*.*'
8+
9+
# Manual trigger for testing/debugging
10+
workflow_dispatch:
11+
inputs:
12+
publish:
13+
description: 'Publish to npm after building'
14+
required: false
15+
type: boolean
16+
default: false
17+
debug:
18+
description: 'Enable debug logging'
19+
required: false
20+
type: boolean
21+
default: false
22+
23+
env:
24+
CARGO_TERM_COLOR: always
25+
26+
jobs:
27+
build:
28+
name: Build ${{ matrix.target }}
29+
runs-on: ${{ matrix.os }}
30+
31+
strategy:
32+
fail-fast: false # Continue other builds if one fails
33+
matrix:
34+
include:
35+
# macOS Intel
36+
- os: macos-latest
37+
target: x86_64-apple-darwin
38+
platform: darwin-x64
39+
40+
# macOS Apple Silicon
41+
- os: macos-latest
42+
target: aarch64-apple-darwin
43+
platform: darwin-arm64
44+
45+
# Linux x64
46+
- os: ubuntu-latest
47+
target: x86_64-unknown-linux-gnu
48+
platform: linux-x64
49+
50+
# Linux ARM64 (cross-compile)
51+
- os: ubuntu-latest
52+
target: aarch64-unknown-linux-gnu
53+
platform: linux-arm64
54+
55+
# Windows x64
56+
- os: windows-latest
57+
target: x86_64-pc-windows-msvc
58+
platform: windows-x64
59+
60+
steps:
61+
- uses: actions/checkout@v4
62+
63+
# Enable debug logging if requested
64+
- name: Enable debug logging
65+
if: inputs.debug
66+
run: echo "CARGO_LOG=debug" >> $GITHUB_ENV
67+
shell: bash
68+
69+
# Setup Rust toolchain
70+
- name: Install Rust
71+
uses: dtolnay/rust-toolchain@stable
72+
with:
73+
targets: ${{ matrix.target }}
74+
75+
# Cache Rust dependencies
76+
- name: Cache cargo registry
77+
uses: actions/cache@v4
78+
with:
79+
path: ~/.cargo/registry
80+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
81+
restore-keys: |
82+
${{ runner.os }}-cargo-registry-
83+
84+
- name: Cache cargo index
85+
uses: actions/cache@v4
86+
with:
87+
path: ~/.cargo/git
88+
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
89+
restore-keys: |
90+
${{ runner.os }}-cargo-index-
91+
92+
- name: Cache cargo build
93+
uses: actions/cache@v4
94+
with:
95+
path: rust/target
96+
key: ${{ runner.os }}-${{ matrix.target }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
97+
restore-keys: |
98+
${{ runner.os }}-${{ matrix.target }}-cargo-build-
99+
100+
# Linux ARM64: Install cross-compilation tools
101+
- name: Install cross-compilation tools (Linux ARM64)
102+
if: matrix.target == 'aarch64-unknown-linux-gnu'
103+
run: |
104+
sudo apt-get update
105+
sudo apt-get install -y gcc-aarch64-linux-gnu
106+
107+
# Configure Cargo linker
108+
mkdir -p ~/.cargo
109+
echo "[target.aarch64-unknown-linux-gnu]" >> ~/.cargo/config.toml
110+
echo 'linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml
111+
112+
# Build binaries
113+
- name: Build CLI binary
114+
working-directory: rust
115+
run: cargo build --release --target ${{ matrix.target }} --package leanspec-cli
116+
117+
- name: Build MCP binary
118+
working-directory: rust
119+
run: cargo build --release --target ${{ matrix.target }} --package leanspec-mcp
120+
121+
# Debug: Show build artifacts
122+
- name: Debug - List build artifacts
123+
if: inputs.debug
124+
shell: bash
125+
run: |
126+
echo "=== Build artifacts ==="
127+
ls -la rust/target/${{ matrix.target }}/release/
128+
129+
# Prepare artifacts
130+
- name: Prepare artifacts
131+
shell: bash
132+
run: |
133+
mkdir -p dist/${{ matrix.platform }}
134+
135+
# Copy CLI binary
136+
if [ "${{ runner.os }}" = "Windows" ]; then
137+
cp rust/target/${{ matrix.target }}/release/lean-spec.exe dist/${{ matrix.platform }}/
138+
else
139+
cp rust/target/${{ matrix.target }}/release/lean-spec dist/${{ matrix.platform }}/
140+
fi
141+
142+
# Copy MCP binary
143+
if [ "${{ runner.os }}" = "Windows" ]; then
144+
cp rust/target/${{ matrix.target }}/release/leanspec-mcp.exe dist/${{ matrix.platform }}/
145+
else
146+
cp rust/target/${{ matrix.target }}/release/leanspec-mcp dist/${{ matrix.platform }}/
147+
fi
148+
149+
# Generate checksums
150+
cd dist/${{ matrix.platform }}
151+
if [ "${{ runner.os }}" = "Windows" ]; then
152+
certutil -hashfile lean-spec.exe SHA256 > lean-spec.exe.sha256
153+
certutil -hashfile leanspec-mcp.exe SHA256 > leanspec-mcp.exe.sha256
154+
else
155+
shasum -a 256 lean-spec > lean-spec.sha256
156+
shasum -a 256 leanspec-mcp > leanspec-mcp.sha256
157+
fi
158+
159+
# Debug: Show prepared artifacts
160+
echo "=== Prepared artifacts ==="
161+
ls -la
162+
163+
# Upload artifacts
164+
- name: Upload artifacts
165+
uses: actions/upload-artifact@v4
166+
with:
167+
name: binaries-${{ matrix.platform }}
168+
path: dist/${{ matrix.platform }}
169+
retention-days: 30
170+
171+
# Publish to npm (optional, requires secrets)
172+
publish:
173+
name: Publish to npm
174+
needs: build
175+
runs-on: ubuntu-latest
176+
if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || inputs.publish
177+
178+
steps:
179+
- uses: actions/checkout@v4
180+
181+
# Download all artifacts
182+
- name: Download artifacts
183+
uses: actions/download-artifact@v4
184+
with:
185+
path: dist
186+
187+
# Debug: Show downloaded artifacts
188+
- name: Debug - List downloaded artifacts
189+
if: inputs.debug
190+
run: |
191+
echo "=== Downloaded artifacts ==="
192+
find dist -type f -exec ls -la {} \;
193+
194+
# Setup Node.js
195+
- name: Setup Node.js
196+
uses: actions/setup-node@v4
197+
with:
198+
node-version: '20'
199+
registry-url: 'https://registry.npmjs.org'
200+
201+
# Setup pnpm
202+
- name: Setup pnpm
203+
uses: pnpm/action-setup@v4
204+
205+
# Install dependencies
206+
- name: Install dependencies
207+
run: pnpm install --frozen-lockfile
208+
209+
# Copy binaries to npm-dist packages
210+
- name: Prepare platform packages
211+
run: |
212+
# CLI packages
213+
for platform in darwin-x64 darwin-arm64 linux-x64 linux-arm64 windows-x64; do
214+
mkdir -p rust/npm-dist/leanspec-cli-$platform/bin
215+
cp dist/binaries-$platform/lean-spec* rust/npm-dist/leanspec-cli-$platform/bin/
216+
done
217+
218+
# MCP packages
219+
for platform in darwin-x64 darwin-arm64 linux-x64 linux-arm64 windows-x64; do
220+
mkdir -p rust/npm-dist/leanspec-mcp-$platform/bin
221+
cp dist/binaries-$platform/leanspec-mcp* rust/npm-dist/leanspec-mcp-$platform/bin/
222+
done
223+
224+
echo "=== Platform packages prepared ==="
225+
find rust/npm-dist -name "bin" -type d -exec ls -la {} \;
226+
227+
# Publish platform packages
228+
- name: Publish CLI platform packages
229+
run: |
230+
for platform in darwin-x64 darwin-arm64 linux-x64 linux-arm64 windows-x64; do
231+
echo "Publishing leanspec-cli-$platform..."
232+
cd rust/npm-dist/leanspec-cli-$platform
233+
OUTPUT=$(npm publish --provenance --access public 2>&1) || {
234+
if echo "$OUTPUT" | grep -q "You cannot publish over the previously published versions"; then
235+
echo "Version already published, skipping..."
236+
else
237+
echo "$OUTPUT"
238+
exit 1
239+
fi
240+
}
241+
echo "$OUTPUT"
242+
cd ../../..
243+
done
244+
env:
245+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
246+
247+
- name: Publish MCP platform packages
248+
run: |
249+
for platform in darwin-x64 darwin-arm64 linux-x64 linux-arm64 windows-x64; do
250+
echo "Publishing leanspec-mcp-$platform..."
251+
cd rust/npm-dist/leanspec-mcp-$platform
252+
OUTPUT=$(npm publish --provenance --access public 2>&1) || {
253+
if echo "$OUTPUT" | grep -q "You cannot publish over the previously published versions"; then
254+
echo "Version already published, skipping..."
255+
else
256+
echo "$OUTPUT"
257+
exit 1
258+
fi
259+
}
260+
echo "$OUTPUT"
261+
cd ../../..
262+
done
263+
env:
264+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

specs/173-rust-binaries-ci-cd-pipeline/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
status: planned
2+
status: in-progress
33
created: '2025-12-18'
44
tags:
55
- ci-cd
@@ -14,12 +14,15 @@ created_at: '2025-12-18T02:31:12.261Z'
1414
depends_on:
1515
- 170-cli-mcp-core-rust-migration-evaluation
1616
- 172-rust-cli-mcp-npm-distribution
17-
updated_at: '2025-12-18T02:31:20.918Z'
17+
updated_at: '2025-12-18T05:34:26.869Z'
18+
transitions:
19+
- status: in-progress
20+
at: '2025-12-18T05:34:26.869Z'
1821
---
1922

2023
# Rust Binaries CI/CD Cross-Platform Build Pipeline
2124

22-
> **Status**: 🗓️ Planned · **Priority**: High · **Created**: 2025-12-18 · **Tags**: ci-cd, rust, github-actions, cross-compilation, automation, cli, mcp
25+
> **Status**: ⏳ In progress · **Priority**: High · **Created**: 2025-12-18 · **Tags**: ci-cd, rust, github-actions, cross-compilation, automation, cli, mcp
2326
2427
## Overview
2528

0 commit comments

Comments
 (0)