Skip to content

Commit eca586e

Browse files
committed
Test with minimum supported sqlite
1 parent 8442338 commit eca586e

File tree

6 files changed

+131
-16
lines changed

6 files changed

+131
-16
lines changed

.github/workflows/tests.yml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ on:
22
push:
33
pull_request:
44
name: "tests"
5+
56
jobs:
67
build:
78
name: Testing on ${{ matrix.os }}
@@ -10,11 +11,10 @@ jobs:
1011
strategy:
1112
fail-fast: false
1213
matrix:
13-
include:
14-
- os: ubuntu-24.04
15-
- os: macos-latest
14+
os: [ubuntu-24.04, macos-latest]
15+
1616
steps:
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
1818
with:
1919
submodules: true
2020
- uses: dart-lang/setup-dart@v1
@@ -55,11 +55,27 @@ jobs:
5555
run: |
5656
./target/release/sqlite3 ":memory:" ".load ./target/release/libpowersync" "select powersync_rs_version()"
5757
58-
- name: Run dart-based tests
59-
# Extension loading fails on macos currently
60-
if: matrix.os == 'ubuntu-24.04'
58+
- uses: actions/cache@v4
59+
id: sqlite_build
60+
with:
61+
path: dart/.dart_tool/sqlite3/
62+
key: ${{ runner.os }}-${{ hashFiles('dart/tool/') }}
63+
64+
- name: Setup Dart tests
65+
working-directory: dart
6166
run: |
62-
cd dart
6367
dart pub get
64-
dart test
68+
dart run tool/download_sqlite3.dart
6569
dart analyze
70+
71+
- name: Dart tests on Linux
72+
if: runner.os == 'ubuntu'
73+
run: |
74+
CORE_TEST_SQLITE=.dart_tool/sqlite3/latest/libsqlite3.so dart test
75+
CORE_TEST_SQLITE=.dart_tool/sqlite3/minimum/libsqlite3.so dart test
76+
77+
- name: Dart tests on macOS
78+
if: runner.os == 'macOS'
79+
run: |
80+
CORE_TEST_SQLITE=.dart_tool/sqlite3/latest/libsqlite3.dylib dart test
81+
CORE_TEST_SQLITE=.dart_tool/sqlite3/minimum/libsqlite3.dylib dart test

crates/core/src/constants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ pub const FULL_GIT_HASH: &'static str = env!("GIT_HASH");
55

66
// We need 3.44 or later to use an `ORDER BY` in an aggregate function invocation.
77
//
8-
// When raising the minimum version requirement, also change the CI to ensure we're testing on the
9-
// oldest SQLite version we claim to support.
8+
// When raising the minimum version requirement, also change it in download_sqlite3.dart to ensure
9+
// we're testing with the minimum version we claim to support.
1010
pub const MIN_SQLITE_VERSION_NUMBER: c_int = 3044000;
1111

1212
pub fn short_git_hash() -> &'static str {

dart/pubspec.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ packages:
1313
dependency: transitive
1414
description:
1515
name: analyzer
16-
sha256: f6154230675c44a191f2e20d16eeceb4aa18b30ca732db4efaf94c6a7d43cfa6
16+
sha256: de617bfdc64f3d8b00835ec2957441ceca0a29cdf7881f7ab231bc14f71159c0
1717
url: "https://pub.dev"
1818
source: hosted
19-
version: "7.5.2"
19+
version: "7.5.6"
2020
args:
2121
dependency: transitive
2222
description:
@@ -85,10 +85,10 @@ packages:
8585
dependency: transitive
8686
description:
8787
name: coverage
88-
sha256: aa07dbe5f2294c827b7edb9a87bba44a9c15a3cc81bc8da2ca19b37322d30080
88+
sha256: "5da775aa218eaf2151c721b16c01c7676fbfdd99cebba2bf64e8b807a28ff94d"
8989
url: "https://pub.dev"
9090
source: hosted
91-
version: "1.14.1"
91+
version: "1.15.0"
9292
crypto:
9393
dependency: transitive
9494
description:
@@ -250,7 +250,7 @@ packages:
250250
source: hosted
251251
version: "0.1.1"
252252
path:
253-
dependency: transitive
253+
dependency: "direct dev"
254254
description:
255255
name: path
256256
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"

dart/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ dev_dependencies:
1616
fake_async: ^1.3.3
1717
convert: ^3.1.2
1818
meta: ^1.16.0
19+
path: ^1.9.1

dart/test/utils/native_test_utils.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ const libPath = '../target/debug';
1212
var didLoadExtension = false;
1313

1414
void applyOpenOverride() {
15+
if (Platform.environment['CORE_TEST_SQLITE'] case final sqlite?) {
16+
sqlite_open.open
17+
.overrideForAll(() => DynamicLibrary.open(p.absolute(sqlite)));
18+
}
19+
1520
sqlite_open.open.overrideFor(sqlite_open.OperatingSystem.linux, () {
1621
return DynamicLibrary.open('libsqlite3.so.0');
1722
});

dart/tool/download_sqlite3.dart

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import 'dart:io';
2+
3+
import 'package:path/path.dart' as p;
4+
5+
typedef SqliteVersion = ({String version, String year});
6+
7+
const SqliteVersion latest = (version: '3500200', year: '2025');
8+
const SqliteVersion minimum = (version: '3440000', year: '2023');
9+
10+
Future<void> main(List<String> args) async {
11+
if (args.contains('version')) {
12+
print(latest.version);
13+
exit(0);
14+
}
15+
16+
await _downloadAndCompile('latest', latest, force: args.contains('--force'));
17+
await _downloadAndCompile('minimum', minimum,
18+
force: args.contains('--force'));
19+
}
20+
21+
extension on SqliteVersion {
22+
String get autoconfUrl =>
23+
'https://sqlite.org/$year/sqlite-autoconf-$version.tar.gz';
24+
}
25+
26+
Future<void> _downloadAndCompile(String name, SqliteVersion version,
27+
{bool force = false}) async {
28+
final dartDirectory = p.dirname(p.dirname(Platform.script.toFilePath()));
29+
final target = p.join(dartDirectory, '.dart_tool', 'sqlite3', name);
30+
final versionFile = File(p.join(target, 'version'));
31+
32+
final needsDownload = force ||
33+
!versionFile.existsSync() ||
34+
versionFile.readAsStringSync() != version.version;
35+
36+
if (!needsDownload) {
37+
print(
38+
'Not downloading sqlite3 $name as it has already been downloaded. Use '
39+
'--force to re-compile it.',
40+
);
41+
return;
42+
}
43+
44+
print('Downloading and compiling sqlite3 $name (${version.version})');
45+
final targetDirectory = Directory(target);
46+
47+
if (!targetDirectory.existsSync()) {
48+
targetDirectory.createSync(recursive: true);
49+
}
50+
51+
final temporaryDir =
52+
await Directory.systemTemp.createTemp('powersync-core-compile-sqlite3');
53+
final temporaryDirPath = temporaryDir.path;
54+
55+
await _run('curl -L ${version.autoconfUrl} --output sqlite.tar.gz',
56+
workingDirectory: temporaryDirPath);
57+
await _run('tar zxvf sqlite.tar.gz', workingDirectory: temporaryDirPath);
58+
59+
final sqlitePath =
60+
p.join(temporaryDirPath, 'sqlite-autoconf-${version.version}');
61+
62+
await _run('./configure', workingDirectory: sqlitePath);
63+
await _run('make -j', workingDirectory: sqlitePath);
64+
65+
await File(p.join(sqlitePath, 'sqlite3')).copy(p.join(target, 'sqlite3'));
66+
final libsPath = name == 'latest' ? sqlitePath : p.join(sqlitePath, '.libs');
67+
68+
if (Platform.isLinux) {
69+
await File(p.join(libsPath, 'libsqlite3.so'))
70+
.copy(p.join(target, 'libsqlite3.so'));
71+
} else if (Platform.isMacOS) {
72+
await File(p.join(libsPath, 'libsqlite3.dylib'))
73+
.copy(p.join(target, 'libsqlite3.dylib'));
74+
}
75+
76+
await File(p.join(target, 'version')).writeAsString(version.version);
77+
}
78+
79+
Future<void> _run(String command, {String? workingDirectory}) async {
80+
print('Running $command');
81+
82+
final proc = await Process.start(
83+
'sh',
84+
['-c', command],
85+
mode: ProcessStartMode.inheritStdio,
86+
workingDirectory: workingDirectory,
87+
);
88+
final exitCode = await proc.exitCode;
89+
90+
if (exitCode != 0) {
91+
exit(exitCode);
92+
}
93+
}

0 commit comments

Comments
 (0)