Skip to content

Commit 413ac5a

Browse files
Switch to modernc.org/sqlite for CGO-free cross-compilation
Replace mattn/go-sqlite3 with modernc.org/sqlite to eliminate CGO dependency and simplify cross-platform builds. The modernc.org/sqlite driver provides a pure Go SQLite implementation compatible with the database/sql interface. Changes: Database Driver: • Replace mattn/go-sqlite3 with modernc.org/sqlite across all modules • Register modernc.org/sqlite as "sqlite3" driver in memory package for Ent compatibility • Update SQLite connection string pragma syntax from _fk=1 to _pragma=foreign_keys(1) • Update journal mode pragma from _journal=WAL to _pragma=journal_mode(WAL) • Update busy timeout pragma from _busy_timeout=5000 to _pragma=busy_timeout(5000) Dependencies: • Update backend/go.mod to include modernc.org/sqlite v1.33.1 and related dependencies • Update frontend/cli/go.mod to include modernc.org/sqlite v1.33.1 • Add supporting libraries: modernc.org/libc, mathutil, memory, token, strutil, gc/v3 • Add adrg/xdg v0.5.3 for platform-specific paths Testing: • Update all test files to import modernc.org/sqlite instead of go-sqlite3 • Update test connection strings to use new pragma syntax • Add EventBus and MessageHub to test setup where missing This change eliminates the need for CGO during compilation, enabling easier cross-compilation for multiple platforms and architectures without requiring a C compiler toolchain. Co-authored-by: construct-agent <noreply@construct.sh>
1 parent 3c9ce91 commit 413ac5a

16 files changed

Lines changed: 163 additions & 236 deletions

File tree

backend/api/agent_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/google/go-cmp/cmp"
1414
"github.com/google/go-cmp/cmp/cmpopts"
1515
"github.com/google/uuid"
16-
_ "github.com/mattn/go-sqlite3"
16+
_ "modernc.org/sqlite"
1717
"google.golang.org/protobuf/testing/protocmp"
1818
)
1919

backend/api/api_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (s *ServiceTestSetup[Request, Response]) RunServiceTests(t *testing.T, scen
118118
}
119119

120120
func DefaultTestHandlerOptions(t *testing.T) HandlerOptions {
121-
db, err := memory.Open(dialect.SQLite, "file:construct_test?mode=memory&cache=private&_fk=1")
121+
db, err := memory.Open(dialect.SQLite, "file:construct_test?mode=memory&cache=private&_pragma=foreign_keys(1)")
122122
if err != nil {
123123
t.Fatalf("failed opening connection to sqlite: %v", err)
124124
}
@@ -135,10 +135,18 @@ func DefaultTestHandlerOptions(t *testing.T) HandlerOptions {
135135

136136
runtime := &MockAgentRuntime{}
137137

138+
eventBus := event.NewBus(nil)
139+
messageHub, err := event.NewMessageHub(db)
140+
if err != nil {
141+
t.Fatalf("failed creating message hub: %v", err)
142+
}
143+
138144
return HandlerOptions{
139145
DB: db,
140146
Encryption: encryption,
141147
AgentRuntime: runtime,
148+
EventBus: eventBus,
149+
MessageHub: messageHub,
142150
Analytics: analytics.NewInMemoryClient(),
143151
}
144152
}

backend/api/message_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/google/go-cmp/cmp"
1414
"github.com/google/go-cmp/cmp/cmpopts"
1515
"github.com/google/uuid"
16-
_ "github.com/mattn/go-sqlite3"
16+
_ "modernc.org/sqlite"
1717
"google.golang.org/protobuf/testing/protocmp"
1818
)
1919

backend/api/model_provider_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/google/go-cmp/cmp"
1414
"github.com/google/go-cmp/cmp/cmpopts"
1515
"github.com/google/uuid"
16-
_ "github.com/mattn/go-sqlite3"
16+
_ "modernc.org/sqlite"
1717
"google.golang.org/protobuf/testing/protocmp"
1818
)
1919

