@@ -8,7 +8,7 @@ import 'package:path/path.dart' as p;
8
8
9
9
const defaultSqlitePath = 'libsqlite3.so.0' ;
10
10
11
- const libPath = '../target/debug' ;
11
+ const cargoDebugPath = '../target/debug' ;
12
12
var didLoadExtension = false ;
13
13
14
14
void applyOpenOverride () {
@@ -44,16 +44,45 @@ CommonDatabase openTestDatabase(
44
44
void loadExtension () {
45
45
applyOpenOverride ();
46
46
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 ())));
48
51
var extension = SqliteExtension .inLibrary (lib, 'sqlite3_powersync_init' );
49
52
sqlite3.ensureExtensionLoaded (extension );
50
53
didLoadExtension = true ;
51
54
}
52
55
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 ()) {
57
86
Abi .androidArm ||
58
87
Abi .androidArm64 ||
59
88
Abi .androidX64 =>
@@ -70,5 +99,5 @@ String getLibraryForPlatform({String? path = "."}) {
70
99
'Unsupported processor architecture "${Abi .current ()}". '
71
100
'Please open an issue on GitHub to request it.' ,
72
101
)
73
- })) ;
102
+ };
74
103
}
0 commit comments