Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Package Manager Mixed Language Source Files

For some reason when I try to run swift build on my Package.swift file:import PackageDescription

let package = Package(
    name: "mobile-HDISegurado-ios",
    dependencies: [
        .package(url: "https://github.com/watson-developer-cloud/swift-sdk", from: "0.30.0"),
        ],
    targets: [
        .target(
            name: "mobile-HDISegurado-ios",
            dependencies: ["WatsonDeveloperCloud"],
            path: "mobile-HDISegurado-ios",
            exclude: [
                "Config",
                "Public",
                "Resources",
                ]
        )
    ] )

I've got the following error:

error: target at '.../mobile-HDISegurado-ios' contains mixed language source files; feature not supported

More details:

  • swift package tools-version: 4.1.0
  • project workspace with Cocoapods running.
like image 876
RodolfoAntonici Avatar asked Jul 26 '18 13:07

RodolfoAntonici


1 Answers

SPM now supports mixed language source files, but you may have to separate them into multiple targets.

From the relevant docs:

Targets can contain Swift, Objective-C/C++, or C/C++ code, but an individual target can’t mix Swift with C-family languages. For example, a Swift package can have two targets, one that contains Objective-C, Objective-C++, and C code, and a second one that contains Swift code.

In practice, you should move your ObjC/C/C++ files into one directory, move your Swift files into another directory, and then modify your Package.swift thus:

products: [
    .library(
        name: "MyLibrary",
        targets: ["MyLibrarySwift", "MyLibraryObjC"]),
],
.target(name: "MyLibraryObjC",
        path: "Sources/MyLibraryObjC"
),
.target(name: "MyLibrarySwift",
        path: "Sources/MyLibrarySwift"
)
like image 190
Eric Avatar answered Sep 17 '22 20:09

Eric