Add GRDBDynamic trait. - #518
Conversation
stephencelis
left a comment
There was a problem hiding this comment.
Thanks for looking into this! Just one thing to think on…
| .product(name: "GRDB", package: "GRDB.swift"), | ||
| .product( | ||
| name: "GRDB-dynamic", | ||
| package: "GRDB.swift", | ||
| condition: .when(traits: ["GRDBDynamic"]) | ||
| ), |
There was a problem hiding this comment.
GRDB's README states:
GRDB offers two libraries,
GRDBandGRDB-dynamic. Pick only one.
So I do wonder if this is legit to do or if it could lead to linking problems down the line. And I guess there's no way to negate a package condition 😕
We'll think on it, but I wonder if traits aren't the right tool here after all.
There was a problem hiding this comment.
In my current build tests, when the trait is enabled, SPM automatically picks GRDB-dynamic over GRDB. I’m not entirely sure how it makes that decision, but it does work for now.
That said, depending on both products at the same time does feel a bit odd, and can’t be sure this behavior won’t change later. A more reliable approach might be to expose two separate products and avoid using traits altogether.
Context
SQLiteDatacurrently links the staticGRDBlibrary from GRDB.swift, which offers two products:GRDB(static) andGRDB-dynamic. GRDB's documentation recommendsGRDB-dynamicwhen a package is linked into multiple targets within a single app, so all targets share one dynamic framework instead of each embedding a copy of the GRDB code.When
SQLiteDatais consumed by several frameworks in the same app (e.g. a multi-framework project), the statically embedded GRDB code causes conflicts.Changes
GRDBDynamictrait to the package.SQLiteDatalinks theGRDB-dynamicproduct of GRDB.swift instead of the staticGRDBproduct.GRDBlibrary is linked as before.Usage
Enable the trait when declaring the dependency (requires SwiftPM 6.1+):
Verification
swift build(default) andswift build --traits GRDBDynamicboth pass; the trait-enabled build produceslibGRDB-dynamic.dylib.Package@swift-6.0.swiftis untouched (traits require SwiftPM 6.1+, so the 6.0 fallback keeps the staticGRDB).