Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ jobs:
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
run: |
swift test -v
swift test -v --traits Encryption
35 changes: 16 additions & 19 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

// Note: Keep in sync with https://github.com/powersync-ja/powersync-kotlin/blob/main/plugins/build-plugin/src/main/kotlin/com/powersync/compile/ClangCompile.kt
let compileTimeOptions: [CSetting] = [
.define("HAVE_GETHOSTUUID", to: "0"),
.define("SQLITE_ENABLE_DBSTAT_VTAB"),
.define("SQLITE_ENABLE_FTS5"),
.define("SQLITE_ENABLE_SNAPSHOT"),
.define("SQLITE_ENABLE_SESSION"),
.define("SQLITE_ENABLE_PREUPDATE_HOOK")
]

let package = Package(
name: "CSQLite",
products: [
Expand All @@ -22,19 +12,26 @@ let package = Package(
targets: ["CSQLite"]
),
],
traits: [
.trait(name: "Encryption"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "CSQLite",
cSettings: compileTimeOptions,
linkerSettings: [
.linkedLibrary("m")
]
),
.target(
name: "CSQLite3MultipleCiphers",
cSettings: compileTimeOptions,
exclude: ["_sqlite", "_sqlite3mc"],
cSettings: [
// Note: Keep in sync with https://github.com/powersync-ja/powersync-kotlin/blob/main/plugins/build-plugin/src/main/kotlin/com/powersync/compile/ClangCompile.kt
.define("HAVE_GETHOSTUUID", to: "0"),
.define("SQLITE_ENABLE_DBSTAT_VTAB"),
.define("SQLITE_ENABLE_FTS5"),
.define("SQLITE_ENABLE_SNAPSHOT"),
.define("SQLITE_ENABLE_SESSION"),
.define("SQLITE_ENABLE_PREUPDATE_HOOK"),

.define("USE_SQLITE3MC", .when(traits: ["Encryption"]))
],
linkerSettings: [
.linkedLibrary("m")
]
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Sources/CSQLite/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module CSQLite {
header "sqlite3.h"
header "sqlite3_entry.h"
export *
}
5 changes: 5 additions & 0 deletions Sources/CSQLite/include/sqlite3_entry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifdef USE_SQLITE3MC
#include "../_sqlite3mc/sqlite3.h"
#else
#include "../_sqlite/sqlite3.h"
#endif
5 changes: 5 additions & 0 deletions Sources/CSQLite/sqlite3_entry.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifdef USE_SQLITE3MC
#include "_sqlite3mc/sqlite3mc_amalgamation.c"
#else
#include "_sqlite/sqlite3.c"
#endif
4 changes: 0 additions & 4 deletions Sources/CSQLite3MultipleCiphers/include/module.modulemap

This file was deleted.

20 changes: 19 additions & 1 deletion Tests/CSQLiteTests/CSQLiteTests.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import Testing
@testable import CSQLite

#if Encryption
let encryption = true
#else
let encryption = false
#endif

@Test func smoke_test() throws {
var db: OpaquePointer?
#expect(sqlite3_open_v2(":memory:", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nil) == SQLITE_OK)
try #require(sqlite3_open_v2(":memory:", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nil) == SQLITE_OK)
#expect(sqlite3_close_v2(db) == SQLITE_OK)
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
}

@Test(.disabled(if: !encryption)) func links_sqlite3mc() throws {
var db: OpaquePointer?
try #require(sqlite3_open_v2(":memory:", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nil) == SQLITE_OK)

var stmt: OpaquePointer?
try #require(sqlite3_prepare_v2(db, "pragma cipher", 13, &stmt, nil) == SQLITE_OK)
try #require(sqlite3_step(stmt) == SQLITE_ROW)
let cipher = String(cString: sqlite3_column_text(stmt, 0))
#expect(cipher == "chacha20")
#expect(sqlite3_close_v2(db) == SQLITE_OK)
}
8 changes: 4 additions & 4 deletions download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ cd tmp
curl -o amalgamation.zip -L https://github.com/utelle/SQLite3MultipleCiphers/releases/download/v2.2.6/sqlite3mc-2.2.6-sqlite-3.51.1-amalgamation.zip
unzip amalgamation.zip

mv sqlite3.h ../Sources/CSQLite/include/
mv sqlite3.c ../Sources/CSQLite/
mv sqlite3.h ../Sources/CSQLite/_sqlite/
mv sqlite3.c ../Sources/CSQLite/_sqlite/

mv sqlite3mc_amalgamation.h ../Sources/CSQLite3MultipleCiphers/include/sqlite3.h
mv sqlite3mc_amalgamation.c ../Sources/CSQLite3MultipleCiphers/
mv sqlite3mc_amalgamation.h ../Sources/CSQLite/_sqlite3mc/sqlite3.h
mv sqlite3mc_amalgamation.c ../Sources/CSQLite/_sqlite3mc/

cd ..
rm -r tmp