I used SwiftPM to set up an XCode project for a framework; based on
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "MyThing",
products: [
.library(
name: "MyThing",
targets: ["MyThing"]),
],
dependencies: [
],
targets: [
.target(
name: "MyThing",
dependencies: [])
)
I ran swift package generate-xcodeproj
and then pod install
(based on a Podfile whose content shouldn't matter). I obtain MyThing.xcworkspace
.
Now I figured that
xcodebuild -workspace MyThing.xcworkspace -scheme MyThing clean build
should create the .framework
-- but it doesn't, only a binary file appears. I suspect some automatism is at work here since the source folder contains a file named main.swift
, among others.
What do I have to do to get the framework built?
I need to script the whole process, to please no manual workarounds.
Mixing script files and framework code in one target seems to confuse SwiftPM. Moving main.swift
out of the source folder clears up things.
Scheme MyThing-Package
creates all build products as specified in Package.swift
, including the framework.
If you want to have the script files in the same XCode Workspace (for editing convenience), put them in their own target. You can even create an executable product (which won't create anything useful since an executable can't link to dynamic frameworks).