fix(build): add CGO build tags to fix Docker static builds#138
Merged
Conversation
Fixes #135 Root cause: - sqlite_extension.go and sqlite_vec_loader.go use CGO-only APIs (sqlite3.SQLiteConn.LoadExtension) - Docker builds use CGO_ENABLED=0 for static compilation - These files were being compiled in non-CGO environment, causing: "LoadExtension undefined (type *sqlite3.SQLiteConn has no field or method)" Solution: Use build tags to separate CGO and non-CGO implementations: 1. sqlite_extension.go: !sqlite_vec && cgo - CGO environment: Load extension from dynamic library (.so/.dylib) - Non-CGO: Skip this file 2. sqlite_vec_loader.go: !sqlite_vec && cgo - CGO environment: Try multiple extension paths - Non-CGO: Skip this file 3. sqlite_extension_stub.go: !sqlite_vec && !cgo (NEW) - Non-CGO environment: Return error (use Go fallback) - CGO: Skip this file Build matrix: +------------+------------+----------------------+ | sqlite_vec | CGO | Implementation | +------------+------------+----------------------+ | false | true | Dynamic loader | | false | false | Stub (Go fallback) | | true | N/A | Static linking | +------------+------------+----------------------+ Verification: - ✅ CGO_ENABLED=0 build successful (Docker static build) - ✅ CGO_ENABLED=1 build successful (standard build) - ✅ sqlite-vec extension loads correctly (18 functions) - ✅ Local testing passed - ✅ No regression in existing functionality Impact: - Docker images can now build successfully - Non-CGO builds use Go fallback for vector search - CGO builds maintain full sqlite-vec support Refs #135 Refs #131 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🐛 Problem
Docker 静态构建失败,错误信息:
CI Failure: https://github.com/hrygo/divinesense/actions/runs/21849819582/job/63053719047
🔍 Root Cause
PR #131 添加的
sqlite_extension.go和sqlite_vec_loader.go使用了 CGO 专属的 API:sqlite3.SQLiteConn类型(仅在 CGO 模式下可用)LoadExtension()方法(仅在 CGO 模式下可用)但 Dockerfile 使用
CGO_ENABLED=0进行静态编译:✅ Solution
使用 build tags 分离 CGO 和非 CGO 实现:
修改文件
sqlite_extension.go:
//go:build !sqlite_vec && cgosqlite_vec_loader.go:
//go:build !sqlite_vec && cgosqlite_extension_stub.go (NEW):
//go:build !sqlite_vec && !cgoBuild Matrix
✅ Verification
CGO_ENABLED=0编译成功(Docker 静态构建)CGO_ENABLED=1编译成功(标准构建)📊 Impact
🔗 Related
Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com