How to specify an external dependency for a single product in a multi-products Package.swift?

Hi,
I'm working on a library which allows multi-products:

  • A core library product with the library main tools
  • n additional products with some extra services you may decide or not to use

One of these additional products require an external dependency.
This is my Package.swift manifesto:

import PackageDescription
let package = Package(
    name: "Glider",
    platforms: [
        .iOS(.v12),
        .macOS(.v11)
    ],
    products: [
        // This is my core library
        .library(
            name: "GliderCore",
            targets: ["GliderCore"]
        ),
        // This is an addition product to the core which also needs of an external dependecy
        // when imported.
        .library(
            name: "GliderSQLite",
            targets: ["GliderSQLite"]
        )
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        .package(
            name: "SQLite.swift",
            url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.12.2"
        )
    ],
    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 this package depends on.
        .target(
            name: "GliderCore",
            dependencies: [],
            path: "GliderCore/Sources"
        ),
        .target(
            name: "GliderSQLite",
            dependencies: [
                "GliderCore",
               // It should limit the import of the external dependency to this target but
               // the lib is always fetched even when - importing the framework - I choose
               // to get only the GliderCore, not this extra package.
                .product(name: "SQLite", package: "SQLite.swift")
            ],
            path: "GliderSQLite/Sources"
        ),
        .testTarget(
            name: "GliderCoreTests",
            dependencies: ["GliderCore"]),
    ]
)

Everything works fine but when I decide to fetch only the Core (GliderCore) from the package I always also get the dependency (SQLite.swift) which should be fetched only for "GliderSQLite" product.

Is this correct? Is there a way to decleare it strictly necessary only for one target? I've tried to set it as target's dependency but it seems not work.

Thanks.

Your manifest is correct. SwiftPM should be able to skip the unused dependencies in the future. The relevant optimizations have been implemented, they just have not been released yet.

1 Like

Thank you Jeremy for quick reply.
Have you got a roadmap for release (5.5 maybe)?

See this post:

1 Like

anyone know if it's available on Swift 5.5? I've tried to test it but it still download all the packages.

It is not.

It will probably be activated on main soon after the holidays, because the issues seem to have been resolved. There is more information at the lasted pull request.

1 Like

Thank you @SDGGiesbrecht . I've seen the MR again but it seems blocked. Any news?

Other features keep being added without thought for this one, requiring new patches to reconcile them. I maintain this pull request in working condition, and its checklist tracks the incremental pieces that need to be merged. (The main team reviews the separate components individually.)

I have just pinged them again here to ask when their “next merge window” is scheduled.