Skip to content

Commit 3b93e0a

Browse files
authored
Embed sqlite amalgamation v3.40.0 source code (#35)
* Embed sqlite amalgamation v3.40.0 source code * Includes swift script for bumping to the latest patch version, inspecting the system's sqlite3 compile options, and updating to an arbitrary version * Use sqlite serialized threading on linux * Use async interfaces in vendor-sqlite3 * Prefix sqlite amalgamation symbols with "sqlite_nio_" * Update CI to not depend on system libsqlite3 * Adjust CSQLite compile options to Ubuntu 22.04 Co-authored-by: Austin Payne <[email protected]>
1 parent f68a2bc commit 3b93e0a

File tree

12 files changed

+241016
-53
lines changed

12 files changed

+241016
-53
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@ jobs:
1313
runs-on: ubuntu-latest
1414
container: swift:5.7-jammy
1515
steps:
16-
# N.B.: When we switch to embedded SQLite, these first two steps should be removed,
17-
# and the version saved to the environment should come from the checked-out package.
18-
- name: Install libsqlite3 dependency
19-
run: apt-get -q update && apt-get -q install -y libsqlite3-dev
2016
- name: Save SQLite version to env
2117
run: |
22-
echo SQLITE_VERSION="$(pkg-config --modversion sqlite3)" >> $GITHUB_ENV
18+
echo SQLITE_VERSION="$(cat Sources/CSQLite/version.txt | grep -v '//')" >> $GITHUB_ENV
2319
- name: Check out package
2420
uses: actions/checkout@v3
2521
- name: Run local tests with coverage
@@ -39,8 +35,6 @@ jobs:
3935
runs-on: ubuntu-latest
4036
container: swift:5.7-jammy
4137
steps:
42-
- name: Install libsqlite3 dependency
43-
run: apt-get -q update && apt-get -q install -y libsqlite3-dev
4438
- name: Check out package
4539
uses: actions/checkout@v3
4640
with:
@@ -57,8 +51,6 @@ jobs:
5751
runs-on: ubuntu-latest
5852
container: swift:5.7-jammy
5953
steps:
60-
- name: Install libsqlite3 dependency
61-
run: apt-get -q update && apt-get -q install -y libsqlite3-dev
6254
- name: Check out package
6355
uses: actions/checkout@v3
6456
with:
@@ -96,8 +88,6 @@ jobs:
9688
container: ${{ matrix.runner }}
9789
runs-on: ubuntu-latest
9890
steps:
99-
- name: Install libsqlite3 dependency
100-
run: apt-get -q update && apt-get -q install -y libsqlite3-dev
10191
- name: Check out code
10292
uses: actions/checkout@v3
10393
- name: Run tests with Thread Sanitizer

Package.swift

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ let package = Package(
99
],
1010
products: [
1111
.library(name: "SQLiteNIO", targets: ["SQLiteNIO"]),
12+
// This target is only used to add our vendor prefix and is added and removed automatically.
13+
// See: scripts/vendor-sqlite3.swift
14+
/* VENDOR_START
15+
.library(name: "CSQLite", type: .static, targets: ["CSQLite"]),
16+
VENDOR_END */
1217
],
1318
dependencies: [
1419
.package(url: "https://github.com/apple/swift-nio.git", from: "2.42.0"),
1520
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
1621
],
1722
targets: [
18-
.systemLibrary(
19-
name: "CSQLite",
20-
providers: [
21-
.apt(["libsqlite3-dev"]),
22-
.brew(["sqlite3"])
23-
]
24-
),
2523
.target(name: "SQLiteNIO", dependencies: [
2624
.target(name: "CSQLite"),
2725
.product(name: "Logging", package: "swift-log"),
@@ -30,3 +28,61 @@ let package = Package(
3028
.testTarget(name: "SQLiteNIOTests", dependencies: ["SQLiteNIO"]),
3129
]
3230
)
31+
32+
// Derived from sqlite3 version 3.37.2 2022-01-06 13:25:41 872ba256cbf61d9290b571c0e6d82a20c224ca3ad82971edc46b29818d5dalt1
33+
// compiled with gcc-11.3.0
34+
// on platform Ubuntu 22.04.1 LTS (Jammy Jellyfish)
35+
var cSQLiteSettings: [CSetting] = [
36+
.define("SQLITE_ENABLE_COLUMN_METADATA"),
37+
.define("SQLITE_ENABLE_DBSTAT_VTAB"),
38+
.define("SQLITE_ENABLE_FTS3"),
39+
.define("SQLITE_ENABLE_FTS3_PARENTHESIS"),
40+
.define("SQLITE_ENABLE_FTS3_TOKENIZER"),
41+
.define("SQLITE_ENABLE_FTS4"),
42+
.define("SQLITE_ENABLE_FTS5"),
43+
.define("SQLITE_ENABLE_JSON1"),
44+
.define("SQLITE_ENABLE_PREUPDATE_HOOK"),
45+
.define("SQLITE_ENABLE_RTREE"),
46+
.define("SQLITE_ENABLE_SESSION"),
47+
.define("SQLITE_ENABLE_STMTVTAB"),
48+
.define("SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION"),
49+
.define("SQLITE_ENABLE_UNLOCK_NOTIFY"),
50+
.define("SQLITE_ENABLE_UPDATE_DELETE_LIMIT"),
51+
.define("SQLITE_HAVE_ISNAN"),
52+
.define("SQLITE_LIKE_DOESNT_MATCH_BLOBS"),
53+
.define("SQLITE_MUTEX_PTHREADS"),
54+
.define("SQLITE_OMIT_LOAD_EXTENSION"),
55+
.define("SQLITE_OMIT_LOOKASIDE"),
56+
.define("SQLITE_SECURE_DELETE"),
57+
.define("SQLITE_SYSTEM_MALLOC"),
58+
.define("SQLITE_USE_URI"),
59+
]
60+
61+
#if os(macOS)
62+
// Derived from sqlite3 version 3.37.0 2021-12-09 01:34:53 9ff244ce0739f8ee52a3e9671adb4ee54c83c640b02e3f9d185fd2f9a179aapl
63+
// compiled with clang-13.1.6
64+
// on platform macOS 12.6 (21G115)
65+
cSQLiteSettings.append(contentsOf: [
66+
.define("SQLITE_DEFAULT_CACHE_SIZE", to: "2000"),
67+
.define("SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT", to: "32768"),
68+
.define("SQLITE_DEFAULT_LOOKASIDE", to: "1200,102"),
69+
.define("SQLITE_DEFAULT_MEMSTATUS", to: "0"),
70+
.define("SQLITE_DEFAULT_MMAP_SIZE", to: "0"),
71+
.define("SQLITE_DEFAULT_PAGE_SIZE", to: "4096"),
72+
.define("SQLITE_DEFAULT_PCACHE_INITSZ", to: "20"),
73+
.define("SQLITE_DEFAULT_SYNCHRONOUS", to: "2"),
74+
.define("SQLITE_DEFAULT_WAL_AUTOCHECKPOINT", to: "1000"),
75+
.define("SQLITE_DEFAULT_WAL_SYNCHRONOUS", to: "1"),
76+
.define("SQLITE_DEFAULT_WORKER_THREADS", to: "0"),
77+
.define("SQLITE_ENABLE_LOCKING_STYLE", to: "1"),
78+
.define("SQLITE_MAX_MMAP_SIZE", to: "1073741824"),
79+
])
80+
#endif
81+
82+
package.targets.append(
83+
.target(
84+
name: "CSQLite",
85+
dependencies: [],
86+
cSettings: cSQLiteSettings
87+
)
88+
)

Sources/CSQLite/csqlite.c

Lines changed: 0 additions & 1 deletion
This file was deleted.

Sources/CSQLite/csqlite.h

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)