Search code examples
swiftswift4swift4.2swift-package-manager

Swift Package Manager - Speech dependency not loading


I'm encountering an issue creating a Swift Package for my project. I have CocoaPods and Travis CI running and both are working swimmingly, however I now intend to also offer the project through the Swift Package Manager. This is where I'm running into issues. My package file is looking like the following:

// swift-tools-version:4.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "Voxosonus",
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "Voxosonus",
            targets: ["Voxosonus"]),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "Voxosonus",
            path: "Voxosonus"),
        .testTarget(
            name: "VoxosonusTests",
            dependencies: ["Voxosonus"],
            path: "VoxosonusTests"),
    ]
)

However when I run swift build I encounter the following:

/Users/<hidden>/Documents/Projecten/Voxosonus/Voxosonus/SpeechRecognizer.swift:8:8: error: no such module 'Speech'
import Speech

My question is - why is it unable to find the 'Speech' module? This is core functionality from Apple themselves and so far the internet has made me none the wiser. Some details on the project:

Build target: iOS 12.x

macOS: 10.14

Swift Version: 4.2.1


Solution

  • As explained in the Swift Package Manager Github, you can't define the target platform of a Swift Package yet:

    At this time there is no explicit support for depending on UIKit, AppKit, etc, though importing these modules should work if they are present in the proper system location. We will add explicit support for system dependencies in the future. Note that at this time the Package Manager has no support for iOS, watchOS, or tvOS platforms.

    So when you are try to build the library with Xcode (or with the swift build command), the compiler can't find the Speech module because it is only available on iOS 10+.

    You can check this github project (swift-package-manager-ios) which provides a ruby script that modify the xcodeproj generated by the Swift Package Manager by adding the necessary information in order to build for the iOS platform.