Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
711cc96
Refactor extensions into separate target
sbooth Jun 5, 2021
5048191
Merge branch 'main' into extension-refactor
sbooth May 24, 2024
3e49f1d
Rename class and add header
sbooth May 24, 2024
bd61218
Update header comment
sbooth May 24, 2024
e775e9a
Merge branch 'main' into extension-refactor
sbooth Jun 2, 2024
63e8a0a
Update module maps
sbooth Jun 2, 2024
1226517
Merge branch 'main' into extension-refactor
sbooth Oct 23, 2024
4bf0144
Merge branch 'main' into extension-refactor
sbooth Oct 24, 2024
9afebf0
Move percentile.c
sbooth Oct 24, 2024
1d12543
Move SQLITE_CORE define
sbooth Oct 24, 2024
caffceb
Merge branch 'main' into extension-refactor
sbooth Oct 25, 2024
4a758b4
Merge branch 'main' into extension-refactor
sbooth Jan 3, 2025
00c7d9e
Merge branch 'main' into extension-refactor
sbooth Feb 7, 2025
1af178c
Merge branch 'main' into extension-refactor
sbooth Feb 19, 2025
e5d3afe
Merge branch 'main' into extension-refactor
sbooth May 21, 2025
9509c21
Merge branch 'main' into extension-refactor
sbooth May 28, 2025
e7927b8
Update Swift 5.3 package
sbooth May 28, 2025
aa69faf
Reorder `header`
sbooth May 29, 2025
3feeaad
Reorganize extensions and add traits for each
sbooth May 30, 2025
1ce1669
Remove comment
sbooth May 30, 2025
47fc68b
Add extension targets
sbooth May 30, 2025
4f09404
Merge branch 'main' into extension-refactor
sbooth May 30, 2025
9620531
Fix copy/paste error
sbooth May 30, 2025
02fd6be
Remove -
sbooth May 30, 2025
5767432
Use plain C for CSQLiteExtensions module
sbooth May 30, 2025
9c8f913
Revert "Use plain C for CSQLiteExtensions module"
sbooth May 31, 2025
188d2aa
Merge branch 'main' into extension-refactor-2
sbooth Jun 1, 2025
9abbf31
Merge branch 'main' into extension-refactor-2
sbooth Jun 6, 2025
9c0839d
Merge branch 'main' into extension-refactor-2
sbooth Jun 6, 2025
b6f6bca
Merge branch 'main' into extension-refactor-2
sbooth Mar 7, 2026
d55f8aa
Fix tests
sbooth Mar 7, 2026
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
100 changes: 96 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ let package = Package(
name: "CSQLite",
targets: [
"CSQLite",
"CSQLiteExtensions",
]),
],
traits: [
Expand Down Expand Up @@ -261,6 +262,27 @@ let package = Package(
name: "ENABLE_STAT4",
description: "Enables the sqlite_stat4 table"
),
// Statically linked extensions
.trait(
name: "CSQLITE_ENABLE_DECIMAL_EXTENSION",
description: "Enables the statically linked decimal extension"
),
.trait(
name: "CSQLITE_ENABLE_IEEE754_EXTENSION",
description: "Enables the statically linked ieee754 extension"
),
.trait(
name: "CSQLITE_ENABLE_SERIES_EXTENSION",
description: "Enables the statically linked series extension"
),
.trait(
name: "CSQLITE_ENABLE_SHA3_EXTENSION",
description: "Enables the statically linked sha3 extension"
),
.trait(
name: "CSQLITE_ENABLE_UUID_EXTENSION",
description: "Enables the statically linked uuid extension"
),
// Default traits
.default(enabledTraits: [
"DQS_0",
Expand All @@ -284,26 +306,96 @@ let package = Package(
"ENABLE_SNAPSHOT",
"ENABLE_STMTVTAB",
"ENABLE_STAT4",
"CSQLITE_ENABLE_DECIMAL_EXTENSION",
"CSQLITE_ENABLE_IEEE754_EXTENSION",
"CSQLITE_ENABLE_SERIES_EXTENSION",
"CSQLITE_ENABLE_SHA3_EXTENSION",
"CSQLITE_ENABLE_UUID_EXTENSION",
]),
],
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 + platformConfiguration + features + [
cSettings: compileTimeOptions + platformConfiguration + features,
linkerSettings: [
.linkedLibrary("m"),
]),
.target(
name: "CSQLiteExtensions",
dependencies: [
.targetItem(name: "CSQLiteDecimalExtension", condition: .when(traits: ["CSQLITE_ENABLE_DECIMAL_EXTENSION"])),
.targetItem(name: "CSQLiteIEEE754Extension", condition: .when(traits: ["CSQLITE_ENABLE_IEEE754_EXTENSION"])),
.targetItem(name: "CSQLiteSeriesExtension", condition: .when(traits: ["CSQLITE_ENABLE_SERIES_EXTENSION"])),
.targetItem(name: "CSQLiteSHA3Extension", condition: .when(traits: ["CSQLITE_ENABLE_SHA3_EXTENSION"])),
.targetItem(name: "CSQLiteUUIDExtension", condition: .when(traits: ["CSQLITE_ENABLE_UUID_EXTENSION"])),
]),
.target(
name: "CSQLiteDecimalExtension",
dependencies: [
"CSQLite",
],
path: "Sources/extensions/decimal",
cSettings: [
// For statically linking extensions
// https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension
.define("SQLITE_CORE", to: "1"),
]),
.target(
name: "CSQLiteIEEE754Extension",
dependencies: [
"CSQLite",
],
linkerSettings: [
.linkedLibrary("m"),
path: "Sources/extensions/ieee754",
cSettings: [
// For statically linking extensions
// https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension
.define("SQLITE_CORE", to: "1"),
]),
.target(
name: "CSQLiteSeriesExtension",
dependencies: [
"CSQLite",
],
path: "Sources/extensions/series",
cSettings: [
// For statically linking extensions
// https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension
.define("SQLITE_CORE", to: "1"),
]),
.target(
name: "CSQLiteSHA3Extension",
dependencies: [
"CSQLite",
],
path: "Sources/extensions/sha3",
cSettings: [
// For statically linking extensions
// https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension
.define("SQLITE_CORE", to: "1"),
]),
.target(
name: "CSQLiteUUIDExtension",
dependencies: [
"CSQLite",
],
path: "Sources/extensions/uuid",
cSettings: [
// For statically linking extensions
// https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension
.define("SQLITE_CORE", to: "1"),
]),
.testTarget(
name: "CSQLiteTests",
dependencies: [
"CSQLite",
])
]),
.testTarget(
name: "CSQLiteExtensionsTests",
dependencies: [
"CSQLiteExtensions",
]),
],
cLanguageStandard: .gnu11
)
74 changes: 70 additions & 4 deletions Package@swift-5.3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,92 @@ let package = Package(
name: "CSQLite",
targets: [
"CSQLite",
"CSQLiteExtensions",
]),
],
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 + platformConfiguration + features + [
cSettings: compileTimeOptions + platformConfiguration + features,
linkerSettings: [
.linkedLibrary("m"),
]),
.target(
name: "CSQLiteExtensions",
dependencies: [
"CSQLiteDecimalExtension",
"CSQLiteIEEE754Extension",
"CSQLiteSeriesExtension",
"CSQLiteSHA3Extension",
"CSQLiteUUIDExtension",
]),
.target(
name: "CSQLiteDecimalExtension",
dependencies: [
"CSQLite",
],
path: "Sources/extensions/decimal",
cSettings: [
// For statically linking extensions
// https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension
.define("SQLITE_CORE", to: "1"),
]),
.target(
name: "CSQLiteIEEE754Extension",
dependencies: [
"CSQLite",
],
linkerSettings: [
.linkedLibrary("m"),
path: "Sources/extensions/ieee754",
cSettings: [
// For statically linking extensions
// https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension
.define("SQLITE_CORE", to: "1"),
]),
.target(
name: "CSQLiteSeriesExtension",
dependencies: [
"CSQLite",
],
path: "Sources/extensions/series",
cSettings: [
// For statically linking extensions
// https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension
.define("SQLITE_CORE", to: "1"),
]),
.target(
name: "CSQLiteSHA3Extension",
dependencies: [
"CSQLite",
],
path: "Sources/extensions/sha3",
cSettings: [
// For statically linking extensions
// https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension
.define("SQLITE_CORE", to: "1"),
]),
.target(
name: "CSQLiteUUIDExtension",
dependencies: [
"CSQLite",
],
path: "Sources/extensions/uuid",
cSettings: [
// For statically linking extensions
// https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension
.define("SQLITE_CORE", to: "1"),
]),
.testTarget(
name: "CSQLiteTests",
dependencies: [
"CSQLite",
])
]),
.testTarget(
name: "CSQLiteExtensionsTests",
dependencies: [
"CSQLiteExtensions",
]),
],
cLanguageStandard: .gnu11
)
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ The following traits enable commonly-used SQLite features:
> [!NOTE]
> The `ENABLE_SESSION` trait also sets the `ENABLE_PREUPDATE_HOOK` trait.

### Statically Linked Extensions

The following traits enable statically linked SQLite extensions and helper functions for automatic extension registration:

| Package Trait | Default | SQLite Extension |
| --- | :---: | --- |
| CSQLITE_ENABLE_DECIMAL_EXTENSION | Y | [decimal](https://sqlite.org/floatingpoint.html#the_decimal_c_extension) |
| CSQLITE_ENABLE_IEEE754_EXTENSION | Y | [ieee754](https://sqlite.org/floatingpoint.html#the_ieee754_c_extension) |
| CSQLITE_ENABLE_SERIES_EXTENSION | Y | [series](https://www.sqlite.org/src/file/ext/misc/series.c) |
| CSQLITE_ENABLE_SHA3_EXTENSION | Y | [sha3](https://www.sqlite.org/src/file/ext/misc/shathree.c) |
| CSQLITE_ENABLE_UUID_EXTENSION | Y | [uuid](https://www.sqlite.org/src/file/ext/misc/uuid.c) |

## License

SQLite is in the [public domain](https://sqlite.org/copyright.html).
57 changes: 0 additions & 57 deletions Sources/CSQLite/csqlite_shims.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,60 +295,3 @@ int csqlite_sqlite3_vtab_uses_all_schemas(sqlite3 *db)
{
return sqlite3_vtab_config(db, SQLITE_VTAB_USES_ALL_SCHEMAS);
}

// MARK: - Database extensions

void sqlite3_decimal_init(void);
int csqlite_sqlite3_auto_extension_decimal()
{
return sqlite3_auto_extension(sqlite3_decimal_init);
}

int csqlite_sqlite3_cancel_auto_extension_decimal()
{
return sqlite3_cancel_auto_extension(sqlite3_decimal_init);
}

void sqlite3_ieee_init(void);
int csqlite_sqlite3_auto_extension_ieee754()
{
return sqlite3_auto_extension(sqlite3_ieee_init);
}

int csqlite_sqlite3_cancel_auto_extension_ieee754()
{
return sqlite3_cancel_auto_extension(sqlite3_ieee_init);
}

void sqlite3_series_init(void);
int csqlite_sqlite3_auto_extension_series()
{
return sqlite3_auto_extension(sqlite3_series_init);
}

int csqlite_sqlite3_cancel_auto_extension_series()
{
return sqlite3_cancel_auto_extension(sqlite3_series_init);
}

void sqlite3_shathree_init(void);
int csqlite_sqlite3_auto_extension_sha3()
{
return sqlite3_auto_extension(sqlite3_shathree_init);
}

int csqlite_sqlite3_cancel_auto_extension_sha3()
{
return sqlite3_cancel_auto_extension(sqlite3_shathree_init);
}

void sqlite3_uuid_init(void);
int csqlite_sqlite3_auto_extension_uuid()
{
return sqlite3_auto_extension(sqlite3_uuid_init);
}

int csqlite_sqlite3_cancel_auto_extension_uuid()
{
return sqlite3_cancel_auto_extension(sqlite3_uuid_init);
}
28 changes: 0 additions & 28 deletions Sources/CSQLite/include/csqlite_shims.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,31 +141,3 @@ int csqlite_sqlite3_vtab_config_innocuous(sqlite3 *db);
int csqlite_sqlite3_vtab_config_directonly(sqlite3 *db);
/// Equivalent to `sqlite3_vtab_config(db, SQLITE_VTAB_USES_ALL_SCHEMAS)`
int csqlite_sqlite3_vtab_uses_all_schemas(sqlite3 *db);

// MARK: - Database extensions
// See https://sqlite.org/loadext.html

/// Equivalent to `sqlite3_auto_extension(sqlite3_decimal_init)`
int csqlite_sqlite3_auto_extension_decimal(void);
/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_decimal_init)`
int csqlite_sqlite3_cancel_auto_extension_decimal(void);

/// Equivalent to `sqlite3_auto_extension(sqlite3_ieee_init)`
int csqlite_sqlite3_auto_extension_ieee754(void);
/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_ieee_init)`
int csqlite_sqlite3_cancel_auto_extension_ieee754(void);

/// Equivalent to `sqlite3_auto_extension(sqlite3_series_init)`
int csqlite_sqlite3_auto_extension_series(void);
/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_series_init)`
int csqlite_sqlite3_cancel_auto_extension_series(void);

/// Equivalent to `sqlite3_auto_extension(sqlite3_shathree_init)`
int csqlite_sqlite3_auto_extension_sha3(void);
/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_shathree_init)`
int csqlite_sqlite3_cancel_auto_extension_sha3(void);

/// Equivalent to `sqlite3_auto_extension(sqlite3_uuid_init)`
int csqlite_sqlite3_auto_extension_uuid(void);
/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_uuid_init)`
int csqlite_sqlite3_cancel_auto_extension_uuid(void);
38 changes: 38 additions & 0 deletions Sources/CSQLiteExtensions/CSQLiteExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
** 2025-05-30
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** Functions to manage automatic database extension registration from Swift.
*/

#if false
@_exported import CSQLite
#endif

#if swift(<6.1) || CSQLITE_ENABLE_DECIMAL_EXTENSION
@_exported import CSQLiteDecimalExtension
#endif

#if swift(<6.1) || CSQLITE_ENABLE_IEEE754_EXTENSION
@_exported import CSQLiteIEEE754Extension
#endif

#if swift(<6.1) || CSQLITE_ENABLE_SERIES_EXTENSION
@_exported import CSQLiteSeriesExtension
#endif

#if swift(<6.1) || CSQLITE_ENABLE_SHA3_EXTENSION
@_exported import CSQLiteSHA3Extension
#endif

#if swift(<6.1) || CSQLITE_ENABLE_UUID_EXTENSION
@_exported import CSQLiteUUIDExtension
#endif
Loading