0

I'm trying to use the Swift package Siesta as a dependency for the package I'm building and reference it in my package code. I've identified how to import the package into my project in my Package.swift file which is simple enough:

dependencies: [
    .package(url: "https://github.com/bustoutsolutions/siesta", from: "1.5.1")
],

This causes the package to be copied into my package just fine. The problem I'm having is actually linking it up to my package so I can import it and reference it in code. I know I need to actually link it up to my target

I've read some other package files and because the package name for Siesta is like this

let package = Package(
    name: "Siesta",

And the products it declares are like this

products: [
    .library(name: "Siesta", targets: ["Siesta"]),
    .library(name: "SiestaUI", targets: ["SiestaUI"]),
    .library(name: "Siesta_Alamofire", targets: ["Siesta_Alamofire"]),
],

I should be able to just do this in my package file's target to use it

.target(
    name: "MyTarget",
    dependencies: [.product(name: "Siesta", package: "Siesta")]),

But when I try to build my package, I get an error:

/Users/blahblah/Desktop/MyPackage/Package.swift: unknown package 'Siesta' in dependencies of target 'MyTarget'

And not only that, all the targets for my single run scheme on my package go missing and I can't build again without discarding all my local version control changes. What's going on here?

1 Answers1

0

With Swift tools version 5.2 you have to provide a name argument when declaring your package dependency.

.package(name: "Siesta", url: "https://github.com/bustoutsolutions/siesta", from: "1.5.1")

A working example of a Package.swift file:

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

import PackageDescription

let package = Package(
    name: "MyPackage",
    products: [
        .library(
            name: "MyLibrary",
            targets: ["MyTarget"]),
    ],
    dependencies: [
        // make sure to provide a `name` argument here
        .package(name: "Siesta", url: "https://github.com/bustoutsolutions/siesta", from: "1.5.1")        
    ],
    targets: [
        .target(
            name: "MyTarget",
            dependencies: [
                .product(name: "Siesta", package: "Siesta")
            ]),
    ]
)

Source: https://forums.swift.org/t/package-names-in-swift-5-2/34886/6

MJN
  • 10,748
  • 1
  • 23
  • 32