How to produce multiple libraries from one package?

I got this to work with the following setup in the Package.Swift:

let package = Package(
    name: "foo",
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "Foo",
            targets: ["Foo"]),
        .library(
            name: "Bar",
            targets: ["Bar"]),
        ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* 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 which this package depends on.
        .target(
            name: "Foo",
            dependencies: ["Bar"],
            path: "Sources/Foo"),
        .target(
            name: "Bar",
            dependencies: [],
            path: "Sources/Bar"),
        .testTarget(
            name: "FooTests",
            dependencies: ["foo"]),
        ]
)
2 Likes