I work on the MongoDB Swift driver, which has a vendored copy of the MongoDB C driver. Both the library itself and the vendored C code are built via SwiftPM.
In order for it to build correctly, we have to define a few macros in our Package.swift:
cSettings: [
.define("MONGO_SWIFT_OS_LINUX", .when(platforms: [.linux])),
.define("MONGO_SWIFT_OS_DARWIN", .when(platforms: [.macOS])),
.define("BSON_COMPILATION"),
.define("MONGOC_COMPILATION")
]
Everything builds just fine from the command line via swift build
, but if you open the folder in Xcode and try to build the project that way, it appears the cSettings
are not respected; there are a number of errors resulting from MONGOC_COMPILATION
and BSON_COMPILATION
being undefined.
The same issue occurs if you add the library as a dependency of another project via File > Swift Packages > Add Package Dependency...
This has unfortunately provided a pretty bad initial installation experience for anyone trying out our library who develops in Xcode and a number of users have brought it up with us (see #387).
A couple of workarounds are discussed on that GitHub thread, both relying on swift package generate-xcodeproj
. I'm posting here mainly in hopes of getting more eyes on this issue and to see if there are any updates on the status of this, as well to see if anyone has any better suggested workarounds. I rarely develop in Xcode myself and I'm not sure if there are other options for working around this that I'm not aware of.
Alternatively, maybe there are ways to work around this by updating our vendored code or Package.swift?
FWIW we filed a Swift bug about this which looks like it got turned into a Radar ticket (which I can't see of course), and as mentioned in the linked GitHub issue one of our users also filed a bug report as well (FB7777476), but I'm not sure what the status of any of those are.
Thanks for reading!