Skip to content

Commit 2c040ba

Browse files
authored
Merge pull request #1070 from stephencelis/linux
Linux CI
2 parents be6bed3 + 0dd440c commit 2c040ba

File tree

10 files changed

+70
-9
lines changed

10 files changed

+70
-9
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,13 @@ jobs:
6161
env:
6262
CARTHAGE_PLATFORM: tvOS
6363
run: ./run-tests.sh
64+
build-linux:
65+
runs-on: ubuntu-latest
66+
steps:
67+
- uses: actions/checkout@v2
68+
- name: Install
69+
run: |
70+
sudo apt-get update -qq
71+
sudo apt-get install -y libsqlite3-dev
72+
- name: Test
73+
run: swift test

Documentation/Linux.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Linux
2+
3+
## Limitations
4+
5+
* Custom functions are currently not supported and crash, caused by a bug in Swift.
6+
See [#1071](https://github.com/stephencelis/SQLite.swift/issues/1071).
7+
* FTS5 might not work, see [#1007](https://github.com/stephencelis/SQLite.swift/issues/1007)
8+
9+
## Debugging
10+
11+
### Create and launch docker container
12+
13+
```shell
14+
$ docker container create swift:focal
15+
$ docker run --cap-add=SYS_PTRACE \
16+
--security-opt seccomp=unconfined \
17+
--security-opt apparmor=unconfined \
18+
-i -t swift:focal bash
19+
```
20+
21+
### Compile and run tests in debugger
22+
23+
```shell
24+
$ apt-get update && apt-get install libsqlite3-dev
25+
$ git clone https://github.com/stephencelis/SQLite.swift.git
26+
$ swift test
27+
$ lldb .build/x86_64-unknown-linux-gnu/debug/SQLite.swiftPackageTests.xctest
28+
(lldb) target create ".build/x86_64-unknown-linux-gnu/debug/SQLite.swiftPackageTests.xctest"
29+
(lldb) run
30+
```

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ syntax _and_ intent.
1919
- [Well-documented][See Documentation]
2020
- Extensively tested
2121
- [SQLCipher][] support via CocoaPods
22+
- Works on [Linux](Documentation/Linux.md) (with some limitations)
2223
- Active support at
2324
[StackOverflow](https://stackoverflow.com/questions/tagged/sqlite.swift),
2425
and [Gitter Chat Room](https://gitter.im/stephencelis/SQLite.swift)

SQLite.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@
227227
19A17399EA9E61235D5D77BF /* CipherTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CipherTests.swift; sourceTree = "<group>"; };
228228
19A175C1F9CB3BBAB8FCEC7B /* RowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowTests.swift; sourceTree = "<group>"; };
229229
19A178A39ACA9667A62663CC /* Cipher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cipher.swift; sourceTree = "<group>"; };
230+
19A1794B7972D14330A65BBD /* Linux.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = Linux.md; sourceTree = "<group>"; };
230231
19A1794CC4D7827E997E32A7 /* FoundationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationTests.swift; sourceTree = "<group>"; };
231232
19A17B93B48B5560E6E51791 /* Fixtures.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Fixtures.swift; sourceTree = "<group>"; };
232233
19A17BA55DABB480F9020C8A /* DateAndTimeFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateAndTimeFunctions.swift; sourceTree = "<group>"; };
@@ -498,6 +499,7 @@
498499
EE247B8F1C3F822500AE3E12 /* Index.md */,
499500
EE247B901C3F822500AE3E12 /* Resources */,
500501
19A17EA3A313F129011B3FA0 /* Release.md */,
502+
19A1794B7972D14330A65BBD /* Linux.md */,
501503
);
502504
path = Documentation;
503505
sourceTree = "<group>";

Sources/SQLite/Core/Connection.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,12 +629,22 @@ public final class Connection {
629629
flags |= SQLITE_DETERMINISTIC
630630
}
631631
#endif
632-
sqlite3_create_function_v2(handle, function, Int32(argc), flags,
633-
unsafeBitCast(box, to: UnsafeMutableRawPointer.self), { context, argc, value in
632+
let resultCode = sqlite3_create_function_v2(handle,
633+
function,
634+
Int32(argc),
635+
flags,
636+
unsafeBitCast(box, to: UnsafeMutableRawPointer.self), { context, argc, value in
634637
let function = unsafeBitCast(sqlite3_user_data(context), to: Function.self)
635638
function(context, argc, value)
636639
}, nil, nil, nil)
637-
if functions[function] == nil { functions[function] = [:] }
640+
641+
if let result = Result(errorCode: resultCode, connection: self, statement: nil) {
642+
fatalError("Error creating function: \(result)")
643+
}
644+
645+
if functions[function] == nil {
646+
functions[function] = [:] // fails on Linux, https://github.com/stephencelis/SQLite.swift/issues/1071
647+
}
638648
functions[function]?[argc] = box
639649
}
640650

Tests/LinuxMain.swift

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

Tests/SQLiteTests/ConnectionTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ class ConnectionTests: SQLiteTestCase {
343343
}
344344
}
345345

346+
// https://github.com/stephencelis/SQLite.swift/issues/1071
347+
#if !os(Linux)
346348
func test_createFunction_withArrayArguments() {
347349
db.createFunction("hello") { $0[0].map { "Hello, \($0)!" } }
348350

@@ -390,6 +392,7 @@ class ConnectionTests: SQLiteTestCase {
390392
}
391393
}
392394
}
395+
#endif
393396

394397
func test_concurrent_access_single_connection() {
395398
// test can fail on iOS/tvOS 9.x: SQLite compile-time differences?

Tests/SQLiteTests/CustomAggregationTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import CSQLite
1313
import SQLite3
1414
#endif
1515

16+
// https://github.com/stephencelis/SQLite.swift/issues/1071
17+
#if !os(Linux)
18+
1619
class CustomAggregationTests: SQLiteTestCase {
1720
override func setUp() {
1821
super.setUp()
@@ -139,6 +142,7 @@ class CustomAggregationTests: SQLiteTestCase {
139142
XCTAssertEqual(TestObject.deinits, 3) // the initial value is still retained by the aggregate's state block, so deinits is one less than inits
140143
}
141144
}
145+
#endif
142146

143147
/// This class is used to test that aggregation state variables
144148
/// can be reference types and are properly memory managed when

Tests/SQLiteTests/CustomFunctionsTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import XCTest
22
import SQLite
33

4+
// https://github.com/stephencelis/SQLite.swift/issues/1071
5+
#if !os(Linux)
6+
47
class CustomFunctionNoArgsTests: SQLiteTestCase {
58
typealias FunctionNoOptional = () -> Expression<String>
69
typealias FunctionResultOptional = () -> Expression<String?>
@@ -144,3 +147,5 @@ class CustomFunctionTruncation: SQLiteTestCase {
144147
XCTAssertEqual("töl-aa 12", result)
145148
}
146149
}
150+
151+
#endif

Tests/SQLiteTests/QueryTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ class QueryTests: XCTestCase {
290290
)
291291
}
292292

293+
#if !os(Linux) // depends on exact JSON serialization
293294
func test_insert_encodable_with_nested_encodable() throws {
294295
let emails = Table("emails")
295296
let value1 = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4,
@@ -307,6 +308,7 @@ class QueryTests: XCTestCase {
307308
insert
308309
)
309310
}
311+
#endif
310312

311313
func test_upsert_withOnConflict_compilesInsertOrOnConflictExpression() {
312314
assertSQL(

0 commit comments

Comments
 (0)