Skip to content

Commit 70ff168

Browse files
Extended CI for windows
1 parent 38b96e6 commit 70ff168

File tree

3 files changed

+226
-23
lines changed

3 files changed

+226
-23
lines changed

.github/scripts/test_sqlite_no_extensions.ps1

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
$ErrorActionPreference = "Stop"
55

66
$WorkDir = Get-Location
7-
$BuildDir = Join-Path $WorkDir "build_sqlite_win"
7+
$BuildDir = Join-Path $WorkDir "build_sqlite_win_restricted"
88
$InstallDir = Join-Path $BuildDir "install"
99

1010
Write-Host "Using build directory: $BuildDir"
@@ -16,59 +16,74 @@ Set-Location $BuildDir
1616

1717
$SqliteVersion = "3450100"
1818
$SqliteYear = "2024"
19-
$SqliteSource = "sqlite-amalgamation-$SqliteVersion"
20-
$SqliteZip = "$SqliteSource.zip"
19+
$SqliteSourceDirName = "sqlite-src-$SqliteVersion"
20+
$SqliteZip = "$SqliteSourceDirName.zip"
2121

22-
# Download SQLite amalgamation
22+
# Download full SQLite source (consistency with Linux scripts)
2323
if (-not (Test-Path $SqliteZip)) {
2424
Write-Host "Downloading SQLite $SqliteVersion..."
2525
$Url = "https://sqlite.org/$SqliteYear/$SqliteZip"
2626
Invoke-WebRequest -Uri $Url -OutFile $SqliteZip
2727
}
2828

29-
if (-not (Test-Path $SqliteSource)) {
29+
if (-not (Test-Path $SqliteSourceDirName)) {
3030
Write-Host "Extracting SQLite..."
3131
Expand-Archive -Path $SqliteZip -DestinationPath $BuildDir
3232
}
3333

34-
Set-Location $SqliteSource
34+
Set-Location $SqliteSourceDirName
3535

36-
# Compile SQLite with extension loading disabled
37-
# We assume cl.exe (MSVC) is in the path (run from Developer Command Prompt or similar)
38-
Write-Host "Compiling SQLite (DSQLITE_OMIT_LOAD_EXTENSION)..."
36+
# Create install/bin and install/lib directories
37+
$InstallBin = Join-Path $InstallDir "bin"
38+
$InstallLib = Join-Path $InstallDir "lib"
39+
New-Item -ItemType Directory -Force -Path $InstallBin | Out-Null
40+
New-Item -ItemType Directory -Force -Path $InstallLib | Out-Null
3941

40-
# Using /c (compile only), /O2 (optimize), /DSQLITE_OMIT_LOAD_EXTENSION
41-
cl.exe /c /O2 /DSQLITE_OMIT_LOAD_EXTENSION sqlite3.c
42+
# Compile SQLite with extension loading disabled as a DLL
43+
# We build a DLL so that GetProcAddress logic in diesel can work reliably (or fail reliably)
44+
# /O2 = Optimize
45+
# /LD = Create DLL
46+
# /DSQLITE_OMIT_LOAD_EXTENSION = The feature we are testing
47+
# /Fe: = File executable (output name)
48+
Write-Host "Compiling SQLite DLL (DSQLITE_OMIT_LOAD_EXTENSION)..."
4249

43-
# Create static library
44-
lib.exe /OUT:sqlite3.lib sqlite3.obj
50+
cl.exe /O2 /LD /DSQLITE_OMIT_LOAD_EXTENSION sqlite3.c /Fe:sqlite3.dll
51+
52+
if (-not (Test-Path "sqlite3.dll")) {
53+
Write-Error "Failed to build sqlite3.dll"
54+
}
55+
56+
# Move artifacts to install locations
57+
Copy-Item "sqlite3.dll" -Destination $InstallBin
58+
Copy-Item "sqlite3.lib" -Destination $InstallLib
59+
# Also copy dll to lib dir for running convenience if needed, though PATH handles it
60+
Copy-Item "sqlite3.dll" -Destination $InstallLib
4561

4662
Write-Host "Compilation complete."
4763

4864
# Prepare environment for Cargo
49-
$AbsSqliteDir = (Get-Location).Path
65+
# SQLITE3_LIB_DIR tells build.rs where to find sqlite3.lib
66+
$env:SQLITE3_LIB_DIR = $InstallLib
5067

51-
# Set environment variables for libsqlite3-sys
52-
$env:SQLITE3_LIB_DIR = $AbsSqliteDir
53-
$env:SQLITE3_STATIC = "1"
54-
# For runtime check in tests
68+
# Add bin to PATH so the test executable can find sqlite3.dll at runtime
69+
$env:PATH = "$InstallBin;$env:PATH"
70+
71+
# Setting this to 1 tells the test suite to expect "no such function: load_extension"
5572
$env:DIESEL_TEST_SQLITE_EXTENSIONS_DISABLED = "1"
5673

5774
Set-Location $WorkDir
5875

5976
Write-Host "----------------------------------------------------------------"
6077
Write-Host "Running compilation check..."
6178

62-
# Clean to force relink
79+
# Clean to force relink with our new library
6380
cargo clean
6481

6582
Write-Host "Running tests against restricted SQLite..."
6683

67-
# We need to ensure we link against system libraries that sqlite3 might depend on if not fully static
68-
# but standard sqlite3.c usually keeps to itself or basics.
69-
7084
try {
71-
cargo test --package diesel_tests --test integration_tests load_extension --features sqlite
85+
# Run the specific test for extension loading
86+
cargo test --package diesel_tests --test integration_tests load_extension --features sqlite -- --nocapture
7287
Write-Host "----------------------------------------------------------------"
7388
Write-Host "SUCCESS: Diesel compiled and passed tests against SQLite without extension support."
7489
} catch {
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# PowerShell script for testing Diesel against a custom SQLite build (Windows)
2+
# This mimics test_sqlite_with_extensions.sh but adapted for MSVC environment
3+
# It verifies that extension loading works correctly when enabled.
4+
5+
$ErrorActionPreference = "Stop"
6+
7+
$WorkDir = Get-Location
8+
$BuildDir = Join-Path $WorkDir "build_sqlite_win_ext"
9+
$InstallDir = Join-Path $BuildDir "install"
10+
11+
Write-Host "Using build directory: $BuildDir"
12+
if (-not (Test-Path $BuildDir)) {
13+
New-Item -ItemType Directory -Force -Path $BuildDir | Out-Null
14+
}
15+
16+
Set-Location $BuildDir
17+
18+
$SqliteVersion = "3450100"
19+
$SqliteYear = "2024"
20+
$SqliteSourceDirName = "sqlite-src-$SqliteVersion"
21+
$SqliteZip = "$SqliteSourceDirName.zip"
22+
23+
# Download full SQLite source (to get ext/misc/uuid.c)
24+
if (-not (Test-Path $SqliteZip)) {
25+
Write-Host "Downloading SQLite $SqliteVersion..."
26+
$Url = "https://sqlite.org/$SqliteYear/$SqliteZip"
27+
Invoke-WebRequest -Uri $Url -OutFile $SqliteZip
28+
}
29+
30+
if (-not (Test-Path $SqliteSourceDirName)) {
31+
Write-Host "Extracting SQLite..."
32+
Expand-Archive -Path $SqliteZip -DestinationPath $BuildDir
33+
}
34+
35+
Set-Location $SqliteSourceDirName
36+
37+
# Create install/bin and install/lib directories
38+
$InstallBin = Join-Path $InstallDir "bin"
39+
$InstallLib = Join-Path $InstallDir "lib"
40+
New-Item -ItemType Directory -Force -Path $InstallBin | Out-Null
41+
New-Item -ItemType Directory -Force -Path $InstallLib | Out-Null
42+
43+
# ----------------------------------------------------------------
44+
# Build SQLite DLL
45+
# ----------------------------------------------------------------
46+
# -DSQLITE_ENABLE_MATH_FUNCTIONS: Enables math functions (needed for some tests)
47+
# /O2: Optimize
48+
# /LD: Create DLL
49+
# /Fe: Output name
50+
Write-Host "Compiling SQLite DLL (Extensions Enabled + Math)..."
51+
52+
cl.exe /O2 /LD /DSQLITE_ENABLE_MATH_FUNCTIONS sqlite3.c /Fe:sqlite3.dll
53+
54+
if (-not (Test-Path "sqlite3.dll")) {
55+
Write-Error "Failed to build sqlite3.dll"
56+
}
57+
58+
Copy-Item "sqlite3.dll" -Destination $InstallBin
59+
Copy-Item "sqlite3.lib" -Destination $InstallLib
60+
# Also copy dll to lib dir for easy finding
61+
Copy-Item "sqlite3.dll" -Destination $InstallLib
62+
63+
# ----------------------------------------------------------------
64+
# Build Extensions
65+
# ----------------------------------------------------------------
66+
Write-Host "Building Extensions..."
67+
68+
# 1. uuid.dll
69+
# Source: ext/misc/uuid.c
70+
# Needs to link against sqlite3.lib
71+
Write-Host "Building uuid.dll..."
72+
cl.exe /O2 /LD /I. ext/misc/uuid.c sqlite3.lib /Fe:uuid.dll
73+
74+
if (-not (Test-Path "uuid.dll")) {
75+
Write-Error "Failed to build uuid.dll"
76+
}
77+
Copy-Item "uuid.dll" -Destination $InstallLib
78+
79+
# 2. extension-functions.dll
80+
# Download straight from sqlite.org/contrib
81+
Write-Host "Downloading extension-functions.c..."
82+
$ExtFuncUrl = "https://www.sqlite.org/contrib/download/extension-functions.c?get=25"
83+
try {
84+
Invoke-WebRequest -Uri $ExtFuncUrl -OutFile "extension-functions.c"
85+
} catch {
86+
Write-Warning "Failed to download extension-functions.c. Skipping extension-functions.dll build."
87+
}
88+
89+
if (Test-Path "extension-functions.c") {
90+
Write-Host "Building extension-functions.dll..."
91+
# math.h functions usually linked automatically on Windows (or via standard lib)
92+
cl.exe /O2 /LD /I. extension-functions.c sqlite3.lib /Fe:extension-functions.dll
93+
94+
if (Test-Path "extension-functions.dll") {
95+
Copy-Item "extension-functions.dll" -Destination $InstallLib
96+
}
97+
}
98+
99+
# ----------------------------------------------------------------
100+
# Create symlinks/copies for common library names if needed
101+
# ----------------------------------------------------------------
102+
# The test might look for 'spellfix.so' (on Linux) or 'spellfix.dll'.
103+
# We need to see if we can build spellfix or if uuid is enough.
104+
# The Linux script creates a symlink: spellfix.so -> spellfix1.so
105+
# But spellfix is in ext/misc/spellfix.c? Let's check if we have it in full source.
106+
if (Test-Path "ext/misc/spellfix.c") {
107+
Write-Host "Building spellfix.dll..."
108+
cl.exe /O2 /LD /I. ext/misc/spellfix.c sqlite3.lib /Fe:spellfix.dll
109+
if (Test-Path "spellfix.dll") {
110+
Copy-Item "spellfix.dll" -Destination $InstallLib
111+
}
112+
}
113+
114+
Write-Host "Extensions built."
115+
116+
# ----------------------------------------------------------------
117+
# Environment Setup
118+
# ----------------------------------------------------------------
119+
# SQLITE3_LIB_DIR tells build.rs where to find sqlite3.lib
120+
$env:SQLITE3_LIB_DIR = $InstallLib
121+
122+
# Add bin and lib to PATH so tests can find sqlite3.dll and extensions
123+
# Note: Windows checks PATH for DLLs.
124+
$env:PATH = "$InstallBin;$InstallLib;$env:PATH"
125+
126+
# Setting this to 0 tells the test suite to expect successful extension loading
127+
$env:DIESEL_TEST_SQLITE_EXTENSIONS_DISABLED = "0"
128+
129+
Set-Location $WorkDir
130+
131+
Write-Host "----------------------------------------------------------------"
132+
Write-Host "Running compilation check..."
133+
134+
# Clean to force relink
135+
cargo clean
136+
137+
Write-Host "Running tests against standard SQLite..."
138+
139+
# Debug: Print PATH
140+
# Write-Host "Path: $env:PATH"
141+
142+
try {
143+
# Run the specific test for extension loading
144+
cargo test --package diesel_tests --test integration_tests load_extension --features sqlite -- --nocapture
145+
Write-Host "----------------------------------------------------------------"
146+
Write-Host "SUCCESS: Diesel compiled and passed tests against SQLite with extension support."
147+
} catch {
148+
Write-Host "----------------------------------------------------------------"
149+
Write-Host "FAILURE: Tests failed or compilation failed."
150+
exit 1
151+
}

.github/workflows/ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,3 +619,40 @@ jobs:
619619
if: runner.os == 'Windows'
620620
shell: powershell
621621
run: .github/scripts/test_sqlite_no_extensions.ps1
622+
623+
sqlite_extension_build:
624+
name: SQLite Extension Build
625+
runs-on: ${{ matrix.os }}
626+
needs: [rustfmt_and_clippy]
627+
strategy:
628+
fail-fast: false
629+
matrix:
630+
os: [ubuntu-latest, windows-2025]
631+
steps:
632+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
633+
with:
634+
persist-credentials: false
635+
636+
- name: Cache cargo registry
637+
uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
638+
with:
639+
key: extension-sqlite-${{ matrix.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
640+
641+
- name: Install rust toolchain
642+
uses: dtolnay/rust-toolchain@f7ccc83f9ed1e5b9c81d8a67d7ad1a747e22a561 # master
643+
with:
644+
toolchain: stable
645+
646+
- name: Setup MSVC (Windows)
647+
if: runner.os == 'Windows'
648+
uses: ilammy/msvc-dev-cmd@v1
649+
650+
- name: Run Extension Build Test (Linux)
651+
if: runner.os == 'Linux'
652+
shell: bash
653+
run: .github/scripts/test_sqlite_with_extensions.sh
654+
655+
- name: Run Extension Build Test (Windows)
656+
if: runner.os == 'Windows'
657+
shell: powershell
658+
run: .github/scripts/test_sqlite_with_extensions.ps1

0 commit comments

Comments
 (0)