Skip to content

Commit de18ba1

Browse files
authored
SWIFT-823 Use Swift 5.2-compatible way of including system libraries (#466)
1 parent 1388516 commit de18ba1

15 files changed

+79
-66
lines changed

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.0
1+
5.1.4

Package.resolved

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
1-
// swift-tools-version:5.0
1+
// swift-tools-version:5.1
22
import PackageDescription
33
let package = Package(
44
name: "MongoSwift",
55
products: [
66
.library(name: "MongoSwift", targets: ["MongoSwift"])
77
],
88
dependencies: [
9-
.package(url: "https://github.com/mongodb/swift-bson", .upToNextMajor(from: "2.0.0")),
10-
.package(url: "https://github.com/mongodb/swift-mongoc", .upToNextMajor(from: "2.0.0")),
119
.package(url: "https://github.com/Quick/Nimble.git", .exact("8.0.2"))
1210
],
1311
targets: [
1412
.target(name: "MongoSwift", dependencies: ["mongoc", "bson"]),
1513
.target(name: "AtlasConnectivity", dependencies: ["MongoSwift"]),
16-
.testTarget(name: "MongoSwiftTests", dependencies: ["MongoSwift", "Nimble", "mongoc"])
14+
.testTarget(name: "MongoSwiftTests", dependencies: ["MongoSwift", "Nimble", "mongoc"]),
15+
.systemLibrary(
16+
name: "mongoc",
17+
pkgConfig: "libmongoc-1.0",
18+
providers: [
19+
.brew(["mongo-c-driver"]),
20+
.apt(["libmongoc-dev"])
21+
]
22+
),
23+
.systemLibrary(
24+
name: "bson",
25+
pkgConfig: "libbson-1.0",
26+
providers: [
27+
.brew(["mongo-c-driver"]),
28+
.apt(["libbson-dev"])
29+
]
30+
)
1731
]
1832
)

Sources/MongoSwift/BSON/BSONEncoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ private class _BSONReferencingEncoder: _BSONEncoder {
362362
// With a regular encoder, the storage and coding path grow together.
363363
// A referencing encoder, however, inherits its parents coding path, as well as the key it was created for.
364364
// We have to take this into account.
365-
return self.storage.count == self.codingPath.count - self.encoder.codingPath.count - 1
365+
self.storage.count == self.codingPath.count - self.encoder.codingPath.count - 1
366366
}
367367

368368
/// Finalizes `self` by writing the contents of our storage to the referenced encoder's storage.

Sources/MongoSwift/BSON/CodableNumber.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,28 @@ extension Int64: CodableNumber {}
6161
extension Int8: CodableNumber {
6262
internal var bsonValue: BSONValue? {
6363
// Int8 always fits in an Int32
64-
return Int32(exactly: self)
64+
Int32(exactly: self)
6565
}
6666
}
6767

6868
extension Int16: CodableNumber {
6969
internal var bsonValue: BSONValue? {
7070
// Int16 always fits in an Int32
71-
return Int32(exactly: self)
71+
Int32(exactly: self)
7272
}
7373
}
7474

7575
extension UInt8: CodableNumber {
7676
internal var bsonValue: BSONValue? {
7777
// UInt8 always fits in an Int32
78-
return Int32(exactly: self)
78+
Int32(exactly: self)
7979
}
8080
}
8181

8282
extension UInt16: CodableNumber {
8383
internal var bsonValue: BSONValue? {
8484
// UInt16 always fits in an Int32
85-
return Int32(exactly: self)
85+
Int32(exactly: self)
8686
}
8787
}
8888

@@ -198,6 +198,6 @@ extension Float: CodableNumber {
198198

199199
internal var bsonValue: BSONValue? {
200200
// a Float can always be represented as a Double
201-
return Double(exactly: self)
201+
Double(exactly: self)
202202
}
203203
}

Sources/MongoSwift/BSON/Document+Collection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ extension Document: Collection {
5555
/// held within. This method does not guarantee constant-time (O(1)) access.
5656
public subscript(bounds: Range<Index>) -> Document {
5757
// TODO: SWIFT-252 should provide a more efficient implementation for this.
58-
return DocumentIterator.subsequence(of: self, startIndex: bounds.lowerBound, endIndex: bounds.upperBound)
58+
DocumentIterator.subsequence(of: self, startIndex: bounds.lowerBound, endIndex: bounds.upperBound)
5959
}
6060
}

Sources/MongoSwift/MongoCollection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public struct MongoCollection<T: Codable> {
4343
/// The name of this collection.
4444
public var name: String {
4545
// safe to force unwrap as collection name is always present for a collection namespace.
46-
return self.namespace.collection! // swiftlint:disable:this force_unwrapping
46+
self.namespace.collection! // swiftlint:disable:this force_unwrapping
4747
}
4848

4949
/// The `ReadConcern` set on this collection, or `nil` if one is not set.

Sources/MongoSwift/SDAM.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public struct ServerDescription {
184184
extension ServerDescription: Equatable {
185185
public static func == (lhs: ServerDescription, rhs: ServerDescription) -> Bool {
186186
// Compare everything except `error` it is always nil and `MongoError`s are not `Equatable`
187-
return lhs.connectionId == rhs.connectionId &&
187+
lhs.connectionId == rhs.connectionId &&
188188
lhs.roundTripTime == rhs.roundTripTime &&
189189
lhs.lastWriteDate == rhs.lastWriteDate &&
190190
lhs.opTime == rhs.opTime &&
@@ -274,7 +274,7 @@ public struct TopologyDescription {
274274
/// Returns `true` if the topology has a readable server available, and `false` otherwise.
275275
public func hasReadableServer() -> Bool {
276276
// (this function should take in an optional ReadPreference, but we have yet to implement that type.)
277-
return [.single, .replicaSetWithPrimary, .sharded].contains(self.type)
277+
[.single, .replicaSetWithPrimary, .sharded].contains(self.type)
278278
}
279279

280280
/// Returns `true` if the topology has a writable server available, and `false` otherwise.
@@ -304,7 +304,7 @@ public struct TopologyDescription {
304304
extension TopologyDescription: Equatable {
305305
public static func == (lhs: TopologyDescription, rhs: TopologyDescription) -> Bool {
306306
// Compare everything except `error` it is always nil and `MongoError`s are not `Equatable`
307-
return lhs.type == rhs.type &&
307+
lhs.type == rhs.type &&
308308
lhs.setName == rhs.setName &&
309309
lhs.maxSetVersion == rhs.maxSetVersion &&
310310
lhs.maxElectionId == rhs.maxElectionId &&

Sources/bson/libbson.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#define BCON_H_
2+
#include <bson.h>
3+
4+
uint32_t _bson_get_len(const bson_t *bson)
5+
{
6+
BSON_ASSERT (bson);
7+
return bson->len;
8+
}

Sources/bson/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module bson [system] {
2+
header "libbson.h"
3+
link "bson-1.0"
4+
export *
5+
}

0 commit comments

Comments
 (0)