Skip to content

Commit 22a7ab4

Browse files
author
Sisyphus Agent
committed
docs(build): 添加 oho 构建指南并修复 Makefile build-linux 目标
- 在 AGENTS.md 中添加 oho 项目构建指南,强调 ldflags 的重要性 - 修复 Makefile build-linux 目标缺少 ldflags 的问题 - 添加构建验证说明,确保版本信息正确显示 原来 build-linux 命令缺少 ldflags,导致构建显示: oho version dev (commit: none, built: unknown) 修复后显示: oho version v1.x.x (commit: xxxxx, built: YYYY-MM-DDThh:mm:ssZ)
1 parent 9580e5f commit 22a7ab4

2 files changed

Lines changed: 53 additions & 3 deletions

File tree

AGENTS.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,63 @@ set -e
120120

121121
---
122122

123+
## oho 项目构建指南
124+
125+
oho 是用 Go 编写的 CLI 工具,位于 `oho/` 子目录。
126+
127+
### ⚠️ 重要:构建命令必须包含 ldflags
128+
129+
oho 使用 ldflags 注入版本信息。**必须使用以下格式**,否则版本信息会显示为 `commit: none, built: unknown`
130+
131+
```bash
132+
# 正确:包含完整 ldflags
133+
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev")
134+
COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
135+
DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
136+
go build -ldflags "-s -w -X main.Version=${VERSION} -X main.Commit=${COMMIT} -X main.Date=${DATE}" -o bin/oho ./cmd
137+
138+
# 错误:缺少 ldflags(版本信息会丢失)
139+
go build -o bin/oho ./cmd
140+
```
141+
142+
### 推荐使用 Makefile
143+
144+
```bash
145+
cd oho
146+
147+
# 本地构建(推荐)
148+
make build
149+
150+
# Linux 交叉编译
151+
make build-linux
152+
153+
# 开发模式(无版本信息)
154+
make build-dev
155+
```
156+
157+
### 验证构建
158+
159+
```bash
160+
./bin/oho --version
161+
# 应该显示: oho version v1.x.x (commit: xxxxx, built: YYYY-MM-DDThh:mm:ssZ)
162+
# 而不是: oho version dev (commit: none, built: unknown)
163+
```
164+
165+
---
166+
123167
## 项目结构
124168

125169
```
126170
opencode_cli/
127-
├── scripts/ # Python/Shell 脚本
171+
├── oho/ # Go CLI 项目 (主项目)
172+
│ ├── cmd/ # 命令入口
173+
│ ├── internal/ # 内部包
174+
│ ├── Makefile # 构建目标
175+
│ └── README.md # oho 详细文档
176+
├── scripts/ # Python/Shell 脚本
128177
│ ├── opencode-submit.py
129178
│ └── opencode-test.py
130-
└── AGENTS.md # 本文件
179+
└── AGENTS.md # 本文件
131180
```
132181

133182
---

oho/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ build-dev:
2626
# Build for Linux (Ubuntu)
2727
build-linux:
2828
@echo "Building $(BINARY_NAME) for Linux..."
29-
@GOOS=linux GOARCH=amd64 go build -o $(BUILD_DIR)/$(BINARY_NAME)-linux $(CMD_PATH)
29+
@GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.Version=$(VERSION) -X main.Commit=$(COMMIT) -X main.Date=$(DATE)" -o $(BUILD_DIR)/$(BINARY_NAME)-linux $(CMD_PATH)
3030
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)-linux"
31+
@$(BUILD_DIR)/$(BINARY_NAME)-linux --version
3132

3233
# Build for Linux with version info
3334
build-linux-version:

0 commit comments

Comments
 (0)