@@ -8,7 +8,7 @@ import 'package:path/path.dart' as p;
88
99const defaultSqlitePath = 'libsqlite3.so.0' ;
1010
11- const libPath = '../target/debug' ;
11+ const cargoDebugPath = '../target/debug' ;
1212var didLoadExtension = false ;
1313
1414void applyOpenOverride () {
@@ -44,16 +44,45 @@ CommonDatabase openTestDatabase(
4444void loadExtension () {
4545 applyOpenOverride ();
4646
47- var lib = DynamicLibrary .open (getLibraryForPlatform (path: libPath));
47+ // Using an absolute path is required for macOS, where Dart can't dlopen
48+ // relative paths due to being a "hardened program".
49+ var lib =
50+ DynamicLibrary .open (p.normalize (p.absolute (resolvePowerSyncLibrary ())));
4851 var extension = SqliteExtension .inLibrary (lib, 'sqlite3_powersync_init' );
4952 sqlite3.ensureExtensionLoaded (extension );
5053 didLoadExtension = true ;
5154}
5255
53- String getLibraryForPlatform ({String ? path = "." }) {
54- // Using an absolute path is required for macOS, where Dart can't dlopen
55- // relative paths due to being a "hardened program".
56- return p.normalize (p.absolute (switch (Abi .current ()) {
56+ String resolvePowerSyncLibrary () {
57+ if (Directory ('assets' ).existsSync ()) {
58+ // For the CI tests, we download prebuilt artifacts from an earlier step
59+ // into assets. Use that.
60+ const prefix = 'assets' ;
61+
62+ return p.join (
63+ prefix,
64+ switch (Abi .current ()) {
65+ Abi .macosX64 => 'libpowersync_x64.dylib' ,
66+ Abi .macosArm64 => 'libpowersync_aarch64.dylib' ,
67+ Abi .windowsX64 => 'powersync_x64.dll' ,
68+ Abi .windowsArm64 => 'powersync_aarch64.dll' ,
69+ Abi .linuxX64 => 'libpowersync_x64.so' ,
70+ Abi .linuxArm => 'libpowersync_armv7.so' ,
71+ Abi .linuxArm64 => 'libpowersync_aarch64.so' ,
72+ Abi .linuxRiscv64 => 'libpowersync_riscv64gc.so' ,
73+ _ => throw ArgumentError (
74+ 'Unsupported processor architecture "${Abi .current ()}". '
75+ 'Please open an issue on GitHub to request it.' ,
76+ )
77+ });
78+ } else {
79+ // Otherwise, use a local build from ../target/debug/.
80+ return _getLibraryForPlatform ();
81+ }
82+ }
83+
84+ String _getLibraryForPlatform ({String ? path = cargoDebugPath}) {
85+ return switch (Abi .current ()) {
5786 Abi .androidArm ||
5887 Abi .androidArm64 ||
5988 Abi .androidX64 =>
@@ -70,5 +99,5 @@ String getLibraryForPlatform({String? path = "."}) {
7099 'Unsupported processor architecture "${Abi .current ()}". '
71100 'Please open an issue on GitHub to request it.' ,
72101 )
73- })) ;
102+ };
74103}
0 commit comments