Uninify MSVC version that is used in provisioning

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>
This commit is contained in:
Alexey Edelev
2023-05-11 14:57:12 +02:00
parent fde60661d9
commit 84df93d37e
4 changed files with 27 additions and 58 deletions

View File

@@ -144,31 +144,7 @@ $env:Path = $oldPath
### MSVC
# Add cl to path if it is not already there
if (!(Get-Command cl.exe -ErrorAction SilentlyContinue)) {
$vswhere = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
$vc_component = "Microsoft.VisualStudio.Component.VC.CoreIde"
# We pick the oldest build tools we can find and use that to be compatible with it and any newer version:
# If MSVC has an ABI break this will stop working, and yet another build must be added.
$vs_location = (& $vswhere -nologo -products * -requires $vc_component -sort -format value -property installationPath | Select-Object -Last 1)
$vcvars_location = Join-Path $vs_location "VC\Auxiliary\Build\"
Push-Location $vcvars_location
# This snippet was stolen from https://stackoverflow.com/a/2124759
# Grabs all the environment variables that the script has set and assigns it
# to environment variables in PowerShell (calling batch files creates a
# cmd.exe instance which does not propagate environment variables)
cmd /c "vcvarsall.bat $env:PROCESSOR_ARCHITECTURE & set" |
ForEach-Object {
if ($_ -match "=") {
$v = $_.Split("=");
Set-Item -Force -Path "ENV:\$($v[0])" -Value "$($v[1])"
}
}
Pop-Location
}
EnterVSDevShell
build-install-grpc -CC "cl" -CXX "cl" -BuildType "Release" -Postfix "msvc"

View File

@@ -283,3 +283,26 @@ function GetVSPath {
return (& $VSWhere -nologo -latest -products * -requires $Component -property installationPath)
}
function EnterVSDevShell {
# Add cl to path if it is not already there.
if (Get-Command cl.exe -ErrorAction SilentlyContinue) {
return $true
}
$vsWere = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
$vcComponent = "Microsoft.VisualStudio.Component.VC.CoreIde"
# We pick the oldest build tools we can find and use that to be compatible with it and any newer version:
# If MSVC has an ABI break this will stop working, and yet another build must be added.
$VSPath = (& $vsWere -nologo -products * -requires $vcComponent -sort -format value -property installationPath | Select-Object -Last 1)
Write-Host "Enter VisualStudio developer shell"
try {
Import-Module "$VSPath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
Enter-VsDevShell -VsInstallPath $VSPath -DevCmdArguments "-arch=x64 -no_logo"
} catch {
Write-Host "Failed to enter VisualStudio DevShell"
return $false
}
return $true
}

View File

@@ -107,14 +107,8 @@ function InstallMingwFfmpeg {
function InstallMsvcFfmpeg {
$vsPath = GetVSPath
Write-Host "Enter VisualStudio developer shell"
try {
Import-Module "$vsPath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
Enter-VsDevShell -VsInstallPath $vsPath -DevCmdArguments "-arch=x64 -no_logo"
} catch {
Write-Host "Failed to enter VisualStudio DevShell"
$result = EnterVSDevShell
if (-Not $result) {
return $false
}

View File

@@ -104,31 +104,7 @@ $env:Path = $oldPath
### MSVC
# Add cl to path if it is not already there
if (!(Get-Command cl.exe -ErrorAction SilentlyContinue)) {
$vswhere = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
$vc_component = "Microsoft.VisualStudio.Component.VC.CoreIde"
# We pick the oldest build tools we can find and use that to be compatible with it and any newer version:
# If MSVC has an ABI break this will stop working, and yet another build must be added.
$vs_location = (& $vswhere -nologo -products * -requires $vc_component -sort -format value -property installationPath | Select-Object -Last 1)
$vcvars_location = Join-Path $vs_location "VC\Auxiliary\Build\"
Push-Location $vcvars_location
# This snippet was stolen from https://stackoverflow.com/a/2124759
# Grabs all the environment variables that the script has set and assigns it
# to environment variables in PowerShell (calling batch files creates a
# cmd.exe instance which does not propagate environment variables)
cmd /c "vcvarsall.bat $env:PROCESSOR_ARCHITECTURE & set" |
ForEach-Object {
if ($_ -match "=") {
$v = $_.Split("=");
Set-Item -Force -Path "ENV:\$($v[0])" -Value "$($v[1])"
}
}
Pop-Location
}
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")