Skip to content

Add GRDBDynamic trait. - #518

Open
VentanYu wants to merge 1 commit into
pointfreeco:mainfrom
VentanYu:add-grdb-dynamic-trait
Open

Add GRDBDynamic trait.#518
VentanYu wants to merge 1 commit into
pointfreeco:mainfrom
VentanYu:add-grdb-dynamic-trait

Conversation

@VentanYu

@VentanYu VentanYu commented Aug 6, 2026

Copy link
Copy Markdown

Context

SQLiteData currently links the static GRDB library from GRDB.swift, which offers two products: GRDB (static) and GRDB-dynamic. GRDB's documentation recommends GRDB-dynamic when 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 SQLiteData is consumed by several frameworks in the same app (e.g. a multi-framework project), the statically embedded GRDB code causes conflicts.

Changes

  • Adds a GRDBDynamic trait to the package.
  • When the trait is enabled, SQLiteData links the GRDB-dynamic product of GRDB.swift instead of the static GRDB product.
  • The default behavior is unchanged: without the trait, the static GRDB library is linked as before.

Usage

Enable the trait when declaring the dependency (requires SwiftPM 6.1+):

.package(url: "https://github.com/pointfreeco/sqlite-data", from: "", traits: ["GRDBDynamic"])

Verification

  • swift build (default) and swift build --traits GRDBDynamic both pass; the trait-enabled build produces libGRDB-dynamic.dylib.
  • Verified in a production app with multiple frameworks (Swift ≥ 6.1).
  • Package@swift-6.0.swift is untouched (traits require SwiftPM 6.1+, so the 6.0 fallback keeps the static GRDB).

@stephencelis stephencelis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this! Just one thing to think on…

Comment thread Package.swift
Comment on lines 88 to +93
.product(name: "GRDB", package: "GRDB.swift"),
.product(
name: "GRDB-dynamic",
package: "GRDB.swift",
condition: .when(traits: ["GRDBDynamic"])
),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GRDB's README states:

GRDB offers two libraries, GRDB and GRDB-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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants