-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23212 from l0rd/vs-buildtools
Using Visual Studio BuildTools as a MinGW alternative
- Loading branch information
Showing
7 changed files
with
248 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
function Build-WSLKernelInstaller { | ||
param ( | ||
[string]$wslkerninstFolder, | ||
[string]$artifactsFolder | ||
); | ||
Set-Variable GOARCH=amd64 | ||
go build -ldflags -H=windowsgui -o "$artifactsFolder\podman-wslkerninst.exe" "$wslkerninstFolder" | ||
} | ||
|
||
function Build-MSIHooks { | ||
param ( | ||
[string]$msiHooksFolder, | ||
[string]$artifactsFolder | ||
); | ||
|
||
# Build using x86 toolchain, see comments in check.c for rationale and details | ||
if ( Get-MingW ) { | ||
Build-MSIHooks-Using-MingW $msiHooksFolder $artifactsFolder | ||
} elseif ( Get-VSBuildTools ) { | ||
$vsinstance = Get-VSSetupInstance | Select-VSSetupInstance -Product Microsoft.VisualStudio.Product.BuildTools | ||
Build-MSIHooks-Using-VSBuildTools $msiHooksFolder $artifactsFolder $vsinstance | ||
} else { | ||
$msg = "A C/C++ compiler is required to build `"$msiHooksFolder\check.c`". " | ||
$msg += "Supported compilers are MinGW CC (`"x86_64-w64-mingw32-gcc`") and the " | ||
$msg += "`"Microsoft.VisualStudio.Product.BuildTools`" with `"VSSetup`" PowerShell extension." | ||
Write-Error -Message $msg -ErrorAction Stop | ||
} | ||
} | ||
|
||
function Get-MingW { | ||
return Get-Command "x86_64-w64-mingw32-gcc" -errorAction SilentlyContinue | ||
} | ||
|
||
function Get-VSBuildTools { | ||
return ((Get-Command "Get-VSSetupInstance" -errorAction SilentlyContinue) -and ` | ||
(@(Get-VSSetupInstance | Select-VSSetupInstance -Product "Microsoft.VisualStudio.Product.BuildTools").Count -gt 0)) | ||
} | ||
|
||
function Build-MSIHooks-Using-MingW { | ||
param ( | ||
[string]$msiHooksFolder, | ||
[string]$artifactsFolder | ||
); | ||
Set-Variable GOARCH=amd64 | ||
x86_64-w64-mingw32-gcc $msiHooksFolder/check.c -shared -lmsi -mwindows -o $artifactsFolder/podman-msihooks.dll | ||
} | ||
|
||
function Build-MSIHooks-Using-VSBuildTools { | ||
param ( | ||
[string]$msiHooksFolder, | ||
[string]$artifactsFolder, | ||
[Microsoft.VisualStudio.Setup.Instance]$vsinstance | ||
); | ||
$vspath = $vsinstance.InstallationPath | ||
$vsinstanceid = $vsinstance.InstanceId | ||
|
||
Import-Module "$vspath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" | ||
Enter-VsDevShell $vsinstanceid -DevCmdArguments '-arch=amd64 -host_arch=amd64' | ||
cl.exe /W4 /Fo$artifactsFolder\ $msiHooksFolder\check.c Advapi32.lib Msi.lib /link /DLL /out:$artifactsFolder\podman-msihooks.dll | ||
} | ||
|
||
$wslkerninstFolder="$PSScriptRoot\..\..\cmd\podman-wslkerninst" | ||
$msiHooksFolder="$PSScriptRoot\podman-msihooks" | ||
$artifactsFolder="$PSScriptRoot\artifacts" | ||
|
||
Build-WSLKernelInstaller $wslkerninstFolder $artifactsFolder | ||
Build-MSIHooks $msiHooksFolder $artifactsFolder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/usr/bin/env pwsh | ||
|
||
# The Param statement must be the first statement, except for comments and any #Require statements. | ||
param ( | ||
[Parameter(Mandatory)] | ||
[ValidateSet("install", "uninstall", "all")] | ||
[string]$operation, | ||
[Parameter(Mandatory)] | ||
[ValidateScript({Test-Path $_ -PathType Leaf})] | ||
[string]$setupExePath, | ||
[ValidateSet("wsl", "hyperv")] | ||
[string]$provider="wsl", | ||
[switch]$installWSL=$false, | ||
[switch]$installHyperV=$false, | ||
[switch]$skipWinVersionCheck=$false | ||
) | ||
|
||
$ConfFilePath = "$env:ProgramData\containers\containers.conf.d\99-podman-machine-provider.conf" | ||
$WindowsPathsToTest = @("C:\Program Files\RedHat\Podman\podman.exe", | ||
"C:\Program Files\RedHat\Podman\win-sshproxy.exe", | ||
"$ConfFilePath", | ||
"HKLM:\SOFTWARE\Red Hat\Podman") | ||
|
||
function Test-Installation { | ||
if ($installWSL) {$wslCheckboxVar = "1"} else {$wslCheckboxVar = "0"} | ||
if ($installHyperV) {$hypervCheckboxVar = "1"} else {$hypervCheckboxVar = "0"} | ||
if ($skipWinVersionCheck) {$allowOldWinVar = "1"} else {$allowOldWinVar = "0"} | ||
|
||
Write-Host "Running the installer (provider=`"$provider`")..." | ||
$ret = Start-Process -Wait ` | ||
-PassThru "$setupExePath" ` | ||
-ArgumentList "/install /quiet ` | ||
MachineProvider=${provider} ` | ||
WSLCheckbox=${wslCheckboxVar} ` | ||
HyperVCheckbox=${hypervCheckboxVar} ` | ||
AllowOldWin=${allowOldWinVar} ` | ||
/log $PSScriptRoot\podman-setup.log" | ||
if ($ret.ExitCode -ne 0) { | ||
Write-Host "Install failed, dumping log" | ||
Get-Content $PSScriptRoot\podman-setup.log | ||
throw "Exit code is $($ret.ExitCode)" | ||
} | ||
|
||
Write-Host "Verifying that the installer has created the expected files, folders and registry entries..." | ||
$WindowsPathsToTest | ForEach-Object { | ||
if (! (Test-Path -Path $_) ) { | ||
throw "Expected $_ but it's not present after uninstall" | ||
} | ||
} | ||
|
||
Write-Host "Verifying that the machine provider configuration is correct..." | ||
$machineProvider = Get-Content $ConfFilePath | Select-Object -Skip 1 | ConvertFrom-StringData | ForEach-Object { $_.provider } | ||
if ( $machineProvider -ne "`"$provider`"" ) { | ||
throw "Expected `"$provider`" as default machine provider but got $machineProvider" | ||
} | ||
|
||
Write-Host "The installation verification was successful!`n" | ||
} | ||
|
||
function Test-Uninstallation { | ||
Write-Host "Running the uninstaller" | ||
$ret = Start-Process -Wait ` | ||
-PassThru "$setupExePath" ` | ||
-ArgumentList "/uninstall ` | ||
/quiet /log $PSScriptRoot\podman-setup-uninstall.log" | ||
if ($ret.ExitCode -ne 0) { | ||
Write-Host "Uninstall failed, dumping log" | ||
Get-Content $PSScriptRoot\podman-setup-uninstall.log | ||
throw "Exit code is $($ret.ExitCode)" | ||
} | ||
|
||
Write-Host "Verifying that the uninstaller has removed files, folders and registry entries as expected..." | ||
$WindowsPathsToTest | ForEach-Object { | ||
if ( Test-Path -Path $_ ) { | ||
throw "Path $_ is still present after uninstall" | ||
} | ||
} | ||
|
||
Write-Host "The uninstallation verification was successful!`n" | ||
} | ||
|
||
switch ($operation) { | ||
'install' { | ||
Test-Installation | ||
} | ||
'uninstall' { | ||
Test-Uninstallation | ||
} | ||
'all' { | ||
Test-Installation | ||
Test-Uninstallation | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters