5

I am creating a Swift Package that is essentially a wrapper for multiple XCFrameworks generated from Objective-C frameworks so they can be installed via SPM.

Everything works fine as far as creating the SP and ability to add it as a dependency to an app. But I have a bunch non-essential files included in the SP's repository that I don't want to include in the actual SP - i.e. They shouldn't show up in Xcode's navigator when the SP is added as a dependency. (These consist of the source Obj-C Frameworks, README, Changelog, Xcode Workspace for demo app, Script files for generating the XCFrameworks, etc).

Is this even possible? Or will SPM always checkout the entire repo and make all files visible to the user?

I have tried using various permutations of the Target specifiers: source, path, exclude but to no avail.

Here is the closest I can get with a valid manifest, but when I check out the SP in a dummy Xcode app, I can still see all the files from the repo included:

// 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: "WrapperSwiftPackage",
    platforms: [.iOS(.v13)],
    products: [
        .library(name: "WrapperSwiftPackage", targets: ["WrapperSwiftPackage"])
    ],
    dependencies: [],
    targets: [
        .target(
            name: "WrapperSwiftPackage",
            dependencies: [
                "ObjCFramework1",
                "ObjCFramework2"
            ],
            path: "", // Set to root directory so we can exclude files below
            exclude: [
                "CHANGELOG.md",
                "Dangerfile.swift",
                "README.md",
                "Workspace.xcworkspace",
                "Scripts/generate-xcframework.sh",
                "Scripts/link_git_hooks.sh",
                "Objective-C Frameworks/"
            ],
            sources: [
                "Sources/WrapperSwiftPackage/main.swift",
                "XCFrameworks/ObjCFramework1.xcframework",
                "XCFrameworks/ObjCFramework2.xcframework"
            ]
        ),
        .binaryTarget(name: "ObjCFramework1", path: "XCFrameworks/ObjCFramework1.xcframework"),
        .binaryTarget(name: "ObjCFramework2", path: "XCFrameworks/ObjCFramework2.xcframework")
    ]
)
Vadim Belyaev
  • 2,456
  • 2
  • 18
  • 23
JimmyJammed
  • 9,598
  • 19
  • 79
  • 146

1 Answers1

9

Not sure if that isn't a bug though, but I've accidentaly came up to one solution for this.

If you put an empty Package.swift (I mean, one like this):

// swift-tools-version:5.5

import PackageDescription

let package = Package()

into one of project subfolders, then even though SPM is checking the subfolder out, it's excluded from Xcode navigator, and thus, from the project visibility.

I would like to know if that's a bug or is it documented somewhere, every hint is appreciated.

Works with local and remote dependencies.

Bolo
  • 91
  • 1
  • 2
  • Tried in Xcode 14.3.1 to strip out an example project in an SPM. But doesn't work. Have you found any other solutions? – Simon McLoughlin Jul 14 '23 at 09:42
  • 1
    Another link suggested to only use a file containing `import PackageDescription`. Not sure if it was this change, or a clean. But one of those worked. Thanks – Simon McLoughlin Jul 14 '23 at 09:48