From b712f00b7e5fb20b0c6b95419d7ad7bfd7745df0 Mon Sep 17 00:00:00 2001 From: PIE Easy Start Date: Sun, 22 Aug 2021 16:04:59 +0000 Subject: [PATCH] Adding CI files --- ci/build.ps1 | 45 ----------------- ci/windows/CMakePresets.json | 67 +++++++++++++++++++++++++ ci/windows/Initialize-MSVC.ps1 | 73 ++++++++++++++++++++++++++++ ci/windows/Install-Prerequisites.ps1 | 12 +++++ 4 files changed, 152 insertions(+), 45 deletions(-) delete mode 100644 ci/build.ps1 create mode 100644 ci/windows/CMakePresets.json create mode 100644 ci/windows/Initialize-MSVC.ps1 create mode 100644 ci/windows/Install-Prerequisites.ps1 diff --git a/ci/build.ps1 b/ci/build.ps1 deleted file mode 100644 index 5b18a6a2df..0000000000 --- a/ci/build.ps1 +++ /dev/null @@ -1,45 +0,0 @@ -param( - [Parameter()] - [ValidateSet("Debug", "Release")] - [string] $BuildType = "Release" -) - -$SourceDirectory = (Convert-Path "$PSScriptRoot/../").Replace("\", "/") -$WorkingDirectory = "$pwd" -$BuildOutputDirectory = "$SourceDirectory/out/build/x64/$BuildType" -$InstallDirectory = "$SourceDirectory/out/install/x64/$BuildType" - -$commands = @() -if (!(Get-Command cl)) { - $commands += '"C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat"' -} - -$commands += @" -cmake.exe - -G "Ninja" - -S "$SourceDirectory" - -B "$WorkingDirectory" - -DCMAKE_BUILD_TYPE:STRING=$BuildType - -DCMAKE_INSTALL_PREFIX:PATH="$InstallDirectory" - -DDISABLE_PYTHON_BINDINGS=1 ` - 2>&1 -"@.Replace("`r`n", "") - -$commands += @" -cmake.exe --build $WorkingDirectory --config $BuildType -"@ - -$commands += @" -cmake.exe --install $WorkingDirectory -"@ -cmd /c ($commands -join " && ") - -Write-Host "Copying build output to $BuildOutputDirectory..." -mkdir $BuildOutputDirectory -Force | Out-Null -Get-ChildItem $WorkingDirectory -Recurse -Attributes !ReparsePoint | foreach { - $path = $_.FullName.Replace("$pwd", $BuildOutputDirectory) - $parent = Split-Path -Parent $path - mkdir $parent -Force | Out-Null - Copy-Item $_.FullName -Destination $path -Force -} -Write-Host "Done." \ No newline at end of file diff --git a/ci/windows/CMakePresets.json b/ci/windows/CMakePresets.json new file mode 100644 index 0000000000..515f9df339 --- /dev/null +++ b/ci/windows/CMakePresets.json @@ -0,0 +1,67 @@ +{ + "version": 2, + "configurePresets": [ + { + "name": "base", + "hidden": true, + "description": "Base preset", + "generator": "Ninja", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "cacheVariables": { + "CMAKE_C_COMPILER": "cl.exe", + "CMAKE_CXX_COMPILER": "cl.exe" + }, + "architecture": { + "value": "x64", + "strategy": "external" + }, + "toolset": { + "value": "host=x64,version=16.11", + "strategy": "external" + } + }, + { + "name": "x64-Debug", + "inherits": "base", + "displayName": "x64 Debug", + "description": "Sets debug build type and x64 arch", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "x64-Release", + "displayName": "x64 Release", + "description": "Sets release build type", + "inherits": "x64-Debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + } + ], + "buildPresets": [ + { + "name": "default-debug-build", + "displayName": "Debug Build", + "configurePreset": "x64-Debug" + }, + { + "name": "verbose-debug-build", + "displayName": "Verbose Debug Build", + "configurePreset": "x64-Debug", + "nativeToolOptions": [ "-v" ] + }, + { + "name": "default-release-build", + "displayName": "Release Build", + "configurePreset": "x64-Release" + }, + { + "name": "verbose-release-build", + "displayName": "Verbose Release Build", + "configurePreset": "x64-Release", + "nativeToolOptions": [ "-v" ] + } + ], + "testPresets": [] +} \ No newline at end of file diff --git a/ci/windows/Initialize-MSVC.ps1 b/ci/windows/Initialize-MSVC.ps1 new file mode 100644 index 0000000000..28b4a9611e --- /dev/null +++ b/ci/windows/Initialize-MSVC.ps1 @@ -0,0 +1,73 @@ +param ( + [string] $Architecture='x64' +) + +if (!(Get-Module VSSetup)) +{ + Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force + Install-Module VSSetup -Force +} + +function Get-VSInstallPath { + [CmdletBinding()] + param ( + [Parameter(Mandatory=$true)] + [int] $MaxVersion + ) + $latest = Get-VSSetupInstance ` + | where { $_.InstallationVersion.Major -le $MaxVersion } ` + | Select-VSSetupInstance -Require Microsoft.VisualStudio.VC.CMake -Latest + + if (!$latest) + { + throw [System.IO.FileNotFoundException]::new("No Visual Studio installation found that matches max version: $MaxVersion!") + } + return $latest.InstallationPath +} + +function Where-Program { + [CmdletBinding()] + param ( + [Parameter(Mandatory=$true,ValueFromPipeline=$true)] + [string] $Program + ) + process + { + return Get-Command $Program | select Source -ExpandProperty source | Split-Path -Parent + } +} + +function Persist-EnvironmentVariable { + [CmdletBinding()] + param ( + [Parameter(Mandatory=$true,ValueFromPipeline=$true)] + [string] $Name + ) + process + { + $value=[System.Environment]::GetEnvironmentVariable($Name) + [System.Environment]::SetEnvironmentVariable($Name, $value, [System.EnvironmentVariableTarget]::Machine) + } +} + +$VsInstallationPath = Get-VSInstallPath -MaxVersion 16 +Write-Host "Found VS installation: $VsInstallationPath" + +[array] $originalEnv = [System.Environment]::GetEnvironmentVariables().Keys + +Import-Module "$VsInstallationPath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" +Enter-VsDevShell -VsInstallPath $VsInstallationPath -SkipAutomaticLocation -DevCmdArguments "-arch=$Architecture" + +$Programs = 'cmake', 'Ninja', 'cl' +$programsPath = $Programs | Where-Program +Write-Host "Found paths for $($Programs -join ', '): $($programsPath -join ', ')" + +$newPath = "$($programsPath -join ';');${env:Path}" +Write-Host "Persisting new PATH: $newPath" +[System.Environment]::SetEnvironmentVariable('PATH', $newPath, [System.EnvironmentVariableTarget]::Machine) + +[array] $vsEnv = [System.Environment]::GetEnvironmentVariables().Keys +[array] $newEnv = $vsEnv | where { $_ -notin $originalEnv -and $_ -ne 'PATH' } + +Write-Host "Persisting new environment variables: $($newEnv -join ', ')" +$newEnv | Persist-EnvironmentVariable diff --git a/ci/windows/Install-Prerequisites.ps1 b/ci/windows/Install-Prerequisites.ps1 new file mode 100644 index 0000000000..2d15cb9b35 --- /dev/null +++ b/ci/windows/Install-Prerequisites.ps1 @@ -0,0 +1,12 @@ +[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 +iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) + +choco install conan -y +choco install sed -y +choco install winflexbison -y +if (!(Get-Command python)) +{ + choco install python -y +} + +[System.Environment]::SetEnvironmentVariable('PATH', "C:\Program Files\Git\bin;${env:PATH}", [System.EnvironmentVariableTarget]::Machine) \ No newline at end of file