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 05f7104
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 24 deletions.
28 changes: 12 additions & 16 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,11 +23,20 @@ jobs:
with:
crystal: 1.9

- run: shards install --production
- name: Build SQLite3 static library
run: "scripts/sqlite3-static.ps1"

- name: Install shards dependencies
run: shards install --production

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

- name: Prepare distribution archive
run: |
cd dist
$vsbase = vswhere.exe -products * -property installationPath
& "$vsbase\VC\Tools\MSVC\14.37.32822\bin\HostX64\x64\dumpbin.exe" /dependents coveralls.exe
tar -acf coveralls-windows.zip coveralls.exe
- name: Upload 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/
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,19 @@ Run specs:
make test
```

### Setup Windows in Vagrant

```bash
vagrant up

# to re-run provision script
vagrant provision

# to access Windows VM
vagrant ssh
# type powershell<enter>
```

### Deployment

Cutting new releases.
Expand Down
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
15 changes: 15 additions & 0 deletions scripts/provision.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Set-ExecutionPolicy Bypass -Scope LocalMachine
$ProgressPreference = "SilentlyContinue"

Write-Output "Installing the Scoop package manager..."
irm get.scoop.sh -outfile 'install-scoop.ps1'
& "install-scoop.ps1" -RunAsAdmin
rm "install-scoop.ps1"

Write-Output "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"
29 changes: 29 additions & 0 deletions scripts/sqlite3-static.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Write-Output "Configuring Build Tools..."
$vsbase = vswhere.exe -products * -property installationPath

Write-Output "Resolving SQLite3 distribution..."
$sqlite_info = Invoke-WebRequest -Uri '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-Output "Downloading SQLite sources: $sqlite_sources"
mkdir /sqlite
pushd /sqlite
Invoke-WebRequest -Uri $sqlite_sources -OutFile sqlite.zip -UseBasicParsing
Expand-Archive -Path sqlite.zip -DestinationPath .
popd

Write-Output "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-Output "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-Output "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 05f7104

Please sign in to comment.