i’m really struggling with this error when building a SwiftPM Snippet in a package that has a dependency on swift-collections
the project is swift-bson at 0.1.0, and i’m trying to add the following Snippet:
import BSON
do
{
let full:[UInt8] = [
0x09, 0x00, 0x00, 0x00, // Document header
0x08, 0x62, 0x00, 0x01, // Document body
0x00 // Trailing null byte
]
let bson:BSON.Document = .init(bytes: full[4 ..< 8])
print(bson)
}
when i do a fresh build of the package, i get
$ swift build --explicit-target-dependency-import-check=error
Building for debugging...
error: link command failed with exit code 1 (use -v to see invocation)
/swift/swift-bson/.build/checkouts/swift-collections/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift:79: error: undefined reference to 'round'
/swift/swift-bson/.build/checkouts/swift-collections/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift:79: error: undefined reference to 'rint'
/swift/swift-bson/.build/checkouts/swift-collections/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift:79: error: undefined reference to 'trunc'
/swift/swift-bson/.build/checkouts/swift-collections/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift:79: error: undefined reference to 'ceil'
/swift/swift-bson/.build/checkouts/swift-collections/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift:79: error: undefined reference to 'floor'
/swift/swift-bson/.build/checkouts/swift-collections/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift:79: error: undefined reference to 'ceil'
/swift/swift-bson/.build/checkouts/swift-collections/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift:79: error: undefined reference to 'floor'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[336/337] Linking GettingStarted
what is really strange is that the BSON target has no actual dependency on swift-collections, that package is only used by a different target called BSON_OrderedCollections.
i’m not certain who the “somebody” is here, but i suspect it’s SwiftPM, because the package compiles successfully when the Snippet is removed, or when the BSON_OrderedCollections product is commented out, even though they are not related to each other except through a common dependency on the BSON target.
Huh. swift-collections just calls Double.rounded(.up) from the Standard Library; it does not directly reference those routines.
let minimumEntries = Swift.max(
Int((Double(capacity) / maximumLoadFactor).rounded(.up)),
capacity + 1)
It is admittedly somewhat silly to use floating point arithmetics to implement the minimum/maximum load factors -- the code in that file can also be implemented with integers.
Doing something like this is an option if the SwiftPM issue proves difficult to fix, e.g., if the code needs to work with shipping toolchains, and there is no easy client-level workaround. (Let me know if you need this.)
@lorentey making this change would be really helpful for embedded where we don't want to assume an fpu is available. If I recall correctly @kubamracek had a PR to do this (or something very similar)
yes please! i’d love to start documenting the swift-bson library for public consumption, and this is preventing me from adding the example snippets to the tutorial i am trying to write.
i’m reluctant to ask for changes to an unrelated library to work around what is almost certainly a bug in SwiftPM, but if there are other more compelling reasons to do this, all the better!