Skip to content

Try loading winsqlite3.dll on Windows #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
dart: [stable, dev]
sqlite: [system, compiled]

name: Unit tests with Dart ${{ matrix.dart }} on ${{ matrix.os }}
name: Unit tests with Dart ${{ matrix.dart }} on ${{ matrix.os }} with ${{ matrix.sqlite }} sqlite
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -148,34 +149,40 @@ jobs:
sdk: ${{ matrix.dart }}

- name: Download compiled sqlite3
if: runner.os == 'Linux' || runner.os == 'Windows' || runner.os == 'macOS'
if: matrix.sqlite == 'compiled' && (runner.os == 'Linux' || runner.os == 'Windows' || runner.os == 'macOS')
uses: actions/download-artifact@v4
with:
name: sqlite3-${{ runner.os }}
path: sqlite/out

- name: Install compiled sqlite3 (Linux)
if: runner.os == 'Linux'
if: matrix.sqlite == 'compiled' && runner.os == 'Linux'
run: |
chmod a+x sqlite/out/sqlite3
realpath sqlite/out >> $GITHUB_PATH
echo "LD_LIBRARY_PATH=$(realpath sqlite/out)" >> $GITHUB_ENV
echo "C_INCLUDE_PATH=$(realpath sqlite/out)" >> $GITHUB_ENV
- name: Install system sqlite3 (Ubuntu)
if: matrix.sqlite == 'system' && runner.os == 'Linux'
run: sudo apt install sqlite3
- name: Install compiled sqlite3 (macOS)
if: runner.os == 'macOS'
if: matrix.sqlite == 'compiled' && runner.os == 'macOS'
run: |
chmod a+x sqlite/out/sqlite3
echo "$(pwd)/sqlite/out" >> $GITHUB_PATH
echo "DYLD_LIBRARY_PATH=$(pwd)/sqlite/out" >> $GITHUB_ENV
echo "CPATH=$(pwd)/sqlite/out" >> $GITHUB_ENV
- uses: ilammy/msvc-dev-cmd@v1
if: runner.os == 'Windows'
if: matrix.sqlite == 'compiled' && runner.os == 'Windows'
- name: Install compiled sqlite3 (Windows)
if: runner.os == 'Windows'
if: matrix.sqlite == 'compiled' && runner.os == 'Windows'
run: |
echo $env:path
Resolve-Path -Path "sqlite/out" >> $env:GITHUB_PATH
"INCLUDE=" + $env:INCLUDE + ";" + (Resolve-Path -Path "sqlite/out") >> $env:GITHUB_EN
- name: Check if Winsqlite exists
if: matrix.sqlite == 'system' && runner.os == 'Windows'
run: Test-Path C:\Windows\System32\winsqlite3.dll

- uses: actions/cache@v4
with:
Expand All @@ -188,11 +195,11 @@ jobs:
- name: Test sqlite3 package
run: |
dart pub get
dart test -P ci
dart test --test-randomize-ordering-seed "random" -P ci
working-directory: sqlite3/

- name: Test with SQLITE_OMIT_AUTOINIT
if: runner.os == 'Linux'
if: matrix.sqlite == 'compiled' && runner.os == 'Linux'
run: |
ls $LD_LIBRARY_PATH
dart run tool/check_compile_time_option.dart OMIT_AUTOINIT
Expand All @@ -202,6 +209,7 @@ jobs:
working-directory: sqlite3/

- name: Test sqlite3_test package
if: matrix.sqlite != 'system' || runner.os != 'Windows'
run: |
dart pub get
dart test
Expand All @@ -215,7 +223,7 @@ jobs:
# If browsers behave differently on different platforms, surely that's not our fault...
# So, only run browser tests on Linux to be faster.
# todo: Something broke Dart web tests in Dart 2.18, it looks like this is related to finalizers
if: runner.os == 'Linux'
if: matrix.sqlite == 'compiled' && runner.os == 'Linux'
working-directory: sqlite3/

# The integration tests for android are currently broken (the emulator doesn't want to
Expand Down
8 changes: 6 additions & 2 deletions sqlite3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ Here's how to use this library on the most popular platforms:
- __macOS__: Contains a built-in version of sqlite that this package will use by default.
Also, you can depend on `sqlite3_flutter_libs` if you want to include the latest
sqlite3 version with your app.
- __Windows__: Flutter users can depend on `sqlite3_flutter_libs` to ship the latest sqlite3
- __Windows__: Contains a built-in version of sqlite (winsqlite3.dll) that this package will use by default.
winsqlite is used by Windows OS components and as the backend of .NET database APIs,
but is [otherwise undocumented](https://github.com/microsoft/win32metadata/issues/824#issuecomment-1067220882);
so you may still want to provide a sqlite3 binary you control.
Flutter users can depend on `sqlite3_flutter_libs` to ship the latest sqlite3
version with their app.
When not using Flutter, you need to manually include sqlite3 (see below).
When not using Flutter, you can manually include sqlite3 (see below).
- __Web__: See [web support](#wasm-web-support) below.

On Android, iOS and macOS, you can depend on the `sqlcipher_flutter_libs` package to use
Expand Down
13 changes: 12 additions & 1 deletion sqlite3/lib/src/ffi/load_library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,18 @@ DynamicLibrary _defaultOpen() {
}
return result;
} else if (Platform.isWindows) {
return DynamicLibrary.open('sqlite3.dll');
try {
// Compability with older versions of package:sqlite3 that did this
return DynamicLibrary.open('sqlite3.dll');
} on ArgumentError catch (_) {
// Load the OS distribution of sqlite3 as a fallback
// This is used as the backend for .NET based Database APIs
// and several Windows apps & features,
// but you may still want to bring your own copy of sqlite3
// since it's undocumented functionality.
// https://github.com/microsoft/win32metadata/issues/824#issuecomment-1067220882
return DynamicLibrary.open('winsqlite3.dll');
}
}

throw UnsupportedError('Unsupported platform: ${Platform.operatingSystem}');
Expand Down
Loading