Skip to content

Commit 5033215

Browse files
vkuttypCopilot
andcommitted
fix: add CSQLite system library for Linux SQLite3 support
- Create Sources/CSQLite/module.modulemap for Linux sqlite3 - Add #if canImport(SQLite3) conditional imports in SQLiteNio sources - Add #if os(Linux) CSQLite system library target in Package.swift - Add libsqlite3-dev install step to all CI/release workflow jobs - Fix PostgreSQL health-cmd to use pg_isready without -d flag This fixes the root cause of all CI job failures: 'import SQLite3' not resolving on Linux caused SwiftPM to fail compiling the entire package, which broke SQLite, PostgreSQL, MySQL, and MSSQL test jobs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 745f8ff commit 5033215

6 files changed

Lines changed: 52 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ jobs:
5959
restore-keys: |
6060
${{ runner.os }}-spm-${{ matrix.swift }}-
6161
62+
- name: Install SQLite (Linux)
63+
if: runner.os == 'Linux'
64+
run: sudo apt-get install -y libsqlite3-dev
65+
6266
- name: Build
6367
run: swift build --configuration debug 2>&1
6468

@@ -98,6 +102,9 @@ jobs:
98102
with:
99103
swift-version: ${{ env.SWIFT_VERSION }}
100104

105+
- name: Install SQLite
106+
run: sudo apt-get install -y libsqlite3-dev
107+
101108
- name: Cache SPM
102109
uses: actions/cache@v4
103110
with:
@@ -137,7 +144,7 @@ jobs:
137144
ports:
138145
- 5432:5432
139146
options: >-
140-
--health-cmd "pg_isready -U pguser -d PostgresNioTestDb"
147+
--health-cmd "pg_isready -U pguser"
141148
--health-interval 5s
142149
--health-timeout 3s
143150
--health-retries 10
@@ -150,6 +157,9 @@ jobs:
150157
with:
151158
swift-version: ${{ env.SWIFT_VERSION }}
152159

160+
- name: Install SQLite
161+
run: sudo apt-get install -y libsqlite3-dev
162+
153163
- name: Cache SPM
154164
uses: actions/cache@v4
155165
with:
@@ -196,6 +206,9 @@ jobs:
196206
with:
197207
swift-version: ${{ env.SWIFT_VERSION }}
198208

209+
- name: Install SQLite
210+
run: sudo apt-get install -y libsqlite3-dev
211+
199212
- name: Cache SPM
200213
uses: actions/cache@v4
201214
with:

.github/workflows/release.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
- uses: swift-actions/setup-swift@v2
2222
with:
2323
swift-version: "6.0"
24+
- name: Install SQLite
25+
run: sudo apt-get install -y libsqlite3-dev
2426
- run: swift test --filter SQLiteNioTests
2527
- run: swift test --filter SQLNioCoreTests
2628

@@ -44,6 +46,8 @@ jobs:
4446
- uses: swift-actions/setup-swift@v2
4547
with:
4648
swift-version: "6.0"
49+
- name: Install SQLite
50+
run: sudo apt-get install -y libsqlite3-dev
4751
- name: Run PostgreSQL tests
4852
env:
4953
PG_TEST_HOST: "127.0.0.1"
@@ -73,6 +77,8 @@ jobs:
7377
- uses: swift-actions/setup-swift@v2
7478
with:
7579
swift-version: "6.0"
80+
- name: Install SQLite
81+
run: sudo apt-get install -y libsqlite3-dev
7682
- name: Run MySQL tests
7783
env:
7884
MYSQL_TEST_HOST: "127.0.0.1"
@@ -101,6 +107,8 @@ jobs:
101107
- uses: swift-actions/setup-swift@v2
102108
with:
103109
swift-version: "6.0"
110+
- name: Install SQLite
111+
run: sudo apt-get install -y libsqlite3-dev
104112
- name: Create test database
105113
run: |
106114
until /opt/mssql-tools18/bin/sqlcmd -S 127.0.0.1 -U sa -P 'aBCD111!' -C \

Package.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
// swift-tools-version: 5.9
22
import PackageDescription
33

4+
// SQLite is provided by the Apple SDK on Darwin; on Linux we need a system library.
5+
#if canImport(Darwin)
6+
let sqliteSystemLibTargets: [Target] = []
7+
let sqliteNioExtraDeps: [Target.Dependency] = []
8+
let sqliteNioLinkerSettings: [LinkerSetting] = [.linkedLibrary("sqlite3")]
9+
#else
10+
let sqliteSystemLibTargets: [Target] = [
11+
.systemLibrary(name: "CSQLite", pkgConfig: "sqlite3",
12+
providers: [.apt(["libsqlite3-dev"])]),
13+
]
14+
let sqliteNioExtraDeps: [Target.Dependency] = [.target(name: "CSQLite")]
15+
let sqliteNioLinkerSettings: [LinkerSetting] = []
16+
#endif
17+
418
let package = Package(
519
name: "sql-nio",
620
platforms: [
@@ -86,9 +100,9 @@ let package = Package(
86100
.product(name: "NIOCore", package: "swift-nio"),
87101
.product(name: "NIOPosix", package: "swift-nio"),
88102
.product(name: "Logging", package: "swift-log"),
89-
],
103+
] + sqliteNioExtraDeps,
90104
swiftSettings: swiftSettings,
91-
linkerSettings: [.linkedLibrary("sqlite3")]
105+
linkerSettings: sqliteNioLinkerSettings
92106
),
93107

94108
// ── Tests ─────────────────────────────────────────────────────────────
@@ -130,7 +144,7 @@ let package = Package(
130144
],
131145
swiftSettings: swiftSettings
132146
),
133-
]
147+
] + sqliteSystemLibTargets
134148
)
135149

136150
var swiftSettings: [SwiftSetting] { [

Sources/CSQLite/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module CSQLite [system] {
2+
header "sqlite3.h"
3+
link "sqlite3"
4+
export *
5+
}

Sources/SQLiteNio/SQLiteBackup.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#if canImport(SQLite3)
12
import SQLite3
3+
#else
4+
import CSQLite
5+
#endif
26
import Foundation
37
import NIOCore
48
import SQLNioCore

Sources/SQLiteNio/SQLiteConnection.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#if canImport(SQLite3)
12
import SQLite3
3+
#else
4+
import CSQLite
5+
#endif
26
import Foundation
37
import NIOCore
48
import NIOPosix

0 commit comments

Comments
 (0)