From 53e654532d1b2584e9486e463a4aa28071271bf3 Mon Sep 17 00:00:00 2001 From: Oleksii Zghurskyi Date: Wed, 23 Apr 2025 20:28:12 +0300 Subject: [PATCH] Add SQLite system library package --- .gitignore | 17 ++++++ .swift-format | 15 ++++++ Package.swift | 27 ++++++++++ README.md | 83 ++++++++++++++++++++++++++++++ Sources/DataLiteC/module.modulemap | 5 ++ Sources/DataLiteC/shim.h | 6 +++ 6 files changed, 153 insertions(+) create mode 100644 .gitignore create mode 100644 .swift-format create mode 100644 Package.swift create mode 100644 Sources/DataLiteC/module.modulemap create mode 100644 Sources/DataLiteC/shim.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..67356a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +## General +.DS_Store +.swiftpm +.build/ + +## Various settings +Package.resolved +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ +*.xcuserdatad/ diff --git a/.swift-format b/.swift-format new file mode 100644 index 0000000..b77abe6 --- /dev/null +++ b/.swift-format @@ -0,0 +1,15 @@ +{ + "fileScopedDeclarationPrivacy": { + "accessLevel": "private" + }, + "indentBlankLines": true, + "indentation": { + "spaces": 4 + }, + "lineLength": 9999, + "maximumBlankLines": 1, + "multiElementCollectionTrailingCommas": false, + "rules": { + "FileScopedDeclarationPrivacy": true + } +} diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..fd99f00 --- /dev/null +++ b/Package.swift @@ -0,0 +1,27 @@ +// swift-tools-version: 5.10 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +#if os(Linux) +let sqlitePkg = "sqlite3" +#else +let sqlitePkg: String? = nil +#endif + +let package = Package( + name: "DataLiteC", + platforms: [ + .macOS(.v10_14), + .iOS(.v12) + ], + products: [ + .library(name: "DataLiteC", targets: ["DataLiteC"]) + ], + targets: [ + .systemLibrary(name: "DataLiteC", pkgConfig: sqlitePkg, providers: [ + .apt(["sqlite3", "libsqlite3-dev"]), + .brew(["sqlite"]) + ]) + ] +) diff --git a/README.md b/README.md index d73b2b8..d111167 100644 --- a/README.md +++ b/README.md @@ -1 +1,84 @@ # DataLiteC Package + +**DataLiteC** is a Swift package that provides a system interface to the SQLite C library. It supports **macOS**, **iOS**, and **Linux** platforms, using the system SQLite library via `pkg-config`. + +## Overview + +DataLiteC is a Swift system library wrapper that links directly to the SQLite C API. It does not add any abstractions and enables direct usage of SQLite's C functions within Swift code. + +## Installation + +### Adding DataLiteC to Your Project + +To use DataLiteC in your Swift project, add it to the dependencies section of your `Package.swift` file: + +```swift +// swift-tools-version: 5.10 + +import PackageDescription + +let package = Package( + name: "YourProject", + dependencies: [ + .package(url: "https://github.com/angd-dev/data-lite-c.git", from: "1.0.0") + ], + targets: [ + .target( + name: "YourTarget", + dependencies: [ + .product(name: "DataLiteC", package: "data-lite-c") + ] + ) + ] +) +``` + +### System Requirements + +DataLiteC requires SQLite to be installed on your system: + +- **Linux**: Install `sqlite3` and development headers: + + ```bash + sudo apt-get install sqlite3 libsqlite3-dev + ``` + +- **macOS**: Install SQLite using Homebrew: + + ```bash + brew install sqlite + ``` + +## Usage + +Once the package is added, you can import it and use SQLite's C API directly: + +```swift +import DataLiteC + +var db: OpaquePointer? +if sqlite3_open(":memory:", &db) == SQLITE_OK { + print("Successfully opened connection to database.") + sqlite3_close(db) +} else { + print("Unable to open database.") +} +``` + +## Troubleshooting + +If you encounter build errors such as missing `sqlite3.h`, ensure that `pkg-config` can locate SQLite: + +```bash +pkg-config --cflags sqlite3 +``` + +If the command returns nothing, manually set the `PKG_CONFIG_PATH`: + +```bash +export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH" +``` + +## License + +This project is licensed under the MIT License. See the `LICENSE` file for details. diff --git a/Sources/DataLiteC/module.modulemap b/Sources/DataLiteC/module.modulemap new file mode 100644 index 0000000..2f51613 --- /dev/null +++ b/Sources/DataLiteC/module.modulemap @@ -0,0 +1,5 @@ +module DataLiteC [system] { + header "shim.h" + link "sqlite3" + export * +} diff --git a/Sources/DataLiteC/shim.h b/Sources/DataLiteC/shim.h new file mode 100644 index 0000000..08fc10f --- /dev/null +++ b/Sources/DataLiteC/shim.h @@ -0,0 +1,6 @@ +#ifndef C_SQLITE_H +#define C_SQLITE_H + +#include + +#endif