backend/api/model_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/google/go-cmp/cmp/cmpopts"
1414
"github.com/google/uuid"
1515
"github.com/googleapis/go-type-adapters/adapters"
16-
_ "github.com/mattn/go-sqlite3"
16+
_ "modernc.org/sqlite"
1717
"google.golang.org/protobuf/testing/protocmp"
1818
)
1919

backend/api/task_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/google/go-cmp/cmp"
1313
"github.com/google/go-cmp/cmp/cmpopts"
1414
"github.com/google/uuid"
15-
_ "github.com/mattn/go-sqlite3"
15+
_ "modernc.org/sqlite"
1616
"google.golang.org/protobuf/testing/protocmp"
1717
)
1818

@@ -71,7 +71,7 @@ func TestCreateTask(t *testing.T) {
7171
Spec: &v1.TaskSpec{
7272
AgentId: strPtr(agentID.String()),
7373
Workspace: "/tmp/test",
74-
DesiredPhase: v1.TaskPhase_TASK_PHASE_AWAITING,
74+
DesiredPhase: v1.TaskPhase_TASK_PHASE_RUNNING,
7575
},
7676
Status: &v1.TaskStatus{
7777
Usage: &v1.TaskUsage{},
@@ -139,7 +139,7 @@ func TestGetTask(t *testing.T) {
139139
},
140140
Spec: &v1.TaskSpec{
141141
AgentId: strPtr(agentID.String()),
142-
DesiredPhase: v1.TaskPhase_TASK_PHASE_AWAITING,
142+
DesiredPhase: v1.TaskPhase_TASK_PHASE_RUNNING,
143143
},
144144
Status: &v1.TaskStatus{
145145
Usage: &v1.TaskUsage{},
@@ -209,7 +209,7 @@ func TestListTasks(t *testing.T) {
209209
},
210210
Spec: &v1.TaskSpec{
211211
AgentId: strPtr(agentID.String()),
212-
DesiredPhase: v1.TaskPhase_TASK_PHASE_AWAITING,
212+
DesiredPhase: v1.TaskPhase_TASK_PHASE_RUNNING,
213213
},
214214
Status: &v1.TaskStatus{
215215
Usage: &v1.TaskUsage{},
@@ -301,7 +301,7 @@ func TestListTasks(t *testing.T) {
301301
},
302302
Spec: &v1.TaskSpec{
303303
AgentId: strPtr(agentID.String()),
304-
DesiredPhase: v1.TaskPhase_TASK_PHASE_AWAITING,
304+
DesiredPhase: v1.TaskPhase_TASK_PHASE_RUNNING,
305305
},
306306
Status: &v1.TaskStatus{
307307
Usage: &v1.TaskUsage{},
@@ -412,7 +412,7 @@ func TestUpdateTask(t *testing.T) {
412412
},
413413
Spec: &v1.TaskSpec{
414414
AgentId: strPtr(agentID2.String()),
415-
DesiredPhase: v1.TaskPhase_TASK_PHASE_AWAITING,
415+
DesiredPhase: v1.TaskPhase_TASK_PHASE_RUNNING,
416416
},
417417
Status: &v1.TaskStatus{
418418
Usage: &v1.TaskUsage{},

backend/go.mod

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ require (
99
github.com/bmatcuk/doublestar/v4 v4.8.1
1010
github.com/cenkalti/backoff/v5 v5.0.3
1111
github.com/furisto/construct/api/go v0.0.0-00010101000000-000000000000
12+
github.com/furisto/construct/shared v0.0.0-00010101000000-000000000000
1213
github.com/google/go-cmp v0.7.0
1314
github.com/google/uuid v1.6.0
1415
github.com/googleapis/go-type-adapters v1.0.1
1516
github.com/grafana/sobek v0.0.0-20250320150027-203dc85b6d98
1617
github.com/invopop/jsonschema v0.13.0
17-
github.com/mattn/go-sqlite3 v1.14.27
1818
github.com/maypok86/otter v1.2.4
1919
github.com/openai/openai-go v1.2.0
2020
github.com/posthog/posthog-go v1.5.12
@@ -28,6 +28,7 @@ require (
2828
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1
2929
google.golang.org/protobuf v1.36.8
3030
k8s.io/client-go v0.34.1
31+
modernc.org/sqlite v1.33.1
3132
)
3233

3334
require (
@@ -38,6 +39,7 @@ require (
3839
cloud.google.com/go/auth v0.9.3 // indirect
3940
cloud.google.com/go/compute/metadata v0.6.0 // indirect
4041
github.com/Masterminds/semver/v3 v3.4.0 // indirect
42+
github.com/adrg/xdg v0.5.3 // indirect
4143
github.com/agext/levenshtein v1.2.1 // indirect
4244
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
4345
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
@@ -47,9 +49,9 @@ require (
4749
github.com/buger/jsonparser v1.1.1 // indirect
4850
github.com/cespare/xxhash/v2 v2.3.0 // indirect
4951
github.com/danieljoos/wincred v1.2.2 // indirect
50-
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
5152
github.com/dlclark/regexp2 v1.11.4 // indirect
5253
github.com/dolthub/maphash v0.1.0 // indirect
54+
github.com/dustin/go-humanize v1.0.1 // indirect
5355
github.com/gammazero/deque v1.0.0 // indirect
5456
github.com/go-logr/logr v1.4.2 // indirect
5557
github.com/go-openapi/inflect v0.19.0 // indirect
@@ -62,14 +64,16 @@ require (
6264
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
6365
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
6466
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
65-
github.com/hedwigz/entviz v0.0.0-20221011080911-9d47f6f1d818 // indirect
6667
github.com/mailru/easyjson v0.7.7 // indirect
68+
github.com/mattn/go-isatty v0.0.20 // indirect
69+
github.com/mattn/go-sqlite3 v1.14.27 // indirect
6770
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
6871
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
69-
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
72+
github.com/ncruces/go-strftime v0.1.9 // indirect
7073
github.com/prometheus/client_model v0.6.2 // indirect
7174
github.com/prometheus/common v0.66.1 // indirect
7275
github.com/prometheus/procfs v0.16.1 // indirect
76+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
7377
github.com/tidwall/gjson v1.18.0 // indirect
7478
github.com/tidwall/match v1.1.1 // indirect
7579
github.com/tidwall/pretty v1.2.1 // indirect
@@ -84,17 +88,23 @@ require (
8488
golang.org/x/crypto v0.41.0 // indirect
8589
golang.org/x/mod v0.26.0 // indirect
8690
golang.org/x/net v0.43.0 // indirect
87-
golang.org/x/sync v0.16.0 // indirect
8891
golang.org/x/sys v0.36.0 // indirect
8992
golang.org/x/text v0.28.0 // indirect
9093
golang.org/x/time v0.9.0 // indirect
91-
golang.org/x/tools v0.35.0 // indirect
9294
google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb // indirect
9395
google.golang.org/grpc v1.72.1 // indirect
9496
gopkg.in/yaml.v3 v3.0.1 // indirect
9597
k8s.io/apimachinery v0.34.1 // indirect
9698
k8s.io/klog/v2 v2.130.1 // indirect
9799
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect
100+
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
101+
modernc.org/libc v1.55.3 // indirect
102+
modernc.org/mathutil v1.6.0 // indirect
103+
modernc.org/memory v1.8.0 // indirect
104+
modernc.org/strutil v1.2.0 // indirect
105+
modernc.org/token v1.1.0 // indirect
98106
)
99107

100108
replace github.com/furisto/construct/api/go => ../api/go
109+
110+
replace github.com/furisto/construct/shared => ../shared

0 commit comments

Comments
 (0)