Skip to content

refactor(db): migrate sqlite to pure-go and add mips compatibility switch#2296

Merged
Suyunmeng merged 8 commits intomainfrom
refactor/go-sqlite
Apr 2, 2026
Merged

refactor(db): migrate sqlite to pure-go and add mips compatibility switch#2296
Suyunmeng merged 8 commits intomainfrom
refactor/go-sqlite

Conversation

@Suyunmeng
Copy link
Copy Markdown
Contributor

@Suyunmeng Suyunmeng commented Apr 2, 2026

Description / 描述

此 PR 将 SQLite 的使用迁移到原生Go依赖,同时保持对部分linux的兼容性。
主要变更:

  • 将默认 SQLite 切换至 github.com/glebarez/sqlite,以降低对 CGO 的依赖。
  • 在程序中引入统一的 openSQLite 条目,并按构建标签拆分驱动程序选择。
  • 为 Linux mips、mips64、mipsle和loong64 添加 sqlite_cgo_compat 回退机制,以保持旧版目标构建的正常运行。
  • 更新 build.sh musl 构建流程,为 mips 系列目标应用兼容性标签。
  • 更新 beta_release 工作流程,以清晰地传递兼容性标签并避免冲突的标志组合。

Motivation and Context / 背景

原有的 gorm.io/driver/sqlite 驱动程序依赖于 mattn/go-sqlite3,而后者需要通过 CGO 编译 C 代码,导致以下问题:

  1. 交叉编译困难: CGO 交叉编译需要为目标平台配置相应的 C 编译器工具链,增加了构建的复杂性。
  2. 构建环境要求高: CI/CD 环境需要 GCC 等 C 编译器。
  3. 无法进行纯 Go 构建: 使用 CGO_ENABLED=0 无法执行纯 Go 静态编译。
    github.com/glebarez/sqlitegorm.io/driver/sqlite 的纯 Go 替代方案,它使用 modernc.org/sqlite(SQLite 的官方 C 代码通过工具自动转换为 Go 代码)。它与 GORM 完全兼容,无需 CGO 即可编译。

解决了 #2211 迁移方案产生的潜在兼容性问题。

How Has This Been Tested? / 测试

  • 运行包测试:
  • go test ./internal/bootstrap ./internal/op -count=1
  • 验证了不同架构的驱动程序选择行为:
  • linux/mips 选择 gorm.io/driver/sqlite
  • linux/amd64 选择 github.com/glebarez/sqlite
  • 验证了显式兼容性切换:
  • 使用 sqlite_cgo_compat 标签的 linux/amd64 选择 gorm.io/driver/sqlite
  • 确认了工作流标志调整,以避免混合 ldflags 和标签解析问题。

Checklist / 检查清单

  • I have read the CONTRIBUTING document.
    我已阅读 CONTRIBUTING 文档。
  • I have formatted my code with go fmt or prettier.
    我已使用 go fmtprettier 格式化提交的代码。
  • I have added appropriate labels to this PR (or mentioned needed labels in the description if lacking permissions).
    我已为此 PR 添加了适当的标签(如无权限或需要的标签不存在,请在描述中说明,管理员将后续处理)。
  • I have requested review from relevant code authors using the "Request review" feature when applicable.
    我已在适当情况下使用"Request review"功能请求相关代码作者进行审查。
  • I have updated the repository accordingly (If it is needed).
    我已相应更新了相关仓库(若适用)。

@Suyunmeng Suyunmeng marked this pull request as draft April 2, 2026 06:50
@Suyunmeng Suyunmeng force-pushed the refactor/go-sqlite branch from 9447bbd to e3bc7f8 Compare April 2, 2026 09:18
@Suyunmeng Suyunmeng changed the title fix(build): migrate sqlite to pure-go and add mips compatibility switch refactor(db): migrate sqlite to pure-go and add mips compatibility switch Apr 2, 2026
@Suyunmeng Suyunmeng marked this pull request as ready for review April 2, 2026 09:58
@Suyunmeng Suyunmeng requested a review from jyxjjj April 2, 2026 10:03
@Suyunmeng Suyunmeng merged commit a5f8623 into main Apr 2, 2026
12 checks passed
Suyunmeng added a commit that referenced this pull request Apr 2, 2026
…itch (#2296)

- Switch default SQLite path to github.com/glebarez/sqlite to reduce CGO dependency pressure.
- Introduce a unified openSQLite entry in bootstrap and split driver selection by build tags.
- Add sqlite_cgo_compat fallback for linux mips, mips64, loong64 and mipsle to keep legacy target builds working.
- Update build.sh musl build flow to apply compatibility tag for mips-family targets.
- Update beta_release workflow to pass compatibility tag cleanly and avoid conflicting flag composition.
Suyunmeng added a commit that referenced this pull request Apr 2, 2026
…itch (#2296)

- Switch default SQLite path to github.com/glebarez/sqlite to reduce CGO dependency pressure.
- Introduce a unified openSQLite entry in bootstrap and split driver selection by build tags.
- Add sqlite_cgo_compat fallback for linux mips, mips64, loong64 and mipsle to keep legacy target builds working.
- Update build.sh musl build flow to apply compatibility tag for mips-family targets.
- Update beta_release workflow to pass compatibility tag cleanly and avoid conflicting flag composition.
Suyunmeng added a commit that referenced this pull request Apr 2, 2026
…itch (#2296)

- Switch default SQLite path to github.com/glebarez/sqlite to reduce CGO dependency pressure.
- Introduce a unified openSQLite entry in bootstrap and split driver selection by build tags.
- Add sqlite_cgo_compat fallback for linux mips, mips64, loong64 and mipsle to keep legacy target builds working.
- Update build.sh musl build flow to apply compatibility tag for mips-family targets.
- Update beta_release workflow to pass compatibility tag cleanly and avoid conflicting flag composition.
Suyunmeng added a commit that referenced this pull request Apr 2, 2026
…itch (#2296)

- Switch default SQLite path to github.com/glebarez/sqlite to reduce CGO dependency pressure.
- Introduce a unified openSQLite entry in bootstrap and split driver selection by build tags.
- Add sqlite_cgo_compat fallback for linux mips, mips64, loong64 and mipsle to keep legacy target builds working.
- Update build.sh musl build flow to apply compatibility tag for mips-family targets.
- Update beta_release workflow to pass compatibility tag cleanly and avoid conflicting flag composition.
Suyunmeng added a commit that referenced this pull request Apr 2, 2026
…itch (#2296)

- Switch default SQLite path to github.com/glebarez/sqlite to reduce CGO dependency pressure.
- Introduce a unified openSQLite entry in bootstrap and split driver selection by build tags.
- Add sqlite_cgo_compat fallback for linux mips, mips64, loong64 and mipsle to keep legacy target builds working.
- Update build.sh musl build flow to apply compatibility tag for mips-family targets.
- Update beta_release workflow to pass compatibility tag cleanly and avoid conflicting flag composition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant