Skip to content

Conversation

corylanou
Copy link
Collaborator

Summary

This PR migrates the main litestream binary from github.com/mattn/go-sqlite3 to modernc.org/sqlite to enable CGO-free builds and automatic cross-platform compilation, particularly for signed Silicon Mac releases.

Changes

  • ✅ Replace mattn/go-sqlite3 with modernc.org/sqlite for main binary
  • ✅ Implement PERSIST_WAL using FileControl API (full feature parity)
  • ✅ Add build tags to conditionally compile VFS support
  • ✅ Keep VFS functionality with mattn/go-sqlite3 for experimental feature
  • ✅ Update all SQLite driver references from "sqlite3" to "sqlite"

Key Benefits

  1. CGO-Free Builds: Main litestream binary can now be built without CGO
  2. Cross-Platform Compilation: Easy compilation for multiple platforms
  3. Signed macOS Releases: Enables automatic signing of Silicon Mac releases
  4. Full Compatibility: PERSIST_WAL functionality maintained via FileControl API

Testing

  • All existing tests pass
  • CGO-free build verified
  • Cross-platform builds tested (Linux, macOS, Windows)
  • PERSIST_WAL functionality verified
  • CI integration tests (to be run)

Notes

  • The VFS feature (cmd/litestream-vfs) intentionally remains CGO-dependent as it's experimental and primarily for Fly.io projects
  • Both SQLite drivers coexist without conflicts
  • See MIGRATION_TO_MODERNC_SQLITE.md for detailed migration notes

Fixes #723

🤖 Generated with Claude Code

corylanou and others added 10 commits September 3, 2025 08:36
Migrates the main litestream binary from github.com/mattn/go-sqlite3 to
modernc.org/sqlite to enable CGO-free builds and automatic cross-platform
compilation. This enables signed macOS releases without cross-compilation
toolchains.

Key changes:
- Replace mattn/go-sqlite3 with modernc.org/sqlite for main binary
- Implement PERSIST_WAL using FileControl API (full feature parity)
- Add build tags to conditionally compile VFS support (requires CGO)
- Keep VFS functionality with mattn/go-sqlite3 for compatibility
- Update all SQLite driver references from "sqlite3" to "sqlite"

The VFS feature (cmd/litestream-vfs) intentionally remains CGO-dependent
as it's experimental and may require write support in the future.

Fixes #723

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
The modernc.org/sqlite package auto-registers as 'sqlite' driver.
Removed custom driver registration and switched all connections to use
the standard 'sqlite' driver name to fix CI build failures.
The cmd/litestream-vfs/main.go file needs a main function for non-CGO
builds. Added a stub that panics with an informative message when the
VFS command is built without the required build tags.
The VFS functionality depends on sqlite3vfs which requires the C SQLite
library. Since we've migrated to modernc.org/sqlite (pure Go), VFS must
be explicitly enabled with the 'vfs' build tag to avoid linking errors.

This change:
- Requires -tags vfs to enable VFS support
- Prevents sqlite3vfs from being linked in default builds
- Fixes CI build failures from missing SQLite C library
- Maintains VFS compatibility when explicitly requested
- Added instructions for testing VFS builds with CGO and build tags
- Added warnings about not committing binary files
- Updated .gitignore to exclude common binary names
- Documented different build configurations to test before commits
MIGRATION_TO_MODERNC_SQLITE.md was for internal planning only
The 'cgo' build tag was redundant since:
- VFS requires CGO due to sqlite3vfs dependency
- The main binary is now pure Go with modernc.org/sqlite
- The 'vfs' tag expresses the actual intent

This simplifies the build tags to focus on what we're building (VFS)
rather than implementation details (CGO requirement).
- Removed redundant binary exclusions from .gitignore
- Updated CLAUDE.md to always build binaries into bin/ directory
- The bin/ directory is already gitignored, preventing accidental commits
The main() function already exists in litestream-vfs.go with the
SQLITE3VFS_LOADABLE_EXT build tag. The stub was causing 'unreachable
code' and wasn't needed - the package is invisible to builds without
the appropriate build tags.
The VFS stub was not needed - VFS types are only referenced in files
that have the appropriate build tags. Without the 'vfs' tag, the VFS
code doesn't exist and there are no references to it.
Copy link

github-actions bot commented Sep 3, 2025

Manual integration tests have been run by @corylanou

View test results

- Removed empty init() function that only contained a comment
- Removed redundant connection comment (PERSIST_WAL handling is documented in setPersistWAL)
- Kept original comments unmodified for clarity
- Revert WAL removal comment to original simple form
- Focus on functional descriptions rather than implementation details
@corylanou corylanou merged commit 74093a4 into main Sep 3, 2025
9 checks passed
@corylanou corylanou deleted the feature/723-cgo-free-sqlite branch September 3, 2025 18:46
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.

Migrate to using the CGO free sqlite library
2 participants