Download only selected libraries? is that possible?

Hello everyone,

I want to make a package with multiple products (library)

let package = Package(
    name: "PKG",
    platforms: [.iOS(.v15)],
    products: [
        .library(name: "Lib1", targets: ["Lib1"]),
        .library(name: "Lib2", targets: ["Lib2"]),
        .library(name: "Lib3", targets: ["Lib3"]),
    dependencies: [
    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: "Lib1", dependencies: []),
        .target(name: "Lib2", dependencies: []),
        .target(name: "Lib3", dependencies: []),

if user select Lib1 only, I want SPM to download only Lib1 folder.

is that possible?

1 Like

No. SPM will always download the entire repo containing your dependency. You can see this in action by using any of the Firebase dependencies through SPM. Both the initial clone and version resolution take quite a while due to the sheer size of the repo. There were proposals for SPM registries which would've solved this issue, but those were never implemented and efforts seems to have died out.

1 Like

that is unfortunate :frowning:, is there a workaround or something?
thank you Jon

Not aside from splitting your libraries into separate repos to keep the size down, no.

Split your package into several local packages, that works just fine and you can build them separately. I.e.:

+ root folder
  - Package.swift
  + Packages
    + Lib1
       - Package.swift
    + Lib2
       - Package.swift

If you also need each of these libraries as a product of the main Package.swift you may make wrapper targets using @export import Lib1 to re-export the targets.

1 Like

hey Marin,
can you give me small example please I'm still newbie to this :slight_smile:

There you go:

You can open Package.swift for the full project or you can open Libraries/MyLibrary/Package.swift to work on MyLibrary specifically without having to check out any of the other dependencies of the root package.

I think this is what you were looking for?