Swift Package Manager not building external dependencies correctly

  • I have created my own SPM through File -> New -> Package

Package.swift looks like:

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

import PackageDescription

let package = Package(
    name: "MyPackage",
    platforms: [.iOS(.v16), .macCatalyst(.v16), .macOS(.v14)],
    products: [.library(name: "MyPackage", targets: ["MyPackage"]),],
    dependencies: [
        .package(path: "../external-package")
    ], targets: [
        .target(name: "MyPackage", path: "Sources"),
        .testTarget(name: "MyPackageTests", dependencies: ["MyPackage"]),
    ]
)
  • When I run swift build the error says:

'.../MyPackage/.build/arm64-apple-macosx/debug/external-package.build/external-package-Swift.h' not found

  • and surely, when I go to directory:

.../MyPackage/.build/arm64-apple-macosx/debug/external-package.build/

  • there are only 2 files in there:

module.modulemap & output-file-map.json

All source files from external-package are missing, therefore swift build fails. The only solution I've found is to copy external-package.build folder manually into:

'.../MyPackage/.build/arm64-apple-macosx/debug/`

What am I missing here? Should swift build create those files in there, or they should be resolved somehow differently?

Note: external-package is not in any way unique, this happens to any added dependency

I'm running on macOS 14.6.1 on Apple Silicon M1 Pro with Xcode 15.4

Answered by Klaudas in 800330022

Ok, so I managed to fix this by adding dependency to my target.

Here's the update Package.swift

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

let package = Package(
    name: "MyPackage",
    platforms: [.iOS(.v16), .macCatalyst(.v16), .macOS(.v14)],
    products: [.library(name: "MyPackage", targets: ["MyPackage"]),],
    dependencies: [
        .package(path: "../external-package")
    ], targets: [
        .target(
            name: "MyPackage",
            dependencies: [
                👉❗️ .product(name: "ExternalPackageName", package: "external-package")
            ],
            path: "Sources"
        ),
        .testTarget(name: "MyPackageTests", dependencies: ["MyPackage"]),
    ]
)
Accepted Answer

Ok, so I managed to fix this by adding dependency to my target.

Here's the update Package.swift

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

let package = Package(
    name: "MyPackage",
    platforms: [.iOS(.v16), .macCatalyst(.v16), .macOS(.v14)],
    products: [.library(name: "MyPackage", targets: ["MyPackage"]),],
    dependencies: [
        .package(path: "../external-package")
    ], targets: [
        .target(
            name: "MyPackage",
            dependencies: [
                👉❗️ .product(name: "ExternalPackageName", package: "external-package")
            ],
            path: "Sources"
        ),
        .testTarget(name: "MyPackageTests", dependencies: ["MyPackage"]),
    ]
)
Swift Package Manager not building external dependencies correctly
 
 
Q