Can I import more than PackageDescription in a Package.swift file?

I'm looking at migrating our dependancy management from Cocoapods to SPM. We currently have one workspace with many projects in it for each of our in house dependancies. We have things well defined with some higher level frameworks depending on lower level frameworks (i.e. many feature frameworks all depending on our DesignSystem framework). It seems like the normal approach here would be to write out each dependancy as a String in each Package.swift file.

What I am hoping to do is create some library that I can import into all of my Package.swift file that will have all of the dependancies for all of my frameworks mapped out. And then in my Package.swift file I can just import DependancyGraph (name TBD) and use strings from there. That way I if I need to add a new dendancy to multiple frameworks I can do it quickly and I wont forget to add it to specific targets.

Has anyone imported anything in addition to PackageDescription into Package.swift?

I don't think you can import anything other than libraries already installed on your system. I have seen other people try to partially work around that by reading some configuration file but that's a bad idea because:

  • the builds system doesn't know about the dependency on the filesystem and therefore doesn't restart dependency resolution if the file on disc changes. This will result in weird build issues.
  • Package.swift is potentially executed in a sandbox and doesn't have access to the file system.

However, what might get you a bit closer to what you want is the usage of an umbrella framework.
We use that in swift-nio as well, but mostly for backwards compatibitly reasons:

If this is a good idea is another question. It uses the unofficial @_exported feature and I actually think we should remove that from swift-nio but others disagree.

Thanks for the reply. Those are some good points to not do anything too hacky. I'm hopeful we wont have to rely on the @_exported work around. After taking a deeper look at what we have, I think it might be good bring everything into one Package.swift file or look into some code gen solution that can take in some inputs and output the Package.Swift files we need (hopefully the first). Just need to figure out if its feasable to do everything in one shot to avoid dependancies being included from SPM and CocoaPods

Also realized that SPM doesnt support mixed language packages (yet) so I'll need to wait for that anyawys.