File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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```
126170opencode_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---
Original file line number Diff line number Diff line change @@ -26,8 +26,9 @@ build-dev:
2626# Build for Linux (Ubuntu)
2727build-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
3334build-linux-version :
You can’t perform that action at this time.
0 commit comments