Dynamically share SwiftPM dependency across frameworks

Hi,

we have a complex app that consists of many plugins in the form of .framework. We use SPM to pull certain capabilities into separate frameworks. One of our common SPM dependencies is a Logging library, that defines a protocol for a Logger object that the rest of SPM dependencies use. When we link one SPM dependency into Engine and another SPM dependency into SharedKit, this is the result in the app folder:

Contents/Frameworks/Engine.framework/Versions/A/Frameworks/Logging_22939944F424CD2_PackageProduct.framework
Contents/Frameworks/SharedKit.framework/Versions/A/Frameworks/Logging_22939944F424CD2_PackageProduct.framework

As you can see, the logging framework is packed separately in each of the frameworks. I am not very proficient with SPM yet so this might be something trivial. Is there a way, how to tell Xcode/SPM to not pack any dependencies inside the .framework? I would like to set proper RUNTIME_SEARCH_PATHS so the framework find a shared Logging.framework that I will add directly to Contents/Frameworks folder.

I was not able to find any reading about what the _PackageProduct.framework is and why it is created instead of being statically linked into each of the frameworks.

Thanks in advance for any references/ideas/help.

1 Like

I got things working by importing all of the frameworks I need for any depdancies also in the main app. So if your case Engine and SharedKit both declare Logging as a dependancy (what you have now), but also your main app needs to declare Logging as a dependancy

If you don't specify a library type in your spm package definition, spm will choose whether it needs to statically or dynamically link your library. If you see a PackageProduct framework, that's because it has determined that it needs to dynamically link. If you want to force the framework to be statically linked, you can specify a .static type on your package definition.