Skip to content

Commit 429b5f6

Browse files
committed
Support testing with downloaded binaries
1 parent 9b84530 commit 429b5f6

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

.github/workflows/tests.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,19 @@ jobs:
152152
dart run tool/download_sqlite3.dart
153153
dart analyze
154154
155+
- name: Download libs
156+
uses: actions/download-artifact@v5
157+
with:
158+
merge-multiple: true
159+
name: linux-library,macos-library,windows-library
160+
path: dart/assets
161+
162+
- name: View downloaded artifacts
163+
if: runner.os == 'Linux'
164+
working-directory: dart
165+
run: |
166+
ls -al assets/
167+
155168
- name: Dart tests on Linux
156169
if: runner.os == 'Linux'
157170
working-directory: dart

dart/test/utils/native_test_utils.dart

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:path/path.dart' as p;
88

99
const defaultSqlitePath = 'libsqlite3.so.0';
1010

11-
const libPath = '../target/debug';
11+
const cargoDebugPath = '../target/debug';
1212
var didLoadExtension = false;
1313

1414
void applyOpenOverride() {
@@ -44,16 +44,45 @@ CommonDatabase openTestDatabase(
4444
void 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

Comments
 (0)