Framework with multiple targets and shared sources
Asked Answered
E

0

9

I have a framework with two targets (A and B) with the following file structure:

FooFramework
|__ A
     |__ Foo.swift
     |__ Bar.swift
     |__ Foobar.swift
|__ B
     |__ Barfoo.swift

B basically has a subset of A's sources (where B is set as a target), e.g. B only uses Foo.swift and Bar.swift, but not Foobar.swift.

Now I have an app that needs both framework A and B (in separate targets targets).

At this point I'm unsure how to setup the Package.swift file for this setup to work. Whenever I open the Package.swift in Xcode and try to build framework B, the compiler is complaining about missing types in Barfoo.swift, because they are included in Bar.swift.

This is how I've setup the Package.swift file:

// swift-tools-version:5.3

import PackageDescription

let package = Package(
    name: "Framework",
    platforms: [
        .iOS(.v11),
        .macOS(.v10_15)
    ],
    products: [
        .library(
            name: "A",
            targets: ["A"]),
        .library(
            name: "B",
            targets: ["B"]),
    ],
    dependencies: [
        .package(name: "Dependency", url: "https://github.com/...", .exact("1.0.0"))
    ],
    targets: [
        .target(
            name: "A",
            dependencies: [
                "Dependency",
            ],
            path: "A",
            exclude: [
                "Info.plist",
            ],
            resources: [
                .process("fonts"),
            ]
        ),
        .target(
            name: "B",
            dependencies: ["A"],
            path: "B",
            exclude: [
                "Info.plist",
            ],
            resources: [
                .process("../A/fonts"),
            ]),
        .testTarget(
            name: "ATests",
            dependencies: ["A"],
            path: "ATests",
            exclude: [
                "Info.plist"
            ]
        )
    ]
)

Related sources, but unfortunately unhelpful:

Epenthesis answered 11/5, 2021 at 20:24 Comment(2)
Did you ever find a solution?Croatian
@SamDoggett Unfortunately, not. We build the other targets as XCFrameworks and manually add them to the app.Epenthesis

© 2022 - 2024 — McMap. All rights reserved.