Good news! Application Metrics for Swift version 1.2.3 now supports Swift 4!
It seemed at first glance that all Swift 3.1 products would work out of the box on Swift 4 due to its language backwards compatibility, however when I began initial testing, Application Metrics for Swift did not compile on Swift 4 snapshots. It failed at the point where SwiftMetrics builds a number of native C++ modules into separate dynamic libraries. This seems to be an unusual use case for Swift modules, so I imagine most Swift modules will run fine in compatability mode, but it didn’t work for us.
After trying various solutions and receiving some helpful input from the Swift Package Manager team via Slack I found that I needed to make some major layout changes in order to get our dynamic libraries built without requiring downstream users to make changes to their manifests. I also had to branch the source to be able to support both Swift 4 and Swift 3 in the same release due to the need to have a different manifest (Package.swift) for each version. Cleverly, Swift allows you to tag a release with the specific version that it’s intended for, meaning that I could tag
1.2.3 on the
master branch and
1.2.3@swift-4 on the
swift4 branch, thus maintaining support for Swift 3.0.2 and 3.1.1. For our users this should be completely seamless and you should always get the right version for the level of Swift you are running without needing to do anything special.
A Swift 4 manifest for a project requiring SwiftMetrics might look a bit like this:
// swift-tools-version:4.0 import PackageDescription let package = Package( name: "MySwiftDemo", products: [ .library(name: "MySwiftDemo", targets: ["MySwiftDemo"])], dependencies: [ .package(url: "https://github.com/RuntimeTools/SwiftMetrics", from: "1.2.3") ], targets: [ .target(name: "MySwiftDemo", dependencies: ["SwiftMetrics"], path: "Sources")] )
||Join the discussion on Slack||Learn more at kitura.io||Star Kitura on GitHub|