How to use libSwiftPM.dylib?


(Marcin Krzyzanowski) #1

I'm looking for any info about how to link a libSwiftPM.dylib and use it in eg. Xcode project.

Problems I found so far:

  • libSwiftPM.dylib needs libllbuildSwift.dylib that needs libllbuild.dylib, that needs llbuild module (I guess it's from llbuild.framework).
  • Then we need swiftmodules to use it. For that we need .build/x86_64-apple-macosx/release/*.swiftmodule (this is what bootstrap --libswiftpm-modules-dir is doing)
  • libSwiftPM need to fix rpath, because it uses hardcoded path to .build/... directory so it won't work if moved outside (addressed by --libswiftpm-library-dir)
  • Some work has been done with bootstrap --libswiftpm-library-dir command, but it only put libSwiftPM.dylib without dependencies hence is not really usable.
  • Xcode project generated by bootstrap script can't be used out of the box as a subproject in another Xcode project due to "clibc" issue

Appreciate any help.


(Jeremy David Giesbrecht) #2

Just declare it as a package dependency and then $ swift package generate-xcodeproj.

The generated project can be used directly or as a subproject of an Xcode workspace also containing manual projects.

I think the bootstrapping for development results is much more complexity because it needs the the compiler and such to be in a corresponding development state.


(Marcin Krzyzanowski) #3

Just declare it as a package dependency and then $ swift package generate-xcodeproj .

that need SPM package based project. I'm talking about using libSwiftPM outside SPM, as a just library.


(Ankit Aggarwal) #4

That is slightly complicated as you noted but not very hard once you know all the pieces involved. You basically need to add all the required header search paths, linker search paths and linked libraries to make it work. If you don't mind sharing, what is the motivation of linking it directly in Xcode vs use it as a SwiftPM dependency?


(Marcin Krzyzanowski) #5

I use it in a desktop app. I can make it all using my magic scripts, just wondered if it has to be such pain (and fragile if SPM changes internals in the future). Small things that comes with SPM is hardcoded rpath that has to be updated manually to run the binary outside build directory (eg. when moved to another machine)

also I had the impression that libSwiftPM ambition is to deliver general use Utilities.