How to use libSwiftPM.dylib?

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.

1 Like

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.

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.

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?

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.

libSwiftPM is definitely the intended path forward for developer tools and utilities that want to build on top of SwiftPM; it's a more robust approach than trying to wrap the command-line utility. We're interested in making it easier to use and to improve the API as needed. JIRAs and PRs are both welcome!

I'd like to use libSwiftPM in a command line tool that I need to develop under Xcode but then build and operate under Linux. That means I need to have the library buildable in both environments. Is there a less-than-magic way to do that?