Skip to content

Commit

Permalink
CI: Download vcredist 120+140 instead of using the local MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
MatejKafka committed Jan 14, 2025
1 parent ac73a2e commit 4319fb8
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 7 deletions.
24 changes: 21 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ env:

# versions of dependencies needed for building and bootstrapping Pog
# these should be updated periodically with the following command:
# ```
# "VERSION_DOTNET: `"$(dotnet --version)`""
# "VERSION_PESTER: `"$((Find-Module Pester).Version)`""
# "VERSION_WIX_DARK: `"$((Find-Pog dark@ScoopInstaller).Version)`""
# Find-Pog ILRepack, UPX, 7zip | % {"VERSION_$($_.PackageName.ToUpperInvariant()): `"$($_.Version)`""}
# ```
VERSION_DOTNET: "9.0.101"
VERSION_PESTER: "5.6.1"
VERSION_PESTER: "5.7.1"
VERSION_WIX_DARK: "3.14"
VERSION_ILREPACK: "2.0.29"
VERSION_UPX: "4.2.3"
VERSION_7ZIP: "24.08"
Expand Down Expand Up @@ -49,6 +53,14 @@ jobs:
$ModuleDir = "$(Split-Path $PROFILE)\Modules"
Expand-Archive D:\pester.nupkg "$ModuleDir\Pester"
# needed to unpack vcredist packages
- name: Install WiX dark.exe
shell: pwsh
run: |
iwr "https://raw.githubusercontent.com/ScoopInstaller/Binary/master/dark/dark-$($env:VERSION_WIX_DARK).zip" -OutFile D:\dark.zip
Expand-Archive D:\dark.zip D:\dark
Add-Content $env:GITHUB_PATH D:\dark
# needed to build Pog.dll
- name: Install ILRepack
shell: pwsh
Expand Down Expand Up @@ -84,6 +96,7 @@ jobs:
run: |
[pscustomobject]@{Name = "dotnet.exe"; Version = dotnet.exe --version; Source = (gcm dotnet.exe).Source}
gmo Pester -ListAvailable | select -First 1
gcm dark.exe
gcm ilrepack.exe
gcm upx.exe
gcm ..\7zip\app\7z.exe
Expand All @@ -103,10 +116,15 @@ jobs:
cmake --build ./Pog.Shim/cmake-build-release --config Release
gi ./PogShimTemplate.exe
- name: Copy VC Redistributable
- name: Download VC Redistributable
shell: pwsh
run: |
& "./app/Pog/_scripts/update vc redist.ps1"
./app/Pog/_scripts/vcredist-download.ps1 -OutDir ./app/Pog/lib_compiled/vcredist @(
# latest vcredist 140
"https://aka.ms/vs/17/release/vc_redist.x64.exe"
# fixed vcredist 120
"https://aka.ms/highdpimfc2013x64enu"
)
- name: Setup Pog
shell: pwsh
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# NOTE: this script is used in CI
### Copy vcredist DLLs from the local MSVC installation.
param(
[Parameter(Mandatory)]
[string]
$OutDir
)

$SrcDir = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -find VC/Redist/MSVC/*/x64 -products *
if ($null -eq $SrcDir) {
throw "Could not find VC Redistributable."
}

$Existing = [System.Collections.Generic.HashSet[string]](ls $PSScriptRoot\..\lib_compiled\vc_redist | % Name)
$null = $Existing.Remove("README.txt")
$Existing = [System.Collections.Generic.HashSet[string]](ls $OutDir -Filter *.dll | % Name)
ls -Recurse -File $SrcDir `
| % {$null = $Existing.Remove($_.Name); Write-Host $_; $_} `
| cp -Destination $PSScriptRoot\..\lib_compiled\vc_redist\
| cp -Destination $OutDir -Force

$Existing | % {
Write-Host "Not updated: $_"
Expand Down
64 changes: 64 additions & 0 deletions app/Pog/_scripts/vcredist-download.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# NOTE: this script is used in CI

### Downloads the vcredist.x64.exe packages from $Url, extracts the contained DLLs and stores them in $OutDir.
###
### Potentially relevant URLs:
### - latest vcredist 140: https://aka.ms/vs/17/release/vc_redist.x64.exe
### - latest vcredist 120 (as of January 2025): https://aka.ms/highdpimfc2013x64enu
param(
[Parameter(Mandatory)]
[string[]]
$Url,
[Parameter(Mandatory)]
[string]
$OutDir,
[switch]
$AdditionalLibraries,
[switch]
$Clean
)

$TmpDir = mkdir ($env:TEMP + "\PogVcRedist-" + (New-Guid).ToString())
try {
$null = mkdir $TmpDir\extracted_cabs

$Url | % {
# download the vcredist.exe binary
iwr $_ -OutFile $TmpDir\vcredist.exe

# extract the .cab files using WiX dark.exe
$null = dark -nologo -x $TmpDir\extracted_installer $TmpDir\vcredist.exe

$DirPattern = if ($AdditionalLibraries) {"*_amd64"} else {"vcRuntimeMinimum_amd64"}
$Cabs = ls $TmpDir\extracted_installer\AttachedContainer\packages\$DirPattern\cab1.cab

# extract DLLs from the extracted CABs
$Cabs | % {
# prefer expand.exe, it's a Windows built-in, so we don't need to install it in CI
$null = expand.exe -F:* $_ $TmpDir\extracted_cabs
#$null = 7z x $_ ("-o" + "$TmpDir\extracted_cabs")
}

rm -Recurse $TmpDir\extracted_installer
}

$null = mkdir -Force $OutDir
if ($Clean) {
rm $OutDir\*.dll
}

# clean up file names and copy them to the output directory
ls $TmpDir\extracted_cabs | % {
$FixedName = switch -Regex ($_.Name) {
# vcredist 120
'^F_CENTRAL_(.*)_x64$' {$Matches[1] + ".dll"}
# vcredist 140
'^(.*).dll_amd64$' {$Matches[1] + ".dll"}
# we do not support anything older
default {throw "Unknown name pattern: $_"}
}
Move-Item $_ $OutDir\$FixedName -Force -PassThru
}
} finally {
rm -Force -Recurse $TmpDir
}

0 comments on commit 4319fb8

Please sign in to comment.