11import 'dart:io' ;
22
3+ import 'package:archive/archive_io.dart' ;
34import 'package:path/path.dart' as p;
5+ import 'package:http/http.dart' ;
46
57typedef SqliteVersion = ({String version, String year});
68
@@ -21,6 +23,9 @@ Future<void> main(List<String> args) async {
2123extension 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
2631Future <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