Skip to content

Commit 9b84530

Browse files
committed
Fix sqlite build on Windows
1 parent 3f21622 commit 9b84530

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ jobs:
126126
name: Testing on ${{ matrix.os }}
127127
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
128128
runs-on: ${{ matrix.os }}
129-
needs: [libs_linux, libs_macos]
129+
needs: [libs_linux, libs_macos, libs_windows]
130130
strategy:
131131
fail-fast: false
132132
matrix:

dart/pubspec.lock

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ packages:
1717
url: "https://pub.dev"
1818
source: hosted
1919
version: "7.5.6"
20+
archive:
21+
dependency: "direct dev"
22+
description:
23+
name: archive
24+
sha256: "2fde1607386ab523f7a36bb3e7edb43bd58e6edaf2ffb29d8a6d578b297fdbbd"
25+
url: "https://pub.dev"
26+
source: hosted
27+
version: "4.0.7"
2028
args:
2129
dependency: transitive
2230
description:
@@ -153,6 +161,14 @@ packages:
153161
url: "https://pub.dev"
154162
source: hosted
155163
version: "2.1.3"
164+
http:
165+
dependency: "direct dev"
166+
description:
167+
name: http
168+
sha256: bb2ce4590bc2667c96f318d68cac1b5a7987ec819351d32b1c987239a815e007
169+
url: "https://pub.dev"
170+
source: hosted
171+
version: "1.5.0"
156172
http_multi_server:
157173
dependency: transitive
158174
description:
@@ -265,6 +281,14 @@ packages:
265281
url: "https://pub.dev"
266282
source: hosted
267283
version: "1.5.1"
284+
posix:
285+
dependency: transitive
286+
description:
287+
name: posix
288+
sha256: "6323a5b0fa688b6a010df4905a56b00181479e6d10534cecfecede2aa55add61"
289+
url: "https://pub.dev"
290+
source: hosted
291+
version: "6.0.3"
268292
power_extensions:
269293
dependency: transitive
270294
description:

dart/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ dev_dependencies:
1717
convert: ^3.1.2
1818
meta: ^1.16.0
1919
path: ^1.9.1
20+
http: ^1.5.0
21+
archive: ^4.0.7

dart/tool/download_sqlite3.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'dart:io';
22

3+
import 'package:archive/archive_io.dart';
34
import 'package:path/path.dart' as p;
5+
import 'package:http/http.dart';
46

57
typedef SqliteVersion = ({String version, String year});
68

@@ -21,6 +23,9 @@ Future<void> main(List<String> args) async {
2123
extension on SqliteVersion {
2224
String get autoconfUrl =>
2325
'https://sqlite.org/$year/sqlite-autoconf-$version.tar.gz';
26+
27+
String get windowsUrl =>
28+
'https://sqlite.org/$year/sqlite-dll-win-x64-$version.zip';
2429
}
2530

2631
Future<void> _downloadAndCompile(String name, SqliteVersion version,
@@ -52,6 +57,38 @@ Future<void> _downloadAndCompile(String name, SqliteVersion version,
5257
await Directory.systemTemp.createTemp('powersync-core-compile-sqlite3');
5358
final temporaryDirPath = temporaryDir.path;
5459

60+
// Compiling on Windows is ugly because we need users to have Visual Studio
61+
// installed and all those tools activated in the current shell.
62+
// Much easier to just download precompiled builds.
63+
if (Platform.isWindows) {
64+
final windowsUri = version.windowsUrl;
65+
final sqlite3Zip = p.join(temporaryDirPath, 'sqlite3.zip');
66+
final client = Client();
67+
final response = await client
68+
.send(Request('GET', Uri.parse(windowsUri))..followRedirects = true);
69+
if (response.statusCode != 200) {
70+
print(
71+
'Could not download $windowsUri, status code ${response.statusCode}');
72+
exit(1);
73+
}
74+
await response.stream.pipe(File(sqlite3Zip).openWrite());
75+
76+
final inputStream = InputFileStream(sqlite3Zip);
77+
final archive = ZipDecoder().decodeStream(inputStream);
78+
79+
for (final file in archive.files) {
80+
if (file.isFile && file.name == 'sqlite3.dll') {
81+
final outputStream = OutputFileStream(p.join(target, 'sqlite3.dll'));
82+
83+
file.writeContent(outputStream);
84+
outputStream.close();
85+
}
86+
}
87+
88+
await File(p.join(target, 'version')).writeAsString(version.version);
89+
exit(0);
90+
}
91+
5592
await _run('curl -L ${version.autoconfUrl} --output sqlite.tar.gz',
5693
workingDirectory: temporaryDirPath);
5794
await _run('tar zxvf sqlite.tar.gz', workingDirectory: temporaryDirPath);

0 commit comments

Comments
 (0)