|
| 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 | +} |
0 commit comments