Skip to content

Commit c096278

Browse files
committed
SQLCipher support (GRDB 5.26.0, SQLCipher 4.5.1)
1 parent 23f4254 commit c096278

File tree

9 files changed

+260149
-20
lines changed

9 files changed

+260149
-20
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GRDB/Export.swift merge=ours
2+
Sources/CSQLite merge=ours
3+
Sources/SQLCipher/include/SQLCipher_config.h merge=ours

.github/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# GRBD + SQLCipher
2+
3+
## What is this?
4+
This is a fork of [GRBD](https://github.com/groue/GRDB.swift) which contains a [SQLCipher Community Edition](https://www.zetetic.net/sqlcipher/open-source/) amalgamation packaged so that it can be consumed as a Swift Package.
5+
6+
The default branch for this repository is `SQLCipher` so that we can more easily pull upstream changes if we need to.
7+
8+
## Versioning
9+
10+
* This Package: *1.2.1*
11+
* GRDB: *5.26.0*
12+
* SQLCipher: *4.5.1*
13+
14+
## Contributions
15+
We do not accept contributions to this repository at this time. However, feel free to open an issue in order to start a discussion.
16+
17+
## We are hiring!
18+
DuckDuckGo is growing fast and we continue to expand our fully distributed team. We embrace diverse perspectives, and seek out passionate, self-motivated people, committed to our shared vision of raising the standard of trust online. If you are a senior software engineer capable in either iOS or Android, visit our [careers](https://duckduckgo.com/hiring/#open) page to find out more about our openings!
19+
20+
## Updating from Upstream
21+
22+
Add remote upstream:
23+
24+
* `git remote add upstream [email protected]:groue/GRDB.swift.git`
25+
26+
Check out upstream's master branch locally:
27+
28+
* `git fetch upstream +master:upstream-master && git checkout upstream-master`
29+
30+
Branch off upstream's branch:
31+
32+
* `git checkout -b relase/x.y.z-grdb-a.b.c-sqlcipher-i.j.k`
33+
34+
where `x.y.z` is the new version, `a.b.c` is the upstream GRDB version and `i.j.k` is the SQLCipher version.
35+
36+
Apply the original version of the SQLCipher patch:
37+
38+
* `git am -3 0001-SQLCipher-support.patch`
39+
40+
Compile SQLCipher amalgamation package [see general instructions](https://github.com/sqlcipher/sqlcipher#compiling-for-unix-like-systems):
41+
42+
* Use `./configure --with-crypto-lib=none`
43+
* Remember to use `make sqlite3.c` and not `make`.
44+
* Copy `sqlite3.c` and `sqlite3.h` to `Sources/SQLCipher/sqlite3.c` and `Sources/SQLCipher/include/sqlite3.h`
45+
46+
Then update the README to state the versions used. Commit and push your branch, create PR for BSK referencing your new branch,
47+
and then create PRs for iOS and macOS apps referencing your BSK branch.
48+
49+
Once merged, tag the branch with a version according to how the version of GRDB was updated,
50+
i.e. maintaining [Semantic Versioning Rules](https://semver.org), but note you don't need
51+
to follow the version number of GRDB directly.
52+
53+
Examples:
54+
55+
* Upstream GRDB 5.6.0, after merge -> 5.12.0
56+
* This project 1.0.0 -> 1.1.0
57+
58+
* Upstream GRDB 5.12.0, after merge -> 6.0.0
59+
* This project 1.1.0 -> 2.0.0

GRDB/Export.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
// Export the underlying SQLite library
2-
#if SWIFT_PACKAGE
3-
@_exported import CSQLite
4-
#elseif GRDBCIPHER
51
@_exported import SQLCipher
6-
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
7-
@_exported import SQLite3
8-
#endif

Package.swift

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,62 @@ let package = Package(
1818
dependencies: [
1919
],
2020
targets: [
21-
.systemLibrary(
22-
name: "CSQLite",
23-
providers: [.apt(["libsqlite3-dev"])]),
2421
.target(
2522
name: "GRDB",
26-
dependencies: ["CSQLite"],
27-
path: "GRDB"),
23+
dependencies: ["SQLCipher"],
24+
path: "GRDB",
25+
cSettings: [
26+
.define("SQLITE_HAS_CODEC"),
27+
.define("SQLITE_TEMP_STORE", to: "2"),
28+
.define("SQLITE_SOUNDEX"),
29+
.define("SQLITE_THREADSAFE"),
30+
.define("SQLITE_ENABLE_RTREE"),
31+
.define("SQLITE_ENABLE_STAT3"),
32+
.define("SQLITE_ENABLE_STAT4"),
33+
.define("SQLITE_ENABLE_COLUMN_METADATA"),
34+
.define("SQLITE_ENABLE_MEMORY_MANAGEMENT"),
35+
.define("SQLITE_ENABLE_LOAD_EXTENSION"),
36+
.define("SQLITE_ENABLE_FTS4"),
37+
.define("SQLITE_ENABLE_FTS4_UNICODE61"),
38+
.define("SQLITE_ENABLE_FTS3_PARENTHESIS"),
39+
.define("SQLITE_ENABLE_UNLOCK_NOTIFY"),
40+
.define("SQLITE_ENABLE_JSON1"),
41+
.define("SQLITE_ENABLE_FTS5"),
42+
.define("SQLCIPHER_CRYPTO_CC"),
43+
.define("HAVE_USLEEP", to: "1"),
44+
.define("SQLITE_MAX_VARIABLE_NUMBER", to: "99999")
45+
],
46+
swiftSettings: [
47+
.define("SQLITE_HAS_CODEC"),
48+
.define("GRDBCIPHER"),
49+
.define("SQLITE_ENABLE_FTS5")
50+
]),
51+
.target(
52+
name: "SQLCipher",
53+
cSettings: [
54+
.define("NDEBUG"),
55+
.define("SQLITE_HAS_CODEC"),
56+
.define("SQLITE_TEMP_STORE", to: "2"),
57+
.define("SQLITE_SOUNDEX"),
58+
.define("SQLITE_THREADSAFE"),
59+
.define("SQLITE_ENABLE_RTREE"),
60+
.define("SQLITE_ENABLE_STAT3"),
61+
.define("SQLITE_ENABLE_STAT4"),
62+
.define("SQLITE_ENABLE_COLUMN_METADATA"),
63+
.define("SQLITE_ENABLE_MEMORY_MANAGEMENT"),
64+
.define("SQLITE_ENABLE_LOAD_EXTENSION"),
65+
.define("SQLITE_ENABLE_FTS4"),
66+
.define("SQLITE_ENABLE_FTS4_UNICODE61"),
67+
.define("SQLITE_ENABLE_FTS3_PARENTHESIS"),
68+
.define("SQLITE_ENABLE_UNLOCK_NOTIFY"),
69+
.define("SQLITE_ENABLE_JSON1"),
70+
.define("SQLITE_ENABLE_FTS5"),
71+
.define("SQLCIPHER_CRYPTO_CC"),
72+
.define("HAVE_USLEEP", to: "1"),
73+
.define("SQLITE_MAX_VARIABLE_NUMBER", to: "99999"),
74+
.define("HAVE_GETHOSTUUID", to: "0"),
75+
// .unsafeFlags(["-w"])
76+
]),
2877
.testTarget(
2978
name: "GRDBTests",
3079
dependencies: ["GRDB"],

Sources/CSQLite/module.modulemap

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

Sources/CSQLite/shim.h renamed to Sources/SQLCipher/include/SQLCipher_config.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
#include <sqlite3.h>
1+
#ifndef grdb_config_h
2+
#define grdb_config_h
23

3-
typedef void(*errorLogCallback)(void *pArg, int iErrCode, const char *zMsg);
4+
#include "sqlite3.h"
5+
6+
typedef void(*_errorLogCallback)(void *pArg, int iErrCode, const char *zMsg);
47

58
/// Wrapper around sqlite3_config(SQLITE_CONFIG_LOG, ...) which is a variadic
69
/// function that can't be used from Swift.
7-
static inline void registerErrorLogCallback(errorLogCallback callback) {
10+
static inline void registerErrorLogCallback(_errorLogCallback callback) {
811
sqlite3_config(SQLITE_CONFIG_LOG, callback, 0);
912
}
1013

@@ -26,3 +29,4 @@ static inline void enableDoubleQuotedStringLiterals(sqlite3 *db) {
2629
static inline void disableDoubleQuotedStringLiterals(sqlite3 *db) { }
2730
static inline void enableDoubleQuotedStringLiterals(sqlite3 *db) { }
2831
#endif
32+
#endif /* grdb_config_h */

0 commit comments

Comments
 (0)