Skip to content

Commit fcc33ed

Browse files
authored
Linux (#488)
* Fixed test build with SPM Explicitly import Core Location in each test file that uses it. * SPM 5.3 Upgraded to SPM 5.3. Added fixtures to test target so that tests pass. * Updated tests for SPM * Added Linux to CI * Removed Core Location dependency on Linux * Removed Core Graphics dependency on Linux * Migrated Linux to FoundationNetworking * DateComponentsFormatter is unimplemented in swift-corelibs-foundation * Polyline v5.0.2, Turf v1.1.0 * Imported Foundation where missing * Use current ProcessInfo instead of creating a new one * Remove Objective-C runtime dependency on Linux * Bridge Turf and Polyline compatibility shims for Core Location on Linux * Documented Linux support Reworked the system requirements documentation for clarity. * Test on Linux * Removed truisms from unit tests Removed some assertions that, combined with other assertions nearby, essentially check that a Foundation class’s non-failable initializer doesn’t return nil. These default initializers happen to also be unavailable in swift-corelibs-foundation. * Work around swift-corelibs-foundation usage of NSNull swift-corelibs-foundation’s implementation of JSONSerialization uses NSNull to represent a JSON null value, whereas the implementation on Apple platforms uses nil.
1 parent 5a8202e commit fcc33ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+472
-67
lines changed

.circleci/config.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ commands:
3737
command: bash <(curl -s https://codecov.io/bash)
3838

3939
jobs:
40+
spm-linux-job:
41+
docker:
42+
- image: swift:5.3
43+
steps:
44+
- checkout
45+
- run: swift build
46+
- run: swift test
47+
4048
spm-job:
4149
parameters:
4250
xcode:
@@ -132,3 +140,5 @@ workflows:
132140
- spm-job:
133141
name: "SPM_build"
134142
xcode: "12.0.0"
143+
- spm-linux-job:
144+
name: "SPM_Ubuntu_build"

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes to Mapbox Directions for Swift
22

3+
## v1.2.0
4+
5+
* Added support for building and running on any Linux distribution supported by Swift. ([#488](https://github.com/mapbox/mapbox-directions-swift/pull/488))
6+
37
## v1.1.0
48

59
* Added the `DirectionsResult.typicalTravelTime`, `RouteLeg.typicalTravelTime` and `RouteStep.typicalTravelTime` properties that indicate the typical travel time, as opposed to the current expected travel time. ([#462](https://github.com/mapbox/mapbox-directions-swift/pull/462))

Cartfile.resolved

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" "5.9.0"
22
github "linksmt/OHHTTPStubs" "563f48d3fab84ef04639649c770b00f4fa502cca"
33
github "mapbox/mapbox-events-ios" "v0.10.5"
4-
github "mapbox/turf-swift" "v1.0.0"
5-
github "raphaelmor/Polyline" "v5.0.0"
4+
github "mapbox/turf-swift" "v1.1.0"
5+
github "raphaelmor/Polyline" "v5.0.2"

Package.resolved

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

Package.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.0
1+
// swift-tools-version:5.3
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -17,17 +17,22 @@ let package = Package(
1717
],
1818
dependencies: [
1919
// Dependencies declare other packages that this package depends on.
20-
.package(url: "https://github.com/raphaelmor/Polyline.git", from: "5.0.0"),
21-
.package(url: "https://github.com/mapbox/turf-swift.git", from: "1.0.0")
20+
.package(url: "https://github.com/raphaelmor/Polyline.git", from: "5.0.2"),
21+
.package(name: "Turf", url: "https://github.com/mapbox/turf-swift.git", from: "1.1.0")
2222
],
2323
targets: [
2424
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2525
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
2626
.target(
2727
name: "MapboxDirections",
28-
dependencies: ["Polyline", "Turf"]),
28+
dependencies: ["Polyline", "Turf"],
29+
exclude: ["Info.plist"]),
2930
.testTarget(
3031
name: "MapboxDirectionsTests",
31-
dependencies: ["MapboxDirections"]),
32+
dependencies: ["MapboxDirections"],
33+
exclude: ["Info.plist"],
34+
resources: [
35+
.process("Fixtures"),
36+
]),
3237
]
3338
)

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![SPM compatible](https://img.shields.io/badge/SPM-compatible-4BC51D.svg?style=flat)](https://swift.org/package-manager/)
77
[![codecov](https://codecov.io/gh/mapbox/mapbox-directions-swift/branch/main/graph/badge.svg)](https://codecov.io/gh/mapbox/mapbox-directions-swift)
88

9-
Mapbox Directions for Swift (formerly MapboxDirections.swift) makes it easy to connect your iOS, macOS, tvOS, or watchOS application to the [Mapbox Directions](https://docs.mapbox.com/api/navigation/) and [Map Matching](https://docs.mapbox.com/api/navigation/#map-matching) APIs. Quickly get driving, cycling, or walking directions, whether the trip is nonstop or it has multiple stopping points, all using a simple interface reminiscent of MapKit’s `MKDirections` API. Fit a GPX trace to the [OpenStreetMap](https://www.openstreetmap.org/) road network. The Mapbox Directions and Map Matching APIs are powered by the [OSRM](http://project-osrm.org/) and [Valhalla](https://github.com/valhalla/valhalla/) routing engines. For more information, see the [Mapbox Navigation](https://www.mapbox.com/navigation/) homepage.
9+
Mapbox Directions for Swift (formerly MapboxDirections.swift) makes it easy to connect your iOS, macOS, tvOS, watchOS, or Linux application to the [Mapbox Directions](https://docs.mapbox.com/api/navigation/) and [Map Matching](https://docs.mapbox.com/api/navigation/#map-matching) APIs. Quickly get driving, cycling, or walking directions, whether the trip is nonstop or it has multiple stopping points, all using a simple interface reminiscent of MapKit’s `MKDirections` API. Fit a GPX trace to the [OpenStreetMap](https://www.openstreetmap.org/) road network. The Mapbox Directions and Map Matching APIs are powered by the [OSRM](http://project-osrm.org/) and [Valhalla](https://github.com/valhalla/valhalla/) routing engines. For more information, see the [Mapbox Navigation](https://www.mapbox.com/navigation/) homepage.
1010

1111
Mapbox Directions pairs well with [MapboxGeocoder.swift](https://github.com/mapbox/MapboxGeocoder.swift), [MapboxStatic.swift](https://github.com/mapbox/MapboxStatic.swift), the [Mapbox Navigation SDK for iOS](https://github.com/mapbox/mapbox-navigation-ios/), and the [Mapbox Maps SDK for iOS](https://docs.mapbox.com/ios/maps/) or [macOS SDK](https://mapbox.github.io/mapbox-gl-native/macos/).
1212

@@ -32,11 +32,24 @@ Or in your [Swift Package Manager](https://swift.org/package-manager/) Package.s
3232

3333
Then `import MapboxDirections`.
3434

35-
This library requires Xcode 11 or higher in order to build.
36-
This library supports a minimum deployment target of iOS 10.0 or above, macOS 10.12.0 or above, tvOS 10.0 or above, or watchOS 2.0 or above. v0.30.0 is the last release of MapboxDirections.swift that supports a minimum deployment target of iOS 9._x_, macOS 10.11._x_, tvOS 9._x_, or watchOS 2._x_. v0.30.0 is also the last release that is compatible with Objective-C or AppleScript code.
37-
3835
This repository contains an example application that demonstrates how to use the framework. To run it, you need to use [Carthage](https://github.com/Carthage/Carthage) 0.19 or above to install the dependencies. Detailed documentation is available in the [Mapbox API Documentation](https://docs.mapbox.com/api/navigation/#directions).
3936

37+
## System requirements
38+
39+
* One of the following package managers:
40+
* CocoaPods (CocoaPods 1.10 or above if using Xcode 12)
41+
* Carthage 0.19 or above (run [this script](https://github.com/mapbox/mapbox-directions-swift/blob/main/scripts/wcarthage.sh) instead of `carthage` if using Xcode 12)
42+
* Swift Package Manager 5.3 or above
43+
* Xcode 11 or above (Xcode 12 or above if using Swift Package Manager)
44+
* One of the following operating systems:
45+
* iOS 10.0 or above
46+
* macOS 10.12.0 or above
47+
* tvOS 10.0 or above
48+
* watchOS 2.0 or above
49+
* Any Linux distribution supported by Swift
50+
51+
v0.30.0 is the last release of MapboxDirections.swift that supports a minimum deployment target of iOS 9._x_, macOS 10.11._x_, tvOS 9._x_, or watchOS 2._x_. v0.30.0 is also the last release that is compatible with Objective-C or AppleScript code.
52+
4053
## Usage
4154

4255
**[API reference](https://docs.mapbox.com/ios/api/directions/)**

Sources/MapboxDirections/Directions.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import Foundation
2+
#if canImport(FoundationNetworking)
3+
import FoundationNetworking
4+
#endif
25

36
typealias JSONDictionary = [String: Any]
47

@@ -37,7 +40,7 @@ let userAgent: String = {
3740
#else
3841
system = "unknown"
3942
#endif
40-
let systemVersion = ProcessInfo().operatingSystemVersion
43+
let systemVersion = ProcessInfo.processInfo.operatingSystemVersion
4144
components.append("\(system)/\(systemVersion.majorVersion).\(systemVersion.minorVersion).\(systemVersion.patchVersion)")
4245

4346
let chip: String

Sources/MapboxDirections/DirectionsCredentials.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ public struct DirectionsCredentials: Equatable {
2020
The SKU Token associated with the request. Used for billing.
2121
*/
2222
public var skuToken: String? {
23+
#if os(iOS)
2324
guard let mbx: AnyClass = NSClassFromString("MBXAccounts") else { return nil }
2425
guard mbx.responds(to: Selector(("serviceSkuToken"))) else { return nil }
2526
return mbx.value(forKeyPath: "serviceSkuToken") as? String
27+
#else
28+
return nil
29+
#endif
2630
}
2731

2832
/**

Sources/MapboxDirections/DirectionsError.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import Foundation
2+
#if canImport(FoundationNetworking)
3+
import FoundationNetworking
4+
#endif
25

36
/**
47
An error that occurs when calculating directions.
@@ -131,12 +134,16 @@ public enum DirectionsError: LocalizedError {
131134
case .requestTooLarge:
132135
return "The request is too large."
133136
case let .rateLimited(rateLimitInterval: interval, rateLimit: limit, _):
134-
let intervalFormatter = DateComponentsFormatter()
135-
intervalFormatter.unitsStyle = .full
136137
guard let interval = interval, let limit = limit else {
137138
return "Too many requests."
138139
}
140+
#if os(Linux)
141+
let formattedInterval = "\(interval) seconds"
142+
#else
143+
let intervalFormatter = DateComponentsFormatter()
144+
intervalFormatter.unitsStyle = .full
139145
let formattedInterval = intervalFormatter.string(from: interval) ?? "\(interval) seconds"
146+
#endif
140147
let formattedCount = NumberFormatter.localizedString(from: NSNumber(value: limit), number: .decimal)
141148
return "More than \(formattedCount) requests have been made with this access token within a period of \(formattedInterval)."
142149
case let .unknown(_, underlying: error, _, message):

Sources/MapboxDirections/DirectionsOptions.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Foundation
22
import Polyline
3-
import CoreLocation
43

54
/**
65
Maximum length of an HTTP request URL for the purposes of switching from GET to

0 commit comments

Comments
 (0)