From 30cc88aebd7fda2a4a5dc9849d3f1df0391fcc93 Mon Sep 17 00:00:00 2001 From: Sergey Nebolsin Date: Mon, 16 Oct 2023 18:44:31 +0300 Subject: [PATCH] fix: link sqlite3 statically on windows --- .github/workflows/build.yml | 24 +++++++++--------------- .gitignore | 16 +++++++++------- Vagrantfile | 11 +++++++++++ scripts/provision.ps1 | 13 +++++++++++++ scripts/sqlite3-static.ps1 | 30 ++++++++++++++++++++++++++++++ shard.lock | 2 +- 6 files changed, 73 insertions(+), 23 deletions(-) create mode 100644 Vagrantfile create mode 100644 scripts/provision.ps1 create mode 100644 scripts/sqlite3-static.ps1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 802e5b9c..b10db8f4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -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 diff --git a/.gitignore b/.gitignore index 3ded40f1..6436ca2f 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 00000000..1ccb7350 --- /dev/null +++ b/Vagrantfile @@ -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 diff --git a/scripts/provision.ps1 b/scripts/provision.ps1 new file mode 100644 index 00000000..fcebf795 --- /dev/null +++ b/scripts/provision.ps1 @@ -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" diff --git a/scripts/sqlite3-static.ps1 b/scripts/sqlite3-static.ps1 new file mode 100644 index 00000000..9693bf6c --- /dev/null +++ b/scripts/sqlite3-static.ps1 @@ -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,(?\d+\.\d+\.\d+),(?(?\d+)/sqlite-amalgamation-(?\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 diff --git a/shard.lock b/shard.lock index 4e69fbaf..2c28e30d 100644 --- a/shard.lock +++ b/shard.lock @@ -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