I want to create a single Package.swift file at the root of a Git repos, and it has two library targets, and the code for each are in subdirs. The syntax for this seemingly simple config is eluding me.
Here are my files:
🆑 ls -R
Cheese Ham Package.swift
./Cheese:
Sources Tests
./Cheese/Sources:
Cheese
./Cheese/Sources/Cheese:
Cheese.swift
./Cheese/Tests:
CheeseTests
./Cheese/Tests/CheeseTests:
CheeseTests.swift
./Ham:
Sources Tests
./Ham/Sources:
Ham
./Ham/Sources/Ham:
Ham.swift
./Ham/Tests:
HamTests
./Ham/Tests/HamTests:
HamTests.swift
Here is the Package.swift file:
// swift-tools-version: 6.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "Melon",
products: [
.library(
name: "Ham",
targets: ["Ham"]
),
.library(
name: "Cheese",
targets: ["Cheese"]
),
],
targets: [
.target(
name: "Ham",
path: "Ham",
sources: [ "Sources" ]
),
.testTarget(
name: "HamTests",
dependencies: ["Ham"],
path: "Ham",
sources: [ "Tests" ]
),
.target(
name: "Cheese",
path: "Cheese",
sources: [ "Sources" ]
),
.testTarget(
name: "CheeseTests",
dependencies: ["Cheese"],
path: "Cheese",
sources: [ "Tests" ]
),
]
)
And, after a swift package clean here is what happens when I build:
🆑 swift build
warning: 'rats': found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
/Users/jeff/Code/Rats/Ham/Tests/HamTests/HamTests.swift
warning: 'rats': found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
/Users/jeff/Code/Rats/Cheese/Tests/CheeseTests/CheeseTests.swift
Building for debugging...
[7/7] Emitting module Ham
Build complete! (0.74s)
I do not get it. I have tried lots of things.
I started with the Package.swift from Ham. I moved it up a level. I added in the elements from Cheese. I added path args and then added sources args to make various build errors go away. If I showed how I built up this syntax as I fixed error after error this note would be too long.
There must be some way to make this simple example work with having to individually list every source file. I should be able to tell it what to do using only folder names. But how to do it eludes me.
