|
| 1 | +// swift-tools-version:6.2 |
| 2 | +import PackageDescription |
| 3 | + |
| 4 | +let package = Package( |
| 5 | + name: "SQLiteKit", |
| 6 | + platforms: [ |
| 7 | + .macOS(.v13), |
| 8 | + .iOS(.v16), |
| 9 | + .tvOS(.v16), |
| 10 | + .watchOS(.v9), |
| 11 | + .visionOS(.v1), |
| 12 | + ], |
| 13 | + products: [ |
| 14 | + // The SDK: a thin, pure-Swift wrapper over the vendored SQLite |
| 15 | + // amalgamation. FTS5 and sqlite-vec ride along behind opt-in traits. |
| 16 | + .library(name: "SQLiteKit", targets: ["SQLiteKit"]), |
| 17 | + ], |
| 18 | + // Opt-in, build-time engine toggles. Both off by default. |
| 19 | + // • depending on this package: .package(url: …, traits: ["FTS5", "SQLiteVec"]) |
| 20 | + // • building this package direct: swift build --traits FTS5,SQLiteVec |
| 21 | + // See `fullTextSearchFTS5` / `semanticSearchSQLiteVec` / `vec0BlobBind` |
| 22 | + // in SQLiteKitTests for the on/off contract each trait pins. |
| 23 | + traits: [ |
| 24 | + .trait(name: "FTS5", |
| 25 | + description: "Compile SQLite with FTS5 full-text search."), |
| 26 | + .trait(name: "SQLiteVec", |
| 27 | + description: "Compile in sqlite-vec for on-device vector / semantic search."), |
| 28 | + ], |
| 29 | + dependencies: [ |
| 30 | + // Vendored SQLite amalgamation — a single public-domain `sqlite3.c` |
| 31 | + // packaged as a SwiftPM C target. Pinned exact so the engine version |
| 32 | + // is identical on every platform. Our `FTS5` trait forwards to |
| 33 | + // CSQLite's `FTS5` trait, which compiles the amalgamation with |
| 34 | + // `-DSQLITE_ENABLE_FTS5`. |
| 35 | + .package(url: "https://github.com/stephencelis/CSQLite", |
| 36 | + exact: "3.50.4", |
| 37 | + traits: [.trait(name: "FTS5", condition: .when(traits: ["FTS5"]))]), |
| 38 | + ], |
| 39 | + targets: [ |
| 40 | + // Typed C wrappers for SQLite's variadic printf (`sqlite3_mprintf`), |
| 41 | + // which Swift can't call directly — gives `SQLiteKit` byte-exact access |
| 42 | + // to the engine's float formatting for round-trip output. |
| 43 | + .target( |
| 44 | + name: "CSQLiteShim", |
| 45 | + dependencies: [ |
| 46 | + .product(name: "SQLiteSwiftCSQLite", package: "CSQLite"), |
| 47 | + ], |
| 48 | + publicHeadersPath: "include" |
| 49 | + ), |
| 50 | + // sqlite-vec, compiled statically into the engine for on-device vector |
| 51 | + // search. Linked only when the `SQLiteVec` trait is on (see SQLiteKit's |
| 52 | + // dependency below); no product exposes it, so consumers don't build it |
| 53 | + // unless they opt in. The vendored amalgamation (sqlite-vec.c) is |
| 54 | + // compiled via sqlite-vec-shim.c — which adds the one missing system |
| 55 | + // include — so it stays byte-for-byte upstream and is excluded from |
| 56 | + // direct compilation. See Sources/CSQLiteVec/README.md. |
| 57 | + .target( |
| 58 | + name: "CSQLiteVec", |
| 59 | + dependencies: [ |
| 60 | + .product(name: "SQLiteSwiftCSQLite", package: "CSQLite"), |
| 61 | + ], |
| 62 | + exclude: ["sqlite-vec.c", "README.md", "LICENSE-MIT", "LICENSE-APACHE"], |
| 63 | + publicHeadersPath: "include", |
| 64 | + cSettings: [ |
| 65 | + // Static link against the core engine (no sqlite3ext.h |
| 66 | + // api-routine indirection); empty the API export macro so the |
| 67 | + // symbol isn't dllexport'd on Windows for a static build; drop |
| 68 | + // the filesystem helpers to keep vectors in-database. |
| 69 | + .define("SQLITE_CORE"), |
| 70 | + .define("SQLITE_VEC_STATIC"), |
| 71 | + .define("SQLITE_VEC_OMIT_FS"), |
| 72 | + ] |
| 73 | + ), |
| 74 | + // The SDK — `SQLiteDatabase`, `SQLiteStatement`, `SQLiteValue`, |
| 75 | + // `SQLiteRow`, `ResultSet`, `ResultFormatter`. Pure Swift over the |
| 76 | + // amalgamation; no system libsqlite3. |
| 77 | + .target( |
| 78 | + name: "SQLiteKit", |
| 79 | + dependencies: [ |
| 80 | + .product(name: "SQLiteSwiftCSQLite", package: "CSQLite"), |
| 81 | + "CSQLiteShim", |
| 82 | + // Linked (and the amalgamation compiled) only when the |
| 83 | + // SQLiteVec trait is enabled. |
| 84 | + .target(name: "CSQLiteVec", condition: .when(traits: ["SQLiteVec"])), |
| 85 | + ], |
| 86 | + linkerSettings: [ |
| 87 | + // Apple SDKs provide these via libSystem; gate to non-Apple. |
| 88 | + .linkedLibrary("m", .when(platforms: [.linux, .android])), |
| 89 | + .linkedLibrary("dl", .when(platforms: [.linux, .android])), |
| 90 | + // Linux only: Android's Bionic folds pthread into libc (there |
| 91 | + // is no separate libpthread.so), so `-lpthread` would fail |
| 92 | + // there. The pthread symbols come from libc on Android. |
| 93 | + .linkedLibrary("pthread", .when(platforms: [.linux])), |
| 94 | + ] |
| 95 | + ), |
| 96 | + .testTarget( |
| 97 | + name: "SQLiteKitTests", |
| 98 | + dependencies: ["SQLiteKit"] |
| 99 | + ), |
| 100 | + ] |
| 101 | +) |
0 commit comments