I'm implementing a project that uses a plugin architecture, where plugins are shared libraries (
.sos) that are dynamically loaded at runtime using
dlopen. I want to distribute the main ("host") application as a standalone, single-file executable that provides the symbols needed by plugins:
- Package Lib defines
func foo()in source
- Package Host adds Lib as a dependency and links to it statically, providing the
foosymbol in its binary
- Package Plugin adds Lib as a dependency and references
fooin source without actually dynamically linking to it, and without knowledge of Host
With Clang, this is possible by using
-undefined dynamic_lookup when building the plugin and not passing a library to link to — see my example here.
How can I recreate this setup (ie. disable linking to a dependency) in Swift Package Manager while still being able to refer to that dependency in source? Using
unsafeFlags here is OK because the host and plugin are end products, but they need to be compatible with Linux too. Or, as a newbie to linkage, is there a better way to go about this?
Thanks for your help!