diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 02f6591..b760e68 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,3 +16,15 @@ jobs: run: swift build - name: Run tests run: swift test + + build-linux: + runs-on: ubuntu-latest + container: swift:6.1-jammy + steps: + - uses: actions/checkout@v4 + - name: Install SQLite + run: apt-get update && apt-get install -y libsqlite3-dev + - name: Build + run: swift build + - name: Run tests + run: swift test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 630b883..90f49cb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,18 +13,16 @@ jobs: build: name: Build for ${{ matrix.destination.name }} runs-on: ${{ matrix.destination.os }} + container: ${{ matrix.destination.container }} strategy: matrix: destination: - # - Swiftly is failing to install these so commenting out for now - # - { name: "ubuntu-aarch64", os: ubuntu-22.04-arm } - # - { name: "ubuntu-x86_64", os: ubuntu-22.04 } + - { name: "ubuntu-aarch64", os: ubuntu-22.04-arm, container: "swift:6.1-jammy" } + - { name: "ubuntu-x86_64", os: ubuntu-22.04, container: "swift:6.1-jammy" } - { name: "macos-universal", os: macos-15 } steps: - if: startsWith(matrix.destination.name, 'ubuntu') - uses: vapor/swiftly-action@v0.2 - with: - toolchain: 6.1.0 + run: apt-get update && apt-get install -y make libsqlite3-dev - if: startsWith(matrix.destination.name, 'macos') run: sudo xcode-select -s /Applications/Xcode_16.4.app - uses: actions/checkout@v4 @@ -46,6 +44,7 @@ jobs: - name: Deploy the binary uses: softprops/action-gh-release@v2 with: - files: puresql.macos-universal.tar.gz - # puresql.ubuntu-x86_64.tar.gz - # puresql.ubuntu-aarch64.tar.gz \ No newline at end of file + files: | + puresql.macos-universal.tar.gz + puresql.ubuntu-x86_64.tar.gz + puresql.ubuntu-aarch64.tar.gz \ No newline at end of file diff --git a/Makefile b/Makefile index 6159698..d06e658 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ ifeq ($(UNAME_S),Darwin) BUILD_FLAGS := -c release --product PureSQLCLI --arch arm64 --arch x86_64 BUILD_DIR := .build/apple/Products/Release else - BUILD_FLAGS := -c release --product PureSQLCLI + BUILD_FLAGS := -c release --product PureSQLCLI --static-swift-stdlib BUILD_DIR := .build/release endif diff --git a/Package.swift b/Package.swift index 038afb8..98a3a66 100644 --- a/Package.swift +++ b/Package.swift @@ -35,11 +35,21 @@ let package = Package( ] ), + .systemLibrary( + name: "CSQLite", + pkgConfig: "sqlite3", + providers: [ + .apt(["libsqlite3-dev"]), + .yum(["sqlite-devel"]), + ] + ), + .target( name: "PureSQL", dependencies: [ "PureSQLMacros", .product(name: "Collections", package: "swift-collections"), + .target(name: "CSQLite", condition: .when(platforms: [.linux])), ] ), diff --git a/Sources/CSQLite/module.modulemap b/Sources/CSQLite/module.modulemap new file mode 100644 index 0000000..0a291b5 --- /dev/null +++ b/Sources/CSQLite/module.modulemap @@ -0,0 +1,5 @@ +module CSQLite [system] { + header "shim.h" + link "sqlite3" + export * +} diff --git a/Sources/CSQLite/shim.h b/Sources/CSQLite/shim.h new file mode 100644 index 0000000..f52e1f0 --- /dev/null +++ b/Sources/CSQLite/shim.h @@ -0,0 +1 @@ +#include diff --git a/Sources/PureSQL/Cursor.swift b/Sources/PureSQL/Cursor.swift index b4b87bf..e0a59d9 100644 --- a/Sources/PureSQL/Cursor.swift +++ b/Sources/PureSQL/Cursor.swift @@ -5,7 +5,11 @@ // Created by Wes Wickwire on 2/16/25. // +#if canImport(SQLite3) import SQLite3 +#else +import CSQLite +#endif /// A low-level iterator over the results of a prepared database statement. /// diff --git a/Sources/PureSQL/DatabaseObserver.swift b/Sources/PureSQL/DatabaseObserver.swift index bbc84be..07f31ad 100644 --- a/Sources/PureSQL/DatabaseObserver.swift +++ b/Sources/PureSQL/DatabaseObserver.swift @@ -6,7 +6,11 @@ // import Foundation +#if canImport(SQLite3) import SQLite3 +#else +import CSQLite +#endif /// A change that happened in the database. /// Represents many events. Changes are published diff --git a/Sources/PureSQL/DatabasePrimitive.swift b/Sources/PureSQL/DatabasePrimitive.swift index 918f9d4..734917d 100644 --- a/Sources/PureSQL/DatabasePrimitive.swift +++ b/Sources/PureSQL/DatabasePrimitive.swift @@ -6,7 +6,11 @@ // import Foundation +#if canImport(SQLite3) import SQLite3 +#else +import CSQLite +#endif @usableFromInline let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self) diff --git a/Sources/PureSQL/DatabaseValueAdapter.swift b/Sources/PureSQL/DatabaseValueAdapter.swift index b8df376..ab6d4ed 100644 --- a/Sources/PureSQL/DatabaseValueAdapter.swift +++ b/Sources/PureSQL/DatabaseValueAdapter.swift @@ -290,7 +290,7 @@ public struct DecimalDatabaseValueAdapter: DatabaseValueAdapter { public init() {} @inlinable public func encodeToDouble(value: Value) throws(SQLError) -> Double { - Double(truncating: value as NSNumber) + NSDecimalNumber(decimal: value).doubleValue } @inlinable public func decode(from primitive: Double) throws(SQLError) -> Decimal { diff --git a/Sources/PureSQL/Row.swift b/Sources/PureSQL/Row.swift index a19506e..efada41 100644 --- a/Sources/PureSQL/Row.swift +++ b/Sources/PureSQL/Row.swift @@ -5,7 +5,11 @@ // Created by Wes Wickwire on 9/6/25. // +#if canImport(SQLite3) import SQLite3 +#else +import CSQLite +#endif /// A raw SQLite row from a statement. public struct Row: ~Copyable { diff --git a/Sources/PureSQL/SQLAny.swift b/Sources/PureSQL/SQLAny.swift index 7eef95b..be45b8b 100644 --- a/Sources/PureSQL/SQLAny.swift +++ b/Sources/PureSQL/SQLAny.swift @@ -6,7 +6,11 @@ // import Foundation +#if canImport(SQLite3) import SQLite3 +#else +import CSQLite +#endif /// SQLite supports an `ANY` type. Mapping to a `Swift.Any` would /// not be a smart idea and would not implement things like diff --git a/Sources/PureSQL/SQLiteCode.swift b/Sources/PureSQL/SQLiteCode.swift index 8259c6d..0442f45 100644 --- a/Sources/PureSQL/SQLiteCode.swift +++ b/Sources/PureSQL/SQLiteCode.swift @@ -5,7 +5,11 @@ // Created by Wes Wickwire on 11/9/24. // +#if canImport(SQLite3) import SQLite3 +#else +import CSQLite +#endif public enum SQLiteCode: Int32, Error { case sqliteOk = 0 diff --git a/Sources/PureSQL/SQLiteConnection.swift b/Sources/PureSQL/SQLiteConnection.swift index 5f68f94..e73de81 100644 --- a/Sources/PureSQL/SQLiteConnection.swift +++ b/Sources/PureSQL/SQLiteConnection.swift @@ -7,7 +7,11 @@ import Collections import Foundation +#if canImport(SQLite3) import SQLite3 +#else +import CSQLite +#endif /// Represents a raw connection to the SQLite database public protocol RawConnection: Sendable { diff --git a/Sources/PureSQL/Statement.swift b/Sources/PureSQL/Statement.swift index 003a343..f61a907 100644 --- a/Sources/PureSQL/Statement.swift +++ b/Sources/PureSQL/Statement.swift @@ -5,7 +5,11 @@ // Created by Wes Wickwire on 2/16/25. // +#if canImport(SQLite3) import SQLite3 +#else +import CSQLite +#endif /// A prepared SQL statement for executing queries against the database. ///