Skip to content

Commit 9f78d27

Browse files
vkuttypCopilot
andcommitted
fix: replace CSQLite systemLibrary with proper C target for Android/Linux
Converts CSQLite from a .systemLibrary (which required an absolute path to sqlite3.h and relied on pkg-config) to a proper C .target that uses an umbrella header with '#include <sqlite3.h>' (angle-bracket search). Why this works everywhere: - macOS: CSQLite not used — Swift imports SQLite3 framework directly - Linux: '#include <sqlite3.h>' resolves via system include path (libsqlite3-dev installs /usr/include/sqlite3.h) - Android: '--swift-sdk aarch64-unknown-linux-android24' sets NDK sysroot; sqlite3.h is a public NDK API since API 5, found at $(SYSROOT)/usr/include/sqlite3.h automatically The old .systemLibrary approach failed on Android because: - pkg-config is not available in the cross-compilation environment - The absolute path '/usr/include/sqlite3.h' does not exist in the sysroot - The relative path 'sqlite3.h' was not found without pkg-config flags Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent dc8cb70 commit 9f78d27

5 files changed

Lines changed: 20 additions & 7 deletions

File tree

Package.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ let sqliteSystemLibTargets: [Target] = []
77
let sqliteNioExtraDeps: [Target.Dependency] = []
88
let sqliteNioLinkerSettings: [LinkerSetting] = [.linkedLibrary("sqlite3")]
99
#else
10+
// On Linux and Android cross-compilation:
11+
// CSQLite.h does `#include <sqlite3.h>` (angle brackets → system search path).
12+
// Linux: resolves to /usr/include/sqlite3.h (with libsqlite3-dev)
13+
// Android: resolves to $(NDK_SYSROOT)/usr/include/sqlite3.h (NDK public API since API 5)
1014
let sqliteSystemLibTargets: [Target] = [
11-
.systemLibrary(name: "CSQLite", pkgConfig: "sqlite3",
12-
providers: [.apt(["libsqlite3-dev"])]),
15+
.target(
16+
name: "CSQLite",
17+
publicHeadersPath: "include",
18+
linkerSettings: [.linkedLibrary("sqlite3")]
19+
),
1320
]
1421
let sqliteNioExtraDeps: [Target.Dependency] = [.target(name: "CSQLite")]
1522
let sqliteNioLinkerSettings: [LinkerSetting] = []

Sources/CSQLite/include/CSQLite.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
// Umbrella header: forwards to the system SQLite3 header.
3+
// On Linux (libsqlite3-dev) this resolves to /usr/include/sqlite3.h.
4+
// On Android (NDK sysroot) this resolves to $(SYSROOT)/usr/include/sqlite3.h.
5+
#include <sqlite3.h>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module CSQLite {
2+
umbrella header "CSQLite.h"
3+
link "sqlite3"
4+
export *
5+
}

Sources/CSQLite/module.modulemap

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

Sources/CSQLite/shim.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Empty shim — required so Swift Package Manager recognises this as a C target.

0 commit comments

Comments
 (0)