Skip to content

Commit c4de712

Browse files
committed
docs: Add comprehensive build documentation
Created BUILD.md with complete instructions for: - Quick build (--single flag for current platform) - Full build (all platforms) - Testing the binary - Installing globally (copy, symlink, or PATH) - Build output structure - Differences between bun dev and binary - Development workflow - Troubleshooting common issues - Platform-specific notes - CI/CD integration Users can now easily build and distribute OpenCode binaries.
1 parent c5c2966 commit c4de712

1 file changed

Lines changed: 268 additions & 0 deletions

File tree

BUILD.md

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
# Building OpenCode Binary
2+
3+
## Quick Build (Current Platform Only)
4+
5+
Build for your current platform (fastest):
6+
7+
```bash
8+
cd packages/opencode
9+
bun run build --single
10+
```
11+
12+
**Output:** `dist/opencode-{os}-{arch}/bin/opencode`
13+
14+
**Example on macOS ARM64:**
15+
```
16+
dist/opencode-darwin-arm64/bin/opencode
17+
```
18+
19+
**Example on Linux x64:**
20+
```
21+
dist/opencode-linux-x64/bin/opencode
22+
```
23+
24+
## Full Build (All Platforms)
25+
26+
Build for all supported platforms (takes longer):
27+
28+
```bash
29+
cd packages/opencode
30+
bun run build
31+
```
32+
33+
**Platforms built:**
34+
- Linux ARM64 (glibc)
35+
- Linux x64 (glibc)
36+
- Linux x64 baseline (no AVX2)
37+
- Linux ARM64 (musl)
38+
- Linux x64 (musl)
39+
- Linux x64 musl baseline (no AVX2)
40+
- macOS ARM64 (Apple Silicon)
41+
- macOS x64 (Intel)
42+
- macOS x64 baseline (no AVX2)
43+
- Windows x64
44+
- Windows x64 baseline (no AVX2)
45+
46+
## Testing the Binary
47+
48+
After building, test the binary:
49+
50+
```bash
51+
# Macbook (ARM64)
52+
./dist/opencode-darwin-arm64/bin/opencode --version
53+
54+
# Linux x64
55+
./dist/opencode-linux-x64/bin/opencode --version
56+
57+
# Start OpenCode
58+
./dist/opencode-darwin-arm64/bin/opencode
59+
```
60+
61+
## Installing the Binary
62+
63+
### Option 1: Copy to PATH
64+
65+
```bash
66+
# macOS/Linux
67+
sudo cp dist/opencode-darwin-arm64/bin/opencode /usr/local/bin/
68+
69+
# Now you can run from anywhere
70+
opencode --version
71+
```
72+
73+
### Option 2: Symlink
74+
75+
```bash
76+
# macOS/Linux
77+
ln -s $(pwd)/dist/opencode-darwin-arm64/bin/opencode /usr/local/bin/opencode
78+
79+
# Now you can run from anywhere
80+
opencode --version
81+
```
82+
83+
### Option 3: Add to PATH
84+
85+
Add to your `~/.zshrc` or `~/.bashrc`:
86+
87+
```bash
88+
export PATH="$HOME/Development/ai/opencode-auto/packages/opencode/dist/opencode-darwin-arm64/bin:$PATH"
89+
```
90+
91+
Then reload:
92+
93+
```bash
94+
source ~/.zshrc # or ~/.bashrc
95+
opencode --version
96+
```
97+
98+
## Build Output Structure
99+
100+
```
101+
dist/
102+
├── opencode-darwin-arm64/
103+
│ ├── bin/
104+
│ │ └── opencode ← Executable binary
105+
│ └── package.json ← Package metadata
106+
├── opencode-linux-x64/
107+
│ ├── bin/
108+
│ │ └── opencode
109+
│ └── package.json
110+
└── ...
111+
```
112+
113+
## Build Options
114+
115+
### Clean Build
116+
117+
Remove previous builds:
118+
119+
```bash
120+
cd packages/opencode
121+
rm -rf dist
122+
bun run build --single
123+
```
124+
125+
### Debug Build
126+
127+
The build includes source maps in `dist/*/bin/*.js.map` for debugging.
128+
129+
## Differences: `bun dev` vs `opencode` binary
130+
131+
| Feature | `bun dev` | `opencode` binary |
132+
|---------|-----------|-------------------|
133+
| **Speed** | Slower (interprets TypeScript) | Faster (compiled) |
134+
| **Updates** | Instant (no rebuild) | Requires rebuild |
135+
| **Distribution** | Cannot distribute | Single executable |
136+
| **File size** | N/A | ~150MB (includes runtime) |
137+
| **Use case** | Development | Production, distribution |
138+
139+
## Development Workflow
140+
141+
**During development:**
142+
```bash
143+
bun dev
144+
```
145+
146+
**Before testing production behavior:**
147+
```bash
148+
bun run build --single
149+
./dist/opencode-darwin-arm64/bin/opencode
150+
```
151+
152+
**Before creating a release:**
153+
```bash
154+
bun run build # All platforms
155+
```
156+
157+
## Troubleshooting
158+
159+
### Build fails with "Module not found"
160+
161+
Run from the correct directory:
162+
```bash
163+
cd packages/opencode
164+
bun run build --single
165+
```
166+
167+
### Binary doesn't run
168+
169+
Check permissions:
170+
```bash
171+
chmod +x dist/opencode-darwin-arm64/bin/opencode
172+
```
173+
174+
### "Cannot find module @opentui/core"
175+
176+
The build script handles this, but if you see it:
177+
```bash
178+
cd packages/opencode
179+
bun install --os="*" --cpu="*"
180+
bun run build --single
181+
```
182+
183+
### TypeScript errors during build
184+
185+
Make sure all changes compile:
186+
```bash
187+
bun run typecheck
188+
```
189+
190+
Fix any errors, then rebuild.
191+
192+
## Build Performance
193+
194+
**Single platform build:** ~30-60 seconds
195+
**All platforms build:** ~5-10 minutes
196+
197+
## What Gets Compiled
198+
199+
The build compiles:
200+
1. Main entry point: `src/index.ts`
201+
2. Tree-sitter parser worker: `@opentui/core/parser.worker.js`
202+
3. TUI worker: `src/cli/cmd/tui/worker.ts`
203+
204+
All dependencies are bundled into the single executable.
205+
206+
## Binary Size
207+
208+
Each binary is approximately:
209+
- **150-180MB** (includes Bun runtime + all dependencies)
210+
- Compressed distribution: ~60-80MB
211+
212+
This is normal for Bun-compiled binaries as they include the runtime.
213+
214+
## Platform-Specific Notes
215+
216+
### macOS
217+
- ARM64 (M1/M2/M3): Use `opencode-darwin-arm64`
218+
- Intel (x86_64): Use `opencode-darwin-x64`
219+
220+
### Linux
221+
- **glibc** (Ubuntu, Debian, Fedora): Use `opencode-linux-x64`
222+
- **musl** (Alpine): Use `opencode-linux-x64-musl`
223+
- **baseline**: For older CPUs without AVX2
224+
225+
### Windows
226+
- Use `opencode-windows-x64`
227+
- Note: Binary is named `opencode.exe` on Windows
228+
229+
## CI/CD Integration
230+
231+
The build script is designed for CI/CD:
232+
233+
```yaml
234+
# Example GitHub Actions
235+
- name: Build OpenCode
236+
run: |
237+
cd packages/opencode
238+
bun install
239+
bun run build
240+
241+
- name: Upload artifacts
242+
uses: actions/upload-artifact@v3
243+
with:
244+
name: opencode-binaries
245+
path: packages/opencode/dist/*/bin/opencode*
246+
```
247+
248+
## Related Commands
249+
250+
```bash
251+
# Development
252+
bun dev
253+
254+
# Build
255+
bun run build --single
256+
257+
# Test
258+
bun test
259+
260+
# Typecheck
261+
bun run typecheck
262+
```
263+
264+
## See Also
265+
266+
- Development guide: `CONTRIBUTING.md`
267+
- Release process: `RELEASING.md`
268+
- Plugin development: `docs/PLUGIN_DEVELOPMENT.md`

0 commit comments

Comments
 (0)