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.
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.
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.
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.