From 7bce13eb2c6cbf861c5015f6e9d94220fc6ff8ef Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Tue, 20 Oct 2020 16:39:19 +0200 Subject: [PATCH 1/5] Update Windows build scripts for Visual Studio 2019 $env:CMAKE_GENERATOR_PLATFORM is only used in configure-dev.ps1 but now is also required in configure.ps1 to allow the build pipeline to be upgraded to Visual Studio 2019. Additionally bump the versions in paths for Boost and OpenSSL. --- tools/win32/configure.ps1 | 13 ++++++++----- tools/win32/load-vsenv.ps1 | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/win32/configure.ps1 b/tools/win32/configure.ps1 index 63305e5dc..7afd922ae 100644 --- a/tools/win32/configure.ps1 +++ b/tools/win32/configure.ps1 @@ -17,16 +17,19 @@ if (-not ($env:PATH -contains $env:CMAKE_PATH)) { $env:PATH = $env:CMAKE_PATH + ';' + $env:PATH } if (-not (Test-Path env:CMAKE_GENERATOR)) { - $env:CMAKE_GENERATOR = 'Visual Studio 15 2017 Win64' + $env:CMAKE_GENERATOR = 'Visual Studio 16 2019' +} +if (-not (Test-Path env:CMAKE_GENERATOR_PLATFORM)) { + $env:CMAKE_GENERATOR_PLATFORM = 'x64' } if (-not (Test-Path env:OPENSSL_ROOT_DIR)) { - $env:OPENSSL_ROOT_DIR = 'c:\local\OpenSSL_1_1_1b-Win64' + $env:OPENSSL_ROOT_DIR = 'c:\local\OpenSSL_1_1_1h-Win64' } if (-not (Test-Path env:BOOST_ROOT)) { - $env:BOOST_ROOT = 'c:\local\boost_1_69_0-Win64' + $env:BOOST_ROOT = 'c:\local\boost_1_71_0-Win64' } if (-not (Test-Path env:BOOST_LIBRARYDIR)) { - $env:BOOST_LIBRARYDIR = 'c:\local\boost_1_69_0-Win64\lib64-msvc-14.1' + $env:BOOST_LIBRARYDIR = 'c:\local\boost_1_71_0-Win64\lib64-msvc-14.2' } if (-not (Test-Path env:FLEX_BINARY)) { $env:FLEX_BINARY = 'C:\ProgramData\chocolatey\bin\win_flex.exe' @@ -48,7 +51,7 @@ if (Test-Path CMakeCache.txt) { & cmake.exe "$sourcePath" ` -DCMAKE_BUILD_TYPE="$env:CMAKE_BUILD_TYPE" ` - -G "$env:CMAKE_GENERATOR" -DCPACK_GENERATOR=WIX ` + -G "$env:CMAKE_GENERATOR" -A "$env:CMAKE_GENERATOR_PLATFORM" -DCPACK_GENERATOR=WIX ` -DICINGA2_WITH_MYSQL=OFF -DICINGA2_WITH_PGSQL=OFF ` -DICINGA2_WITH_LIVESTATUS=OFF -DICINGA2_WITH_COMPAT=OFF ` -DOPENSSL_ROOT_DIR="$env:OPENSSL_ROOT_DIR" ` diff --git a/tools/win32/load-vsenv.ps1 b/tools/win32/load-vsenv.ps1 index 86fcf4fba..984a4f133 100644 --- a/tools/win32/load-vsenv.ps1 +++ b/tools/win32/load-vsenv.ps1 @@ -18,7 +18,7 @@ if (-not (Test-Path $BUILD)) { if (Test-Path env:VS_INSTALL_PATH) { $VSBASE = $env:VS_INSTALL_PATH } else { - $VSBASE = "C:\Program Files (x86)\Microsoft Visual Studio\2017" + $VSBASE = "C:\Program Files (x86)\Microsoft Visual Studio\2019" } if (Test-Path env:BITS) { From e702fcff82894a6ccad5b0d7bd525d72662ddaad Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Wed, 21 Oct 2020 10:53:59 +0200 Subject: [PATCH 2/5] Update AppVeyor Config to use Visual Studio 2019 --- appveyor.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 92dfe7bef..cd349bb65 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,16 +1,17 @@ --- version: 2.11.0.dev.{build} -os: Visual Studio 2017 +os: Visual Studio 2019 platform: x64 environment: BITS: 64 CMAKE_BUILD_TYPE: Debug - CMAKE_GENERATOR: "Visual Studio 15 2017 Win64" + CMAKE_GENERATOR: "Visual Studio 16 2019" + CMAKE_GENERATOR_PLATFORM: x64 # https://www.appveyor.com/docs/windows-images-software/#boost - BOOST_ROOT: 'C:\Libraries\boost_1_67_0' - BOOST_LIBRARYDIR: 'C:\Libraries\boost_1_67_0\lib64-msvc-14.1' + BOOST_ROOT: 'C:\Libraries\boost_1_71_0' + BOOST_LIBRARYDIR: 'C:\Libraries\boost_1_71_0\lib64-msvc-14.2' # https://www.appveyor.com/docs/windows-images-software/#tools OPENSSL_ROOT_DIR: 'C:\OpenSSL-v111-Win64' BISON_BINARY: 'C:\ProgramData\chocolatey\lib\winflexbison3\tools\win_bison.exe' From 66fbfc674668476e03f80caf4a713caa8434a5c4 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 2 Nov 2020 13:53:07 +0100 Subject: [PATCH 3/5] Docs: provide shorter and batch-ier instructions on how to setup a Windows dev env --- doc/21-development.md | 36 ++++++++++++++++++++ doc/win-dev.ps1 | 77 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 doc/win-dev.ps1 diff --git a/doc/21-development.md b/doc/21-development.md index ff24971a3..7872a3b48 100644 --- a/doc/21-development.md +++ b/doc/21-development.md @@ -1700,6 +1700,42 @@ The required steps are described in [this script](https://github.com/dnsmichi/do The following sections explain how to setup the required build tools and how to run and debug the code. +#### TL;DR + +If you're going to setup a dev environment on a fresh Windows machine +and don't care for the details, + +1. ensure there are 35 GB free space on C: +2. run the following in an administrative Powershell: + 1. `Enable-WindowsOptionalFeature -FeatureName "NetFx3" -Online` + (reboot when asked!) + 2. `powershell -NoProfile -ExecutionPolicy Bypass -Command "Invoke-Expression (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Icinga/icinga2/master/doc/win-dev.ps1')"` + (will take some time) + +This installs everything needed for cloning and building Icinga 2 +on the command line (Powershell) as follows: + +(Don't forget to open a new Powershell window +to be able to use the newly installed Git.) + +``` +git clone https://github.com/Icinga/icinga2.git +cd .\icinga2\ +mkdir build +cd .\build\ + +& "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" ` + -DBoost_INCLUDE_DIR=C:\local\boost_1_71_0-Win64 ` + -DBISON_EXECUTABLE=C:\ProgramData\chocolatey\lib\winflexbison3\tools\win_bison.exe ` + -DFLEX_EXECUTABLE=C:\ProgramData\chocolatey\lib\winflexbison3\tools\win_flex.exe ` + -DICINGA2_WITH_MYSQL=OFF -DICINGA2_WITH_PGSQL=OFF .. + +& "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe" .\icinga2.sln +``` + +Building icinga2.sln via Visual Studio itself seems to require a reboot +after installing the build tools and building once via command line. + #### Chocolatey Open an administrative command prompt (Win key, type “cmd”, right-click and “run as administrator”) and paste the following instructions: diff --git a/doc/win-dev.ps1 b/doc/win-dev.ps1 new file mode 100644 index 000000000..37d6323b8 --- /dev/null +++ b/doc/win-dev.ps1 @@ -0,0 +1,77 @@ +Set-PSDebug -Trace 1 + +Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' +$PSDefaultParameterValues['*:ErrorAction'] = 'Stop' + +function ThrowOnNativeFailure { + if (-not $?) { + throw 'Native failure' + } +} + + +$VsVersion = 2019 +$MsvcVersion = '14.2' +$BoostVersion = @(1, 71, 0) +$OpensslVersion = '1_1_1h' + + +function Install-Exe { + param ( + [string]$Url, + [string]$Dir + ) + + $TempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid().Guid) + $ExeFile = Join-Path $TempDir inst.exe + + New-Item -ItemType Directory -Path $TempDir + + for ($trial = 1;; ++$trial) { + try { + Invoke-WebRequest -Uri $Url -OutFile $ExeFile -UseBasicParsing + } catch { + if ($trial -ge 2) { + throw + } + + continue + } + + break + } + + Start-Process -Wait -FilePath $ExeFile -ArgumentList @('/VERYSILENT', '/INSTALL', '/PASSIVE', '/NORESTART', "/DIR=${Dir}") + Remove-Item -Recurse -Path $TempDir +} + + +Invoke-Expression (New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1') + +$RegEnv = 'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' +$ChocoPath = ";$(Join-Path $Env:AllUsersProfile chocolatey\bin)" + +Set-ItemProperty -Path $RegEnv -Name Path -Value ((Get-ItemProperty -Path $RegEnv -Name Path).Path + $ChocoPath) +$Env:Path += $ChocoPath + + +choco install -y "visualstudio${VsVersion}community" +choco install -y "visualstudio${VsVersion}-workload-netcoretools" +choco install -y "visualstudio${VsVersion}-workload-vctools" +choco install -y "visualstudio${VsVersion}-workload-manageddesktop" +choco install -y "visualstudio${VsVersion}-workload-nativedesktop" +choco install -y "visualstudio${VsVersion}-workload-universal" +choco install -y "visualstudio${VsVersion}buildtools" + + +choco install -y git +choco install -y cmake +choco install -y winflexbison3 +choco install -y windows-sdk-8.1 +choco install -y wixtoolset + + +Install-Exe -Url "https://packages.icinga.com/windows/dependencies/boost_$($BoostVersion -join '_')-msvc-${MsvcVersion}-64.exe" -Dir "C:\local\boost_$($BoostVersion -join '_')-Win64" + +Install-Exe -Url "https://packages.icinga.com/windows/dependencies/Win64OpenSSL-${OpensslVersion}.exe" -Dir "C:\local\OpenSSL_${OpensslVersion}-Win64" From 28a9ee2b803eb0ba886438ac81f02ac6f055d245 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 26 Oct 2020 17:54:24 +0100 Subject: [PATCH 4/5] Don't use Appveyor --- appveyor.yml | 64 ---------------------------------------------------- 1 file changed, 64 deletions(-) delete mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index cd349bb65..000000000 --- a/appveyor.yml +++ /dev/null @@ -1,64 +0,0 @@ ---- -version: 2.11.0.dev.{build} - -os: Visual Studio 2019 -platform: x64 - -environment: - BITS: 64 - CMAKE_BUILD_TYPE: Debug - CMAKE_GENERATOR: "Visual Studio 16 2019" - CMAKE_GENERATOR_PLATFORM: x64 - # https://www.appveyor.com/docs/windows-images-software/#boost - BOOST_ROOT: 'C:\Libraries\boost_1_71_0' - BOOST_LIBRARYDIR: 'C:\Libraries\boost_1_71_0\lib64-msvc-14.2' - # https://www.appveyor.com/docs/windows-images-software/#tools - OPENSSL_ROOT_DIR: 'C:\OpenSSL-v111-Win64' - BISON_BINARY: 'C:\ProgramData\chocolatey\lib\winflexbison3\tools\win_bison.exe' - FLEX_BINARY: 'C:\ProgramData\chocolatey\lib\winflexbison3\tools\win_flex.exe' - -branches: - only: - - master - -cache: -- build -> appveyor.yml -- C:\ProgramData\chocolatey\lib\winflexbison3 - -install: -- ps: | - if (-not (Test-Path "C:\ProgramData\chocolatey\lib\winflexbison3")) { - & choco install winflexbison3 - if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } - } - -# why that env handling, see -# https://help.appveyor.com/discussions/questions/18777-how-to-use-vcvars64bat-from-powershell#comment_44999171 -before_build: -- ps: | - & .\tools\win32\load-vsenv.ps1 - - & powershell.exe .\tools\win32\configure.ps1 - if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } - - del build\Icinga*.msi - -build_script: -- ps: | - & powershell.exe .\tools\win32\build.ps1 - if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } - -test_script: -- ps: | - & powershell.exe .\tools\win32\test.ps1 - if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } - -# Disable until we really need them -# https://github.com/Icinga/icinga2/issues/6106 -# https://help.appveyor.com/discussions/problems/10253-maximum-allowed-artifact-storage-size-of-1000-mb-will-be-exceeded -#artifacts: -#- path: build/Icinga*.msi -#- path: build/choco/*.nupkg -#- path: build/Test.xml - -deploy: off From bea9d22c52b37e961a6e4c79ba4c6a377e5327a2 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 10 Nov 2020 18:34:00 +0100 Subject: [PATCH 5/5] GitHub actions: build Windows --- .github/workflows/packages.yml | 38 ++++++++++++++++++++++++++++++++++ doc/win-dev.ps1 | 26 ++++++++++++++++------- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml index 27bc5fc58..3bed4ec48 100644 --- a/.github/workflows/packages.yml +++ b/.github/workflows/packages.yml @@ -308,3 +308,41 @@ jobs: # -e ICINGA_BUILD_DEB_DEFAULT_ARCH=armhf \ # registry.icinga.com/build-docker/raspbian/${{ matrix.codename }} \ # icinga-build-test + windows: + name: Windows + + strategy: + fail-fast: false + matrix: + bits: [32, 64] + + runs-on: windows-latest + + env: + BITS: '${{ matrix.bits }}' + ICINGA_BUILD_TYPE: snapshot + UPSTREAM_GIT_URL: file://D:/a/icinga2/icinga2/.git + + steps: + - name: Checkout HEAD + uses: actions/checkout@v1 + + - name: windows-icinga2 + run: | + git clone https://git.icinga.com/packaging/windows-icinga2.git + + - name: Build tools + run: | + & .\doc\win-dev.ps1 + + - name: Source + run: | + git checkout -B master + cd windows-icinga2 + & .\source.ps1 + + - name: Binary + working-directory: windows-icinga2 + run: | + New-Item -ItemType Directory -Path 'C:\Program Files\Icinga2\WillBeRemoved' -ErrorAction SilentlyContinue + & .\build.ps1 diff --git a/doc/win-dev.ps1 b/doc/win-dev.ps1 index 37d6323b8..42a48d4f8 100644 --- a/doc/win-dev.ps1 +++ b/doc/win-dev.ps1 @@ -16,6 +16,14 @@ $MsvcVersion = '14.2' $BoostVersion = @(1, 71, 0) $OpensslVersion = '1_1_1h' +switch ($Env:BITS) { + 32 { } + 64 { } + default { + $Env:BITS = 64 + } +} + function Install-Exe { param ( @@ -47,13 +55,17 @@ function Install-Exe { } -Invoke-Expression (New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1') +try { + Get-Command choco +} catch { + Invoke-Expression (New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1') -$RegEnv = 'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -$ChocoPath = ";$(Join-Path $Env:AllUsersProfile chocolatey\bin)" + $RegEnv = 'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' + $ChocoPath = ";$(Join-Path $Env:AllUsersProfile chocolatey\bin)" -Set-ItemProperty -Path $RegEnv -Name Path -Value ((Get-ItemProperty -Path $RegEnv -Name Path).Path + $ChocoPath) -$Env:Path += $ChocoPath + Set-ItemProperty -Path $RegEnv -Name Path -Value ((Get-ItemProperty -Path $RegEnv -Name Path).Path + $ChocoPath) + $Env:Path += $ChocoPath +} choco install -y "visualstudio${VsVersion}community" @@ -72,6 +84,6 @@ choco install -y windows-sdk-8.1 choco install -y wixtoolset -Install-Exe -Url "https://packages.icinga.com/windows/dependencies/boost_$($BoostVersion -join '_')-msvc-${MsvcVersion}-64.exe" -Dir "C:\local\boost_$($BoostVersion -join '_')-Win64" +Install-Exe -Url "https://packages.icinga.com/windows/dependencies/boost_$($BoostVersion -join '_')-msvc-${MsvcVersion}-${Env:BITS}.exe" -Dir "C:\local\boost_$($BoostVersion -join '_')-Win${Env:BITS}" -Install-Exe -Url "https://packages.icinga.com/windows/dependencies/Win64OpenSSL-${OpensslVersion}.exe" -Dir "C:\local\OpenSSL_${OpensslVersion}-Win64" +Install-Exe -Url "https://packages.icinga.com/windows/dependencies/Win${Env:BITS}OpenSSL-${OpensslVersion}.exe" -Dir "C:\local\OpenSSL_${OpensslVersion}-Win${Env:BITS}"