Skip to content

Use build hooks to link core extension#386

Merged
simolus3 merged 8 commits into
devfrom
hooks-for-core-extension
Mar 31, 2026
Merged

Use build hooks to link core extension#386
simolus3 merged 8 commits into
devfrom
hooks-for-core-extension

Conversation

@simolus3
Copy link
Copy Markdown
Contributor

@simolus3 simolus3 commented Mar 26, 2026

Note: I'll use the dev branch for most of the changes from the Dart SDK proposal. That way, we can merge and release everything in the end without making it more difficult to land other changes in the meantime.

Currently, linking the SQLite core extension is the responsibility of the powersync_flutter_libs package. It uses Gradle, SwiftPM and CocoaPods dependencies as well as CMake scripts to make the core extension loadable via DynamicLibrary.open from Dart. This works alright, but has two main downsides:

  1. We need workarounds to link the core extension outside of Flutter apps, e.g. for tests or if users want to use the SDK in Dart CLI applications.
  2. Updating the core extension is a hassle since we need to do it in multiple places.

Starting from Dart 3.10, released in November last year, we have a better option available: Build hooks! These run as part of the toolchain whenever a Dart app is built, and can contribute native code to the app. It's the responsibility of the Dart tool to consume added code in a platform-specific way. So Flutter would setup an XCFramework when building an iOS app for instance, and dart test would load the emitted library manually.

This allows us to write that bundling logic in a single place (hook/build.dart) and delete powersync_flutter_libs.

Important

Instead of deleting powersync_flutter_libs outright, I've removed all build code from that package. By then depending on the updated empty package version, we can ensure users don't end up with the new hook and the old bundling package in their Flutter app.

Tests

  • powersync_core unit tests
  • Test demo on Android.
  • Test demo on iOS simulator.
  • Test demo on iOS with testflight.
  • Test demo on macOS.
  • Test demo on Linux.
  • Test demo on Windows.

@simolus3 simolus3 marked this pull request as ready for review March 26, 2026 15:46
@simolus3 simolus3 requested a review from rkistner March 26, 2026 15:46
@simolus3 simolus3 merged commit 604017f into dev Mar 31, 2026
4 checks passed
@simolus3 simolus3 deleted the hooks-for-core-extension branch March 31, 2026 07:22
simolus3 added a commit that referenced this pull request Mar 31, 2026
@simolus3 simolus3 mentioned this pull request Apr 9, 2026
simolus3 added a commit that referenced this pull request Apr 9, 2026
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.

3 participants