Xcode can't debug Swift package

Hi forum,

I new'ed a swift package in Xcode, with default name "MyLibrary". I then add a new directory MyApp under Sources/ which refers to the MyLibrary module.

Sources/MyLibrary is stated as library, and Sources/MyApp as executable, in Package.Swift.

I'm getting problems with Xcode Version 12.5.1 (12E507):

  1. Xcode can build the while project but produce no print() output,
  2. and breakpoints can't be hit.

But the project runs on terminal and print() output.

$ pwd
/home/ljh/tmp/MyLibrary
$ tree
.
├── Package.swift
├── README.md
├── Sources
│   ├── MyApp
│   │   └── main.swift
│   └── MyLibrary
│       └── MyLibrary.swift
└── Tests
    └── MyLibraryTests
        └── MyLibraryTests.swift

5 directories, 5 files
$ 
$ cat Package.swift 
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "MyLibrary",
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(name: "MyLibrary", targets: ["MyLibrary"]),
        .executable(name: "MyApp", targets: ["MyApp"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.

        // 1. refers to remote package
        // .package(url: /* package url */, from: "1.0.0"),

        // 2. refers to other local package
        // .package(path: /* package url */, from: "1.0.0"),

    ],
    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 this package depends on.

        // 3. refers to module inside same package
        .target( name: "MyApp", dependencies: ["MyLibrary"]),

        .target( name: "MyLibrary", dependencies: []),
        .testTarget( name: "MyLibraryTests", dependencies: ["MyLibrary"]),
    ]
)
$ 
$ cat Sources/MyApp/main.swift 
import Foundation
import MyLibrary

let a = MyLibrary()
print(a.text)
print("MyApp")
$ 
$ cat Sources/MyLibrary/MyLibrary.swift 
import Foundation

public struct MyLibrary {
    public var text = "MyLibrary"
    public init() {
    }
}
$ 
$ uname -a
Darwin Mac-mini.local 20.5.0 Darwin Kernel Version 20.5.0: Sat May  8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64
$
$ swift run
[0/0] Build complete!
MyLibrary
MyApp
$

If I create an executable swift package on terminal then open the package dir within Xcode, it can be debugged.

Once new modules / targets added under Sources/ , the whole project becomes undebuggable in Xcode.

Terms of Service

Privacy Policy

Cookie Policy