Skip to content

Commit f91bbf3

Browse files
steveyeggeclaude
andcommitted
fix(build): add CGO build constraints for Dolt-dependent files
The dolthub/gozstd dependency requires CGO. Several files were importing the dolt package without build constraints, causing CI failures when building with CGO_ENABLED=0 for Linux, FreeBSD, and Android. Changes: - Add //go:build cgo to federation.go and doctor/federation.go - Create dolt_server_cgo.go/nocgo.go to abstract dolt.Server usage - Create federation_nocgo.go with stub command explaining CGO requirement - Create doctor/federation_nocgo.go with stub health checks - Update daemon.go to use the dolt server abstraction Federation and Dolt-specific features are unavailable in non-CGO builds. Users are directed to pre-built binaries from GitHub releases. Fixes v0.49.0 CI failure. Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 9381190 commit f91bbf3

File tree

7 files changed

+225
-13
lines changed

7 files changed

+225
-13
lines changed

cmd/bd/daemon.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/steveyegge/beads/internal/configfile"
1818
"github.com/steveyegge/beads/internal/daemon"
1919
"github.com/steveyegge/beads/internal/rpc"
20-
"github.com/steveyegge/beads/internal/storage/dolt"
2120
"github.com/steveyegge/beads/internal/storage/factory"
2221
"github.com/steveyegge/beads/internal/storage/sqlite"
2322
"github.com/steveyegge/beads/internal/syncbranch"
@@ -421,13 +420,17 @@ func runDaemonLoop(interval time.Duration, autoCommit, autoPush, autoPull, local
421420
}
422421

423422
// Start dolt sql-server if federation mode is enabled and backend is dolt
424-
var doltServer *dolt.Server
423+
var doltServer *DoltServerHandle
425424
factoryOpts := factory.Options{}
426425
if federation && backend != configfile.BackendDolt {
427426
log.Warn("federation mode requires dolt backend, ignoring --federation flag")
428427
federation = false
429428
}
430429
if federation && backend == configfile.BackendDolt {
430+
if !DoltServerAvailable() {
431+
log.Error("federation mode requires CGO; use pre-built binaries from GitHub releases")
432+
return
433+
}
431434
log.Info("starting dolt sql-server for federation mode")
432435

433436
doltPath := filepath.Join(beadsDir, "dolt")
@@ -436,22 +439,16 @@ func runDaemonLoop(interval time.Duration, autoCommit, autoPush, autoPull, local
436439
// Use provided ports or defaults
437440
sqlPort := federationPort
438441
if sqlPort == 0 {
439-
sqlPort = dolt.DefaultSQLPort
442+
sqlPort = DoltDefaultSQLPort
440443
}
441444
remotePort := remotesapiPort
442445
if remotePort == 0 {
443-
remotePort = dolt.DefaultRemotesAPIPort
446+
remotePort = DoltDefaultRemotesAPIPort
444447
}
445448

446-
doltServer = dolt.NewServer(dolt.ServerConfig{
447-
DataDir: doltPath,
448-
SQLPort: sqlPort,
449-
RemotesAPIPort: remotePort,
450-
Host: "127.0.0.1",
451-
LogFile: serverLogFile,
452-
})
453-
454-
if err := doltServer.Start(ctx); err != nil {
449+
var err error
450+
doltServer, err = StartDoltServer(ctx, doltPath, serverLogFile, sqlPort, remotePort)
451+
if err != nil {
455452
log.Error("failed to start dolt sql-server", "error", err)
456453
return
457454
}

cmd/bd/doctor/federation.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build cgo
2+
13
package doctor
24

35
import (

cmd/bd/doctor/federation_nocgo.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//go:build !cgo
2+
3+
package doctor
4+
5+
// CheckFederationRemotesAPI returns N/A when CGO is not available.
6+
func CheckFederationRemotesAPI(path string) DoctorCheck {
7+
return DoctorCheck{
8+
Name: "Federation remotesapi",
9+
Status: StatusOK,
10+
Message: "N/A (requires CGO)",
11+
Category: CategoryFederation,
12+
}
13+
}
14+
15+
// CheckFederationPeerConnectivity returns N/A when CGO is not available.
16+
func CheckFederationPeerConnectivity(path string) DoctorCheck {
17+
return DoctorCheck{
18+
Name: "Peer Connectivity",
19+
Status: StatusOK,
20+
Message: "N/A (requires CGO)",
21+
Category: CategoryFederation,
22+
}
23+
}
24+
25+
// CheckFederationSyncStaleness returns N/A when CGO is not available.
26+
func CheckFederationSyncStaleness(path string) DoctorCheck {
27+
return DoctorCheck{
28+
Name: "Sync Staleness",
29+
Status: StatusOK,
30+
Message: "N/A (requires CGO)",
31+
Category: CategoryFederation,
32+
}
33+
}
34+
35+
// CheckFederationConflicts returns N/A when CGO is not available.
36+
func CheckFederationConflicts(path string) DoctorCheck {
37+
return DoctorCheck{
38+
Name: "Federation Conflicts",
39+
Status: StatusOK,
40+
Message: "N/A (requires CGO)",
41+
Category: CategoryFederation,
42+
}
43+
}
44+
45+
// CheckDoltServerModeMismatch returns N/A when CGO is not available.
46+
func CheckDoltServerModeMismatch(path string) DoctorCheck {
47+
return DoctorCheck{
48+
Name: "Dolt Mode",
49+
Status: StatusOK,
50+
Message: "N/A (requires CGO)",
51+
Category: CategoryFederation,
52+
}
53+
}

cmd/bd/dolt_server_cgo.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//go:build cgo
2+
3+
package main
4+
5+
import (
6+
"context"
7+
8+
"github.com/steveyegge/beads/internal/storage/dolt"
9+
)
10+
11+
// DoltServerHandle wraps a dolt.Server for CGO builds
12+
type DoltServerHandle struct {
13+
server *dolt.Server
14+
}
15+
16+
// DoltDefaultSQLPort is the default SQL port for dolt server
17+
const DoltDefaultSQLPort = dolt.DefaultSQLPort
18+
19+
// DoltDefaultRemotesAPIPort is the default remotesapi port for dolt server
20+
const DoltDefaultRemotesAPIPort = dolt.DefaultRemotesAPIPort
21+
22+
// StartDoltServer starts a dolt sql-server for federation mode
23+
func StartDoltServer(ctx context.Context, dataDir, logFile string, sqlPort, remotePort int) (*DoltServerHandle, error) {
24+
server := dolt.NewServer(dolt.ServerConfig{
25+
DataDir: dataDir,
26+
SQLPort: sqlPort,
27+
RemotesAPIPort: remotePort,
28+
Host: "127.0.0.1",
29+
LogFile: logFile,
30+
})
31+
32+
if err := server.Start(ctx); err != nil {
33+
return nil, err
34+
}
35+
36+
return &DoltServerHandle{server: server}, nil
37+
}
38+
39+
// Stop stops the dolt server
40+
func (h *DoltServerHandle) Stop() error {
41+
if h.server != nil {
42+
return h.server.Stop()
43+
}
44+
return nil
45+
}
46+
47+
// SQLPort returns the SQL port the server is listening on
48+
func (h *DoltServerHandle) SQLPort() int {
49+
if h.server != nil {
50+
return h.server.SQLPort()
51+
}
52+
return 0
53+
}
54+
55+
// RemotesAPIPort returns the remotesapi port the server is listening on
56+
func (h *DoltServerHandle) RemotesAPIPort() int {
57+
if h.server != nil {
58+
return h.server.RemotesAPIPort()
59+
}
60+
return 0
61+
}
62+
63+
// Host returns the host the server is listening on
64+
func (h *DoltServerHandle) Host() string {
65+
if h.server != nil {
66+
return h.server.Host()
67+
}
68+
return ""
69+
}
70+
71+
// DoltServerAvailable returns true when CGO is available
72+
func DoltServerAvailable() bool {
73+
return true
74+
}

cmd/bd/dolt_server_nocgo.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//go:build !cgo
2+
3+
package main
4+
5+
import (
6+
"context"
7+
"errors"
8+
)
9+
10+
// DoltServerHandle is a stub for non-CGO builds
11+
type DoltServerHandle struct{}
12+
13+
// DoltDefaultSQLPort is the default SQL port for dolt server
14+
const DoltDefaultSQLPort = 3306
15+
16+
// DoltDefaultRemotesAPIPort is the default remotesapi port for dolt server
17+
const DoltDefaultRemotesAPIPort = 50051
18+
19+
// ErrDoltRequiresCGO is returned when dolt features are requested without CGO
20+
var ErrDoltRequiresCGO = errors.New("dolt backend requires CGO; use pre-built binaries from GitHub releases or enable CGO")
21+
22+
// StartDoltServer returns an error in non-CGO builds
23+
func StartDoltServer(ctx context.Context, dataDir, logFile string, sqlPort, remotePort int) (*DoltServerHandle, error) {
24+
return nil, ErrDoltRequiresCGO
25+
}
26+
27+
// Stop is a no-op stub
28+
func (h *DoltServerHandle) Stop() error {
29+
return nil
30+
}
31+
32+
// SQLPort returns 0 in non-CGO builds
33+
func (h *DoltServerHandle) SQLPort() int {
34+
return 0
35+
}
36+
37+
// RemotesAPIPort returns 0 in non-CGO builds
38+
func (h *DoltServerHandle) RemotesAPIPort() int {
39+
return 0
40+
}
41+
42+
// Host returns empty string in non-CGO builds
43+
func (h *DoltServerHandle) Host() string {
44+
return ""
45+
}
46+
47+
// DoltServerAvailable returns false when CGO is not available
48+
func DoltServerAvailable() bool {
49+
return false
50+
}

cmd/bd/federation.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build cgo
2+
13
package main
24

35
import (

cmd/bd/federation_nocgo.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//go:build !cgo
2+
3+
package main
4+
5+
import (
6+
"fmt"
7+
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var federationCmd = &cobra.Command{
12+
Use: "federation",
13+
GroupID: "sync",
14+
Short: "Manage peer-to-peer federation (requires CGO)",
15+
Long: `Federation commands require CGO and the Dolt storage backend.
16+
17+
This binary was built without CGO support. To use federation features:
18+
1. Use pre-built binaries from GitHub releases, or
19+
2. Build from source with CGO enabled
20+
21+
Federation enables synchronized issue tracking across multiple Gas Towns,
22+
each maintaining their own Dolt database while sharing updates via remotes.`,
23+
Run: func(cmd *cobra.Command, args []string) {
24+
fmt.Println("Federation requires CGO and Dolt backend.")
25+
fmt.Println("")
26+
fmt.Println("This binary was built without CGO support. To use federation:")
27+
fmt.Println(" 1. Download pre-built binaries from GitHub releases")
28+
fmt.Println(" 2. Or build from source with CGO enabled")
29+
},
30+
}
31+
32+
func init() {
33+
rootCmd.AddCommand(federationCmd)
34+
}

0 commit comments

Comments
 (0)