The package exists on freebsd, yay! I’ve even compiled some simple programs!
I can’t, however, figure out how to use 3rd party packages. I tried looking for some examples using Linux, but almost everything seemed to be about creating packages. I’m used to Xcode on macOS, obviously, so manually dealing with SwiftPM hasn’t been something I’ve done before.
Anyone have any pointers, suggestions, or willingness to just chat about some of this? (Again, I’m assuming it’s pretty similar to Linux, but I’m struggling on that front.)
Once your project is ready you can write your code within the provided .swift file in a directory within the Sources directory.
The Package.swift file will be automatically generated and populated for you.
Yes, I did all that. I tried using ArgumentParser as a package, but when I added dependencies: [“ArgumentParser”] to the target call, it said it couldn’t find it. It was downloading from github (I had to cheat and look at the URL in an Xcode project – I assume there’s a site with a list of packages, but I couldn’t find it?)
Thank you! That tells me that what I was getting wrong was the argument; I need to use .product(name: "ArgumentParser", package: "swift-argument-parser") (and, presumably, similar for any other package).
A related question is how do I use C/C++ code from swift here? I couldn’t see how to use a bridging header. (Simple case for now: I just added foo.c to the Package.swift file, and want to call foo() from my Swift code.)
ETA: Oh, it doesn’t seem supported (yet?): error: 'swifttest': target at '/tmp/SwiftTest/Sources' contains mixed language source files; feature not supported
Yep pretty much you can’t mix .c and .swift files in a target with SwiftPM. If you need C or C++ code, you must have a separate target that contains that code. Here’s a resource for C++ if that’s what you need to do:
FYI: C and C++ are both considered C targets by SwiftPM and interact with Swift with similar effects between each other. You should still learn the particular differences between C and C++ interop.
So this seems to mean that if I wanted to have a project that used C and Swift, I would need to create different targets, and use a module map for the C code. That’s assuming straight-forward swift-calls-c.
Which doesn’t change the issues I’m having, since they don’t seem to be platform specific. Unlike the ones I’ve run into where some packages won’t build. I haven’t mentioned those before.
Fair enough. If you're looking to add a package dependency to your package (so that code from the other package compiles alongside yours and can be imported into your Swift files), see here. I hope that's helpful!
As I said, I haven’t had to deal with SwiftPM before, since I use Xcode and it hides it all from me (and I haven’t made a package yet!), so this is all useful!
I am very much looking forward to the official freebsd release. It’s very exciting to have a good OO, type- and memory-safe language!