Skip to content

Commit bc00519

Browse files
committed
Linux support
1 parent 7d3714d commit bc00519

File tree

9 files changed

+42
-10
lines changed

9 files changed

+42
-10
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
0.11.4 (xx-09-2017), [diff][diff-0.11.4]
22
========================================
33

4+
* Preliminary Linux support ([#315][], [#681][])
45
* Add `RowIterator` for more safety ([#647][], [#726][])
56
* Make Row.get throw instead of crash ([#649][])
67
* Fix create/drop index functions ([#666][])
@@ -46,6 +47,7 @@
4647
[diff-0.11.3]: https://github.com/stephencelis/SQLite.swift/compare/0.11.2...0.11.3
4748
[diff-0.11.4]: https://github.com/stephencelis/SQLite.swift/compare/0.11.3...0.11.4
4849

50+
[#315]: https://github.com/stephencelis/SQLit1e.swift/issues/315
4951
[#481]: https://github.com/stephencelis/SQLit1e.swift/pull/481
5052
[#532]: https://github.com/stephencelis/SQLit1e.swift/issues/532
5153
[#541]: https://github.com/stephencelis/SQLit1e.swift/issues/541
@@ -62,6 +64,7 @@
6264
[#657]: https://github.com/stephencelis/SQLite.swift/issues/657
6365
[#666]: https://github.com/stephencelis/SQLite.swift/pull/666
6466
[#668]: https://github.com/stephencelis/SQLite.swift/pull/668
67+
[#681]: https://github.com/stephencelis/SQLite.swift/issues/681
6568
[#722]: https://github.com/stephencelis/SQLite.swift/pull/722
6669
[#723]: https://github.com/stephencelis/SQLite.swift/pull/723
6770
[#726]: https://github.com/stephencelis/SQLite.swift/pull/726

Package.swift

+11
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ let package = Package(
1111
],
1212
swiftLanguageVersions: [4]
1313
)
14+
15+
#if os(Linux)
16+
package.dependencies = [.package(url: "https://github.com/stephencelis/CSQLite.git", from: "0.0.3")]
17+
package.targets = [
18+
.target(name: "SQLite", exclude: ["Extensions/FTS4.swift", "Extensions/FTS5.swift"]),
19+
.testTarget(name: "SQLiteTests", dependencies: ["SQLite"], path: "Tests/SQLiteTests", exclude: [
20+
"FTS4Tests.swift",
21+
"FTS5Tests.swift"
22+
])
23+
]
24+
#endif

Sources/SQLite/Core/Connection.swift

+8-4
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
// THE SOFTWARE.
2323
//
2424

25-
import Foundation.NSUUID
25+
import Foundation
2626
import Dispatch
2727
#if SQLITE_SWIFT_STANDALONE
2828
import sqlite3
2929
#elseif SQLITE_SWIFT_SQLCIPHER
3030
import SQLCipher
31-
#elseif SWIFT_PACKAGE
31+
#elseif os(Linux)
32+
import CSQLite
33+
#else
3234
import SQLite3
3335
#endif
3436

@@ -413,7 +415,7 @@ public final class Connection {
413415
///
414416
/// db.trace { SQL in print(SQL) }
415417
public func trace(_ callback: ((String) -> Void)?) {
416-
#if SQLITE_SWIFT_SQLCIPHER
418+
#if SQLITE_SWIFT_SQLCIPHER || os(Linux)
417419
trace_v1(callback)
418420
#else
419421
if #available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
@@ -583,9 +585,11 @@ public final class Connection {
583585
}
584586
}
585587
var flags = SQLITE_UTF8
588+
#if !os(Linux)
586589
if deterministic {
587590
flags |= SQLITE_DETERMINISTIC
588591
}
592+
#endif
589593
sqlite3_create_function_v2(handle, function, Int32(argc), flags, unsafeBitCast(box, to: UnsafeMutableRawPointer.self), { context, argc, value in
590594
let function = unsafeBitCast(sqlite3_user_data(context), to: Function.self)
591595
function(context, argc, value)
@@ -702,7 +706,7 @@ extension Result : CustomStringConvertible {
702706
}
703707
}
704708

705-
#if !SQLITE_SWIFT_SQLCIPHER
709+
#if !SQLITE_SWIFT_SQLCIPHER && !os(Linux)
706710
@available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *)
707711
extension Connection {
708712
fileprivate func trace_v2(_ callback: ((String) -> Void)?) {

Sources/SQLite/Core/Statement.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import sqlite3
2727
#elseif SQLITE_SWIFT_SQLCIPHER
2828
import SQLCipher
29-
#elseif SWIFT_PACKAGE
29+
#elseif os(Linux)
30+
import CSQLite
31+
#else
3032
import SQLite3
3133
#endif
3234

Sources/SQLite/Helpers.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import sqlite3
2727
#elseif SQLITE_SWIFT_SQLCIPHER
2828
import SQLCipher
29-
#elseif SWIFT_PACKAGE
29+
#elseif os(Linux)
30+
import CSQLite
31+
#else
3032
import SQLite3
3133
#endif
3234

Sources/SQLite/Typed/CoreFunctions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// THE SOFTWARE.
2323
//
2424

25-
import Foundation.NSData
25+
import Foundation
2626

2727

2828
extension ExpressionType where UnderlyingType : Number {

Tests/LinuxMain.swift

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import XCTest
2+
@testable import SQLiteTests
3+
4+
XCTMain([
5+
testCase([
6+
])])

Tests/SQLiteTests/ConnectionTests.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import XCTest
2+
import Foundation
3+
import Dispatch
24
@testable import SQLite
35

46
#if SQLITE_SWIFT_STANDALONE
57
import sqlite3
68
#elseif SQLITE_SWIFT_SQLCIPHER
79
import SQLCipher
8-
#elseif SWIFT_PACKAGE
10+
#elseif os(Linux)
11+
import CSQLite
12+
#else
913
import SQLite3
1014
#endif
1115

@@ -336,7 +340,7 @@ class ConnectionTests : SQLiteTestCase {
336340
let stmt = try! db.prepare("SELECT *, sleep(?) FROM users", 0.1)
337341
try! stmt.run()
338342

339-
let deadline = DispatchTime.now() + Double(Int64(10 * NSEC_PER_MSEC)) / Double(NSEC_PER_SEC)
343+
let deadline = DispatchTime.now() + 0.01
340344
_ = DispatchQueue(label: "queue", qos: .background).asyncAfter(deadline: deadline, execute: db.interrupt)
341345
AssertThrows(try stmt.run())
342346
}

Tests/SQLiteTests/TestHelpers.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class SQLiteTestCase : XCTestCase {
6969

7070
func async(expect description: String = "async", timeout: Double = 5, block: (@escaping () -> Void) -> Void) {
7171
let expectation = self.expectation(description: description)
72-
block(expectation.fulfill)
72+
block({ expectation.fulfill() })
7373
waitForExpectations(timeout: timeout, handler: nil)
7474
}
7575

0 commit comments

Comments
 (0)