Merge pull request #26023 from l0rd/win-installer-remove-provider-check

Remove providers checks from the Windows Installer
This commit is contained in:
openshift-merge-bot[bot]
2025-05-02 09:49:13 +00:00
committed by GitHub
6 changed files with 19 additions and 240 deletions

View File

@ -11,7 +11,6 @@ Windows.
- [Git and go](#git-and-go)
- [Pandoc](#pandoc)
- [.NET SDK](#net-sdk)
- [Visual Studio Build Tools](#visual-studio-build-tools)
- [Virtualization Provider](#virtualization-provider)
- [WSL](#wsl)
- [Hyper-V](#hyper-v)
@ -90,30 +89,6 @@ used too and can be installed using `dotnet install`:
dotnet tool install --global wix
```
### Visual Studio Build Tools
The installer includes a C program that checks the installation of the
pre-required virtualization providers (WSL or Hyper-V). Building this program
requires the
[Microsoft C/C++ compiler](https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170) and the
[PowerShell Module VSSetup](https://github.com/microsoft/vssetup.powershell):
1. Download the Build Tools for Visual Studio 2022 installer
```pwsh
Invoke-WebRequest -Uri 'https://aka.ms/vs/17/release/vs_BuildTools.exe' -OutFile "$env:TEMP\vs_BuildTools.exe"
```
2. Run the installer with the parameter to include the optional C/C++ Tools
```pwsh
& "$env:TEMP\vs_BuildTools.exe" --passive --wait `
--add Microsoft.VisualStudio.Workload.VCTools `
--includeRecommended `
--remove Microsoft.VisualStudio.Component.VC.CMake.Project
```
3. Install the PowerShell Module VSSetup
```pwsh
Install-Module VSSetup
```
### Virtualization Provider
Running Podman on Windows requires a virtualization provider. The supported
@ -314,8 +289,7 @@ To learn how to use the Podman client, refer to its
## Build and test the Podman Windows installer
The Podman Windows installer (e.g., `podman-5.1.0-dev-setup.exe`) is a bundle
that includes an msi package (`podman.msi`) and installs the WSL kernel
(`podman-wslkerninst.exe`). It's built using the
that includes an msi package (`podman.msi`). It's built using the
[WiX Toolset](https://wixtoolset.org/) and the
[PanelSwWixExtension](https://github.com/nirbar/PanelSwWixExtension/tree/master5)
WiX extension. The source code is in the folder `contrib\win-installer`.
@ -336,9 +310,6 @@ root) with a name like `podman-5.2.0-dev-setup.exe`.
The `installer` target of `winmake.ps1` runs the script
`contrib\win-installer\build.ps1` that, in turns, executes:
- `build-hooks.bat`: builds `podman-wslkerninst.exe` (WSL kernel installer) and
`podman-msihooks.dll` (helper that checks if WSL and Hyper-V are installed).
- `dotnet build podman.wixproj`: builds `podman.msi` from the WiX source files `podman.wxs`,
`pages.wxs`, `podman-ui.wxs` and `welcome-install-dlg.wxs`.
- `dotnet build podman-setup.wixproj`: builds `podman-setup.exe` file from
@ -521,7 +492,13 @@ tools:
[`.pre-commit-config.yaml`](.pre-commit-config.yaml)
:information_source: Install [golangci-lint](https://golangci-lint.run) and
[pre-commit](https://pre-commit.com) to run `winmake.ps1 lint`.
[pre-commit](https://pre-commit.com) to run `winmake.ps1 lint`:
```pwsh
winget install -e golangci-lint.golangci-lint
winget install -e Python.Python.3.13
pip install pre-commit
```
### winmake validatepr

View File

@ -1,67 +0,0 @@
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 -Latest
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

View File

@ -103,11 +103,8 @@ if ($ENV:INSTVER -eq "") {
Exit 1
}
.\build-hooks.ps1; ExitOnError
SignItem @("artifacts/win-sshproxy.exe",
"artifacts/podman.exe",
"artifacts/podman-msihooks.dll",
"artifacts/podman-wslkerninst.exe")
"artifacts/podman.exe")
$gvExists = Test-Path "artifacts/gvproxy.exe"
if ($gvExists) {
SignItem @("artifacts/gvproxy.exe")

View File

@ -1,130 +0,0 @@
#include <windows.h>
#include <MsiQuery.h>
BOOL isWSLEnabled();
BOOL isHyperVEnabled();
LPCWSTR boolToNStr(BOOL value);
LPCSTR szSvcNameHyperv = TEXT("vmms");
/**
* CheckWSL is a custom action loaded by the Podman Windows installer
* to determine whether the system already has WSL installed.
*
* The intention is that this action is compiled for x86_64, which
* can be ran on both Intel and Arm based systems (the latter through
* emulation). While the code should build fine on MSVC and clang, the
* intended usage is MingW-W64 (cross-compiling gcc targeting Windows).
*
* Previously this was implemented as a Golang c-shared cgo library,
* however, the WoW x86_64 emulation layer struggled with dynamic
* hot-loaded transformation of the goruntime into an existing process
* (required by MSI custom actions). In the future this could be
* converted back, should the emulation issue be resolved.
*/
__declspec(dllexport) UINT __cdecl CheckWSL(MSIHANDLE hInstall) {
BOOL hasWSL = isWSLEnabled();
// Set a property with the WSL state for the installer to operate on
MsiSetPropertyW(hInstall, L"HAS_WSLFEATURE", boolToNStr(hasWSL));
return 0;
}
/**
* CheckHyperV is a custom action loaded by the Podman Windows installer
* to determine whether the system already has Hyper-V installed.
*/
__declspec(dllexport) UINT __cdecl CheckHyperV(MSIHANDLE hInstall) {
BOOL hasHyperV = isHyperVEnabled();
// Set a property with the HyperV state for the installer to operate on
MsiSetPropertyW(hInstall, L"HAS_HYPERVFEATURE", boolToNStr(hasHyperV));
return 0;
}
LPCWSTR boolToNStr(BOOL value) {
return value ? L"1" : L"0";
}
BOOL isWSLEnabled() {
/*
* The simplest, and most reliable check across all variants and versions
* of WSL appears to be changing the default version to WSL 2 and check
* for errors, which we need to do anyway.
*/
STARTUPINFOW startup;
PROCESS_INFORMATION process;
ZeroMemory(&startup, sizeof(STARTUPINFOW));
startup.cb = sizeof(STARTUPINFOW);
// These settings hide the console window, so there is no annoying flash
startup.dwFlags = STARTF_USESHOWWINDOW;
startup.wShowWindow = SW_HIDE;
// CreateProcessW requires lpCommandLine to be mutable
wchar_t cmd[] = L"wsl --set-default-version 2";
if (! CreateProcessW(NULL, cmd, NULL, NULL, FALSE, CREATE_NEW_CONSOLE,
NULL, NULL, &startup, &process)) {
return FALSE;
}
DWORD exitCode;
WaitForSingleObject(process.hProcess, INFINITE);
if (! GetExitCodeProcess(process.hProcess, &exitCode)) {
return FALSE;
}
return exitCode == 0;
}
BOOL isHyperVEnabled() {
/*
* Checks if the Windows service `vmms` is running to
* determine if Hyper-V is enabled.
*/
SC_HANDLE schSCManager;
SC_HANDLE schService;
SERVICE_STATUS_PROCESS ssStatus;
DWORD dwBytesNeeded;
// Get a handle to the SCM database.
schSCManager = OpenSCManager(
NULL, // local computer
NULL, // servicesActive database
SERVICE_QUERY_STATUS); // service query access rights
if (NULL == schSCManager) {
return FALSE;
}
// Get a handle to the service.
schService = OpenService(
schSCManager,
szSvcNameHyperv,
SERVICE_QUERY_STATUS);
if (schService == NULL) {
CloseServiceHandle(schSCManager);
return FALSE;
}
// Check the status
if (!QueryServiceStatusEx(
schService, // handle to service
SC_STATUS_PROCESS_INFO, // information level
(LPBYTE) &ssStatus, // address of structure
sizeof(SERVICE_STATUS_PROCESS), // size of structure
&dwBytesNeeded ) ) {
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return FALSE;
}
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return ssStatus.dwCurrentState == SERVICE_RUNNING;
}

View File

@ -52,8 +52,6 @@
<SetProperty Id="HIDE_PROVIDER_CHOICE" After="AppSearch" Value="1" Sequence="first" Condition="(SKIP_CONFIG_FILE_CREATION = 1) OR (MACHINE_PROVIDER_CONFIG_FILE_PATH) OR (MAIN_EXECUTABLE_FILE_PATH)" />
<CustomAction Id="OpenGuide" DllEntry="WixShellExec" Impersonate="yes" BinaryRef="Wix4UtilCA_X86" />
<CustomAction Id="CheckWSL" Execute="firstSequence" DllEntry="CheckWSL" BinaryRef="PodmanHooks" />
<CustomAction Id="CheckHyperV" Execute="firstSequence" DllEntry="CheckHyperV" BinaryRef="PodmanHooks" />
<util:BroadcastEnvironmentChange />
<Feature Id="Complete" Level="1">
<ComponentRef Id="INSTALLDIR_Component" />
@ -82,12 +80,6 @@
<Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="OpenGuide" Condition="(WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1) AND (NOT Installed) AND (NOT UpdateStarted)" />
</UI>
<InstallExecuteSequence>
<Custom Action="CheckWSL" Before="InstallFiles" />
<Custom Action="CheckHyperV" Before="InstallFiles" />
</InstallExecuteSequence>
<Binary Id="PodmanHooks" SourceFile="artifacts/podman-msihooks.dll" />
<StandardDirectory Id="ProgramFiles6432Folder">
<Directory Id="RedHatPFiles" Name="RedHat">
<Directory Id="INSTALLDIR" Name="Podman">

View File

@ -147,10 +147,20 @@ function Test-Installer{
Exit 1
}
$nextSetupExePath = "$PSScriptRoot\contrib\win-installer\podman-9.9.9-dev-setup.exe"
if (!(Test-Path -Path $nextSetupExePath -PathType Leaf)) {
Write-Host "The automated tests include testing the upgrade from current version to a future version."
Write-Host "That requires a version 9.9.9 of the installer:"
Write-Host " .\winmake.ps1 installer 9.9.9"
Write-Host "Build it and retry running installertest."
Exit 1
}
$command = "$PSScriptRoot\contrib\win-installer\test-installer.ps1"
$command += " -scenario all"
$command += " -provider $provider"
$command += " -setupExePath $setupExePath"
$command += " -nextSetupExePath $nextSetupExePath"
Run-Command "${command}"
}