mirror of
git://code.qt.io/qt/qt5.git
synced 2026-01-09 00:16:55 +08:00
We pick the oldest build tools we can find because there is lower
chance that the produced binaries will be incomaptible with the newer
version of MSVC.
With the current provisioning design we also cannot change the MSVC
version for the each package on demand. Once Enter-VsDevShell is called
it litters the powershell environment and blocks the use of
Enter-VsDevShell second time. It could be better to run each .ps1 file
in own instance of powershell to avoid mixing build environment.
Amends f58afd5476
Pick-to: 6.5
Change-Id: Ie752cfc8b69ed985e61ec16209007dd586611866
Reviewed-by: Samuel Mira <samuel.mira@qt.io>
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
117 lines
4.1 KiB
PowerShell
117 lines
4.1 KiB
PowerShell
# Copyright (C) 2022 The Qt Company Ltd.
|
|
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
|
|
|
. "$PSScriptRoot\helpers.ps1"
|
|
|
|
# Here we build protobuf libraries for MinGW and MSVC.
|
|
# Since it's a c++ library we need both msvc and mingw because they mangle symbols differently.
|
|
# For MSVC it builds with both debug and release configurations because of the visual c++ runtime.
|
|
# For MinGW we only need one, so we only build with release.
|
|
# The function below takes care of the common part of building - invoking cmake,
|
|
# calling ninja and installing it to a directory which we set an environment variable to.
|
|
# Because we have two compilers we also have two env. vars. and then each
|
|
# config in CI has the Protobuf_ROOT set to the appropriate one.
|
|
function build-install-protobuf {
|
|
param(
|
|
[string]$CC,
|
|
[string]$CXX,
|
|
[string]$BuildType,
|
|
[string]$Postfix, # Used for install-path and the environment variable name
|
|
[string[]]$ExtraArguments = @()
|
|
)
|
|
$installPrefix = "C:\Utils\protobuf"
|
|
$installPath = "${installPrefix}-$Postfix"
|
|
Write-Output "Configuring and building protobuf for $CXX"
|
|
$oldCC = $env:CC
|
|
$oldCXX = $env:CXX
|
|
$env:CC = $CC
|
|
$env:CXX = $CXX
|
|
mkdir build
|
|
Push-Location build
|
|
cmake .. -G"Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="$BuildType" -DCMAKE_INSTALL_PREFIX="$installPath" -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_WITH_ZLIB=OFF $ExtraArguments
|
|
# ninja install:all # This is broken and does not work
|
|
foreach ($config in $BuildType.split(";")) {
|
|
ninja -f "build-$config.ninja" install
|
|
}
|
|
$env:CC = $oldCC
|
|
$env:CXX = $oldCXX
|
|
Set-EnvironmentVariable "Protobuf_ROOT_$Postfix" "$InstallPath"
|
|
Pop-Location
|
|
Remove build
|
|
}
|
|
|
|
function Find-Tool {
|
|
param(
|
|
[string]$Name,
|
|
[string]$Path
|
|
)
|
|
# Is tool missing from path?
|
|
if (!(Get-Command $Name -ErrorAction SilentlyContinue)) {
|
|
# Is tool in the $Path directory?
|
|
if (Test-Path "$Path\$Name") {
|
|
$env:Path += ";$Path"
|
|
}
|
|
else {
|
|
throw "Cannot find $Name in path or $Name in $Name, something is configured wrong"
|
|
}
|
|
}
|
|
}
|
|
# This script is fairly late in provisioning so both of these should be present!
|
|
Find-Tool -Name "cmake.exe" -Path "C:\CMake\bin"
|
|
Find-Tool -Name "ninja.exe" -Path "C:\Utils\Ninja"
|
|
|
|
$version = "21.9"
|
|
$sha1 = "3226a0e49d048759b702ae524da79387c59f05cc"
|
|
$internalUrl = "http://ci-files01-hki.intra.qt.io/input/protobuf/protobuf-all-$version.zip"
|
|
$externalUrl = "https://github.com/protocolbuffers/protobuf/releases/download/v$version/protobuf-all-$version.zip"
|
|
|
|
$targetDir = "$env:HOMEDRIVE\$env:HOMEPATH\protobuf-$version"
|
|
$targetFile = "$targetDir.zip"
|
|
Download $externalUrl $internalUrl $targetFile
|
|
Verify-Checksum $targetFile $sha1
|
|
Extract-7Zip $targetFile (Join-Path $env:HOMEDRIVE $env:HOMEPATH)
|
|
Remove $targetFile
|
|
|
|
|
|
# cd into the cmake directory where the CMakeLists.txt file is located
|
|
# then we build in a build\ subfolder there for simplicity's sake
|
|
Push-Location $targetDir
|
|
|
|
### MinGW
|
|
|
|
# Check if mingw is where we expect it to be and add it to path:
|
|
$mingwPath = "C:\MINGW1120\mingw64\bin"
|
|
if (!(Test-Path $mingwPath)) {
|
|
throw "Cannot find mingw in $mingwPath, something is configured wrong"
|
|
}
|
|
|
|
$oldPath = $env:Path
|
|
$env:Path = "$mingwPath;$env:Path"
|
|
build-install-protobuf -CC "gcc" -CXX "g++" -BuildType "Release" -Postfix "mingw"
|
|
$env:Path = $oldPath
|
|
|
|
### LLVM MinGW
|
|
|
|
$llvmMingwPath = "C:\llvm-mingw"
|
|
if (!(Test-Path $llvmMingwPath)) {
|
|
throw "Cannot find llvm-mingw in $llvmMingwPath, something is configured wrong"
|
|
}
|
|
|
|
$oldPath = $env:Path
|
|
$env:Path = "$llvmMingwPath\bin;$env:Path"
|
|
build-install-protobuf -CC "clang" -CXX "clang++" -BuildType "Release" -Postfix "llvm_mingw"
|
|
$env:Path = $oldPath
|
|
|
|
### MSVC
|
|
|
|
EnterVSDevShell
|
|
|
|
# We pass along an extra argument to stop protobuf linking with the static runtime
|
|
build-install-protobuf -CC "cl" -CXX "cl" -BuildType "Release" -Postfix "msvc" -ExtraArguments @("-Dprotobuf_MSVC_STATIC_RUNTIME=OFF")
|
|
|
|
$env:Path = $oldPath
|
|
Pop-Location
|
|
Remove $targetDir
|
|
|
|
Write-Output "Protobuf = $version" >> ~/versions.txt
|