Skip to content

Commit

Permalink
fix: link sqlite3 statically on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
nebolsin committed Oct 16, 2023
1 parent 31f2d88 commit 30cc88a
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 23 deletions.
24 changes: 9 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ jobs:
build-windows:
runs-on: windows-2022
steps:
# If this step breaks, try inspecting MSVC directory and consider changing appropriate paths.
#
# ls 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\'
#
# Since windows runner can be updated the version can change in future releases.
- name: Install SQLite3 + generate sqlite3.lib
run: |
choco install sqlite -y
cd C:\ProgramData\chocolatey\lib\SQLite\tools
ls 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\'
& 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\bin\Hostx64\x64\lib.exe' /DEF:sqlite3.def /OUT:sqlite3.lib /MACHINE:x64
cp sqlite3.lib 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\lib\x64'
- name: Checkout code
uses: actions/checkout@v3

Expand All @@ -36,9 +23,16 @@ jobs:
with:
crystal: 1.9

- run: shards install --production
- name: Build SQLite3 static library
run: |
& "scripts/sqlite3-static.ps1"
- name: Install sharts dependencies
run: shards install --production

- name: Build coverage reporter CLI
run: crystal build src\cli.cr -o dist\coveralls --release --static --no-debug --progress

- run: crystal build src\cli.cr -o dist\coveralls --release --static --no-debug --progress
- run: |
cd dist
tar -acf coveralls-windows.zip coveralls.exe
Expand Down
16 changes: 9 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/docs/
/lib/
/bin/
/.shards/
/.crystal/
*.dwarf
.idea
/dist
.DS_Store
/coverage/
.coveralls.yml
/.crystal/
/.shards/
/.vagrant/
/bin/
/coverage/
/dist
/docs/
/insecure_private_keys
/lib/
11 changes: 11 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "gusztavvargadr/windows-server-2022-standard-core"
config.vm.communicator = "winssh"
config.vm.guest = :windows
config.ssh.shell = "powershell"
config.vm.synced_folder ".", "c:/vagrant"
config.vm.provision "shell", path: "scripts/provision.ps1"
end
13 changes: 13 additions & 0 deletions scripts/provision.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Set-ExecutionPolicy Bypass -Scope LocalMachine
$ProgressPreference = "SilentlyContinue"

Write-Host "Installing the Scoop package manager..."
iex "& {$(irm get.scoop.sh)} -RunAsAdmin"

Write-Host "Installing Crystal & dev tools ..."
scoop install git
scoop bucket add crystal-preview "https://github.com/neatorobito/scoop-crystal"
scoop install vs_2022_cpp_build_tools
scoop install crystal

& "scripts/sqlite3-static.ps1"
30 changes: 30 additions & 0 deletions scripts/sqlite3-static.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
scoop install vswhere

Write-Host "Configuring Build Tools..."
$vsbase = vswhere.exe -products * -property installationPath

Write-Host "Downloading SQLite sources..."
mkdir /sqlite
pushd /sqlite
$sqlite_info = curl 'https://www.sqlite.org/download.html' -UseBasicParsing
$sqlite_info -match 'PRODUCT,(?<version>\d+\.\d+\.\d+),(?<url>(?<year>\d+)/sqlite-amalgamation-(?<rev>\d+).zip)'
$sqlite_sources = "https://www.sqlite.org/" + $Matches.url
$sqlite_dir = "/sqlite/sqlite-amalgamation-" + $Matches.rev
Write-Host "Found URL: $sqlite_sources"
curl $sqlite_sources -OutFile:sqlite.zip -UseBasicParsing
Expand-Archive -Path sqlite.zip -DestinationPath .
popd

Write-Host "Building SQLite3 static lib..."
pushd $sqlite_dir
$cmdline = '"' + $vsbase + '\VC\Auxiliary\Build\vcvars64.bat" && cl /c /EHsc sqlite3.c && lib sqlite3.obj'
& "cmd" "/C" "$cmdline"
popd

Write-Host "Copying SQLite3 static lib to $(crystal env CRYSTAL_LIBRARY_PATH)..."
$src = "$sqlite_dir/sqlite3.lib"
$dest = (crystal env CRYSTAL_LIBRARY_PATH) + '/sqlite3-static.lib'
cp "$src" "$dest"

Write-Host "Cleaninig up SQLite3 sources..."
rm -r /sqlite
2 changes: 1 addition & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.0
shards:
ameba:
git: https://github.com/crystal-ameba/ameba.git
version: 1.5.0+git.commit.18d193bd0831db721adeaed41655dd40cad3c0ae
version: 1.5.0+git.commit.7174e81a13f3cb3b3d317e236616149b4360de18

crystal-kcov:
git: https://github.com/vici37/crystal-kcov.git
Expand Down

0 comments on commit 30cc88a

Please sign in to comment.