Skip to content

Commit

Permalink
Merge pull request #8111 from mook-as/win32/install/no-install-wsl
Browse files Browse the repository at this point in the history
Release-1.17: Windows Installer: Do not attempt to install WSL
  • Loading branch information
jandubois authored Jan 18, 2025
2 parents ff41d52 + e71f684 commit a083d59
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 248 deletions.
2 changes: 1 addition & 1 deletion .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ HOSTPORT
hoverable
howett
hpa
hresult
HRESULT
htpasswd
httpconfig
Huawei
Expand Down
6 changes: 4 additions & 2 deletions build/wix/dialogs.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

<Property Id="DefaultUIFont" Value="WixUI_Font_Normal" />
<Property Id="WixUI_Mode" Value="RD" />
<Property Id="ALLUSERS" Secure="yes" Value="2"/>
<Property Id="ALLUSERS" Secure="yes" Value="2" />
<!-- MSIINSTALLPERUSER will get modified when the user advances from InstallScopeDlg -->
<Property Id="MSIINSTALLPERUSER" Secure="yes" Value="0"/>
<Property Id="MSIINSTALLPERUSER" Secure="yes" Value="0" />

<Error Id="100">!(loc.Error_WSLNotInstalled)</Error>

<DialogRef Id="ErrorDlg" />
<DialogRef Id="FatalError" />
Expand Down
28 changes: 8 additions & 20 deletions build/wix/main.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
AllowSameVersionUpgrades="yes"
DowngradeErrorMessage='A newer version of [ProductName] is already installed.'
Schedule="afterInstallInitialize" />
<MediaTemplate CompressionLevel="{{compressionLevel}}" EmbedCab="yes" />
<MediaTemplate CompressionLevel="high" EmbedCab="yes" />
<UIRef Id="WixUI_RD" />

<Property Id="ApplicationFolderName" Value="Rancher Desktop" />
Expand All @@ -47,20 +47,11 @@
<Binary Id="CustomActionBinary" SourceFile="wix-custom-action.dll" />
<CustomAction Id="DetectWSL" BinaryKey="CustomActionBinary" DllEntry="DetectWSL"
Execute="immediate" Return="check" />
<!-- Custom action to install Windows features for WSL -->
<CustomAction Id="InstallWindowsFeature" BinaryKey="CustomActionBinary"
DllEntry="InstallWindowsFeature" Execute="deferred" Return="check" Impersonate="no" />
<!-- Custom action to install WSL -->
<CustomAction Id="InstallWSL" BinaryKey="CustomActionBinary" DllEntry="InstallWSL"
Execute="deferred" Return="check" Impersonate="yes" />
<!-- Custom action to update WSL -->
<CustomAction Id="UpdateWSL" BinaryKey="CustomActionBinary" DllEntry="UpdateWSL"
Execute="deferred" Return="check" Impersonate="yes" />

<!-- Disable the start app prompt if we need a reboot -->
<SetProperty Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Sequence="ui" After="DetectWSL" Value="">
NOT WSLINSTALLED AND NOT Installed
</SetProperty>
<!-- Custom action to raise an error because WSL was not installed -->
<CustomAction Id="ErrorWSLNotInstalled" Error="100" />

<InstallUISequence>
<!--
Expand All @@ -70,23 +61,20 @@
<Custom Action="DetectWSL" After="AppSearch">
NOT WSLINSTALLED <!-- Skip search if user overrides -->
</Custom>
<Custom Action="ErrorWSLNotInstalled" After="RDWelcomeDlg">
NOT WSLINSTALLED AND NOT Installed
</Custom>
</InstallUISequence>
<InstallExecuteSequence>
<Custom Action="DetectWSL" After="AppSearch">
NOT WSLINSTALLED <!-- Skip search if user overrides -->
</Custom>
<Custom Action="InstallWindowsFeature" After="InstallFiles">
NOT WSLINSTALLED AND NOT Installed
</Custom>
<Custom Action="InstallWSL" After="InstallWindowsFeature">
<Custom Action="ErrorWSLNotInstalled" After="LaunchConditions">
NOT WSLINSTALLED AND NOT Installed
</Custom>
<Custom Action="UpdateWSL" After="InstallWSL">
<Custom Action="UpdateWSL" After="InstallFiles">
WSLINSTALLED AND WSLKERNELOUTDATED
</Custom>
<ScheduleReboot After="UpdateWSL">
NOT WSLINSTALLED AND NOT Installed
</ScheduleReboot>
</InstallExecuteSequence>

<!-- Check if the NSIS-based Rancher Desktop is installed, and uninstall if yes. -->
Expand Down
2 changes: 1 addition & 1 deletion build/wix/string-overrides.wxl
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<String Id="InstallScopeDlgPerMachineDescription" Overridable="yes">[ProductName] will be installed in a per-machine folder and be available for all users. This enables listening on non-loopback ports and other features that require additional privileges. You must have local Administrator privileges.</String>
<String Id="InstallScopeDlgPerUserDescription">[ProductName] will be installed in a per-user folder and be available just for your user account. You do not need local Administrator privileges. This will disable support for listening on non-loopback ports, and requires WSL2 to already be installed on your machine.</String>
<String Id="InstallScopeDlgNoPerUserDescription" Overridable="yes">[ProductName] cannot be installed per-user, as Windows Subsystem for Linux 2 was not found. Continuing to install [ProductName] will also install WSL2.</String>
<String Id="VerifyReadyDlgKernelInstallText" Overridable="yes">[ProductName] will be installed in a per-machine folder and be available for all users. This enables listening on non-loopback ports and other features that require additional privileges. Windows Subsystem for Linux 2 will also be installed as a prerequisite.</String>
<String Id="Error_WSLNotInstalled" Overridable="yes">[ProductName] requires Windows Subsystem for Linux 2 (WSL2) to be installed as a prerequisite. Please follow the instructions at https://aka.ms/wslinstall</String>
</WixLocalization>
9 changes: 1 addition & 8 deletions build/wix/verify.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@
<Control Id="InstallText" Type="Text"
X="25" Y="70" Width="320" Height="80" Hidden="yes" NoPrefix="yes"
Text="!(loc.VerifyReadyDlgInstallText)">
<Condition Action="show">WSLINSTALLED</Condition>
</Control>
<Control Id="InstallKernelText" Type="Text"
X="25" Y="70" Width="320" Height="80" Hidden="yes" NoPrefix="yes"
Text="!(loc.VerifyReadyDlgKernelInstallText)">
<Condition Action="show">NOT WSLINSTALLED</Condition>
</Control>

<Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
<Control Id="Back" Type="PushButton" X="156" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)">
<Publish Order="1" Event="NewDialog" Value="RDInstallScopeDlg">WSLINSTALLED</Publish>
<Publish Order="2" Event="NewDialog" Value="RDWelcomeDlg">NOT WSLINSTALLED</Publish>
<Publish Order="1" Event="NewDialog" Value="RDInstallScopeDlg" />
</Control>

<Control Id="Install" Type="PushButton" ElevationShield="yes"
Expand Down
6 changes: 3 additions & 3 deletions build/wix/welcome.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
<![CDATA[RDLicenseAccepted <> "1"]]>
</Condition>
<Condition Action="enable">RDLicenseAccepted = "1"</Condition>
<!-- If the kernel is not installed, the user doesn't have a choice
- and we can skip to the verify install dialog directly.
<!-- If WSL is not installed, we abort the installation now as we are
- no longer able to install WSL as part of our process.
-->
<Publish Event="NewDialog" Order="1" Value="RDInstallScopeDlg">1</Publish>
<Publish Event="NewDialog" Order="2" Value="RDVerifyReadyDlg">NOT WSLINSTALLED</Publish>
<Publish Event="DoAction" Order="2" Value="ErrorWSLNotInstalled">NOT WSLINSTALLED</Publish>
</Control>
<Control Id="Cancel" Type="PushButton" Cancel="yes"
X="304" Y="243" Width="56" Height="17" Text="!(loc.WixUICancel)">
Expand Down
4 changes: 1 addition & 3 deletions scripts/lib/installer-win32.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ export default async function buildInstaller(workDir: string, appDir: string, ou
await writeUpdateConfig(appDir);
const fileList = await generateFileList(appDir);
const template = await fs.promises.readFile(path.join(process.cwd(), 'build', 'wix', 'main.wxs'), 'utf-8');
const output = Mustache.render(template, {
appVersion, fileList, compressionLevel: 'high',
});
const output = Mustache.render(template, { appVersion, fileList });
const wixDir = path.join(process.cwd(), 'resources', 'host', 'wix');

console.log('Writing out WiX definition...');
Expand Down
1 change: 1 addition & 0 deletions scripts/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class Builder {
await executeAppBuilder(['rcedit', '--args', JSON.stringify(rceditArgs)], undefined, undefined, 3);

// Create the custom action for the installer
log.info('building Windows Installer custom action...');
const customActionFile = await buildCustomAction();

// Wait for the virus scanner to be done with the new DLL file
Expand Down
6 changes: 5 additions & 1 deletion scripts/wix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import fs from 'fs';
import path from 'path';

import buildInstaller from './lib/installer-win32';
import buildInstaller, { buildCustomAction } from './lib/installer-win32';

async function run() {
const distDir = path.join(process.cwd(), 'dist');
Expand All @@ -21,6 +21,10 @@ async function run() {
process.exit(1);
}

const customActionFile = await buildCustomAction();

await fs.promises.copyFile(customActionFile,
path.join(appDir, path.basename(customActionFile)));
await buildInstaller(distDir, appDir);
}

Expand Down
123 changes: 0 additions & 123 deletions src/go/wsl-helper/pkg/wsl-utils/dism_windows.go

This file was deleted.

22 changes: 0 additions & 22 deletions src/go/wsl-helper/pkg/wsl-utils/install_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,6 @@ import (
"golang.org/x/sys/windows"
)

// InstallWSL runs wsl.exe to install WSL.
func InstallWSL(ctx context.Context, log *logrus.Entry) error {
// wsl.exe calls wslapi.dll, which eventually uses the WinRT API
// Windows.ApplicationModel.Store.Preview.InstallControl — but that is
// (according to docs) private and only usable by Microsoft-signed apps.
// Just spawn wsl.exe and hope it does the job. Trying to reverse-engineer
// the WslInstaller COM component seems error-prone, and it will likely
// change in the future. Unfortunately, this means more UAC prompts.
newRunnerFunc := NewWSLRunner
if f := ctx.Value(&kWSLExeOverride); f != nil {
newRunnerFunc = f.(func() WSLRunner)
}
// WSL install hangs if we set stdout; don't set that here.
err := newRunnerFunc().
WithStderr(log.WriterLevel(logrus.InfoLevel)).
Run(ctx, "--install", "--no-distribution")
if err != nil {
return err
}
return nil
}

// UpdateWSL runs wsl.exe to update the WSL kernel. This assumes that WSL had
// already been installed. This may request elevation.
func UpdateWSL(ctx context.Context, log *logrus.Entry) error {
Expand Down
44 changes: 0 additions & 44 deletions src/go/wsl-helper/wix/install_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,6 @@ func setupLogger(hInstall MSIHANDLE) *logrus.Entry {
})
}

// InstallWindowsFeatureImpl installs the Windows features necessary for WSL to
// be installed. This needs to be run elevated.
func InstallWindowsFeatureImpl(hInstall MSIHANDLE) uint32 {
ctx := context.Background()
log := setupLogger(hInstall)

log.Infof("Installing Windows feature...")
err := submitMessage(hInstall, INSTALLMESSAGE_ACTIONSTART, []string{
"", "InstalWindowsFeature", "Installing required Windows features...", "<unused>",
})
if err != nil {
log.WithError(err).Info("Failed to update progress")
}
if err := wslutils.DismDoInstall(ctx, log); err != nil {
log.WithError(err).Error("Failed to install feature")
return 1
}

return 0
}

// InstallWSLImpl installs WSL.
// This assumes WSL was not previously installed.
// This needs to be run as the user.
func InstallWSLImpl(hInstall MSIHANDLE) uint32 {
ctx := context.Background()
log := setupLogger(hInstall)

log.Info("Installing WSL...")
err := submitMessage(hInstall, INSTALLMESSAGE_ACTIONSTART, []string{
"", "InstallWSL", "Installing Windows Subsystem for Linux...", "<unused>",
})
if err != nil {
log.WithError(err).Info("Failed to update progress")
}
if err := wslutils.InstallWSL(ctx, log); err != nil {
log.WithError(err).Error("Installing WSL failed")
return 1
}

log.Info("WSL successfully installed.")
return 0
}

// UpdateWSLImpl updates the previously installed WSL.
// This needs to be run as the user, and may request elevation.
func UpdateWSLImpl(hInstall MSIHANDLE) uint32 {
Expand Down
20 changes: 0 additions & 20 deletions src/go/wsl-helper/wix/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,6 @@ func DetectWSL(hInstall C.ulong) C.ulong {
return C.ulong(DetectWSLImpl(MSIHANDLE(hInstall)))
}

// InstallWindowsFeature is a wrapper around InstallWindowsFeature; this is the
// stub to be exported in the DLL. This only exists to limit cgo to this file
// so that editing on a machine that requires cross compilation can avoid
// needing a cross cgo toolchain.
//
//export InstallWindowsFeature
func InstallWindowsFeature(hInstall C.ulong) C.ulong {
return C.ulong(InstallWindowsFeatureImpl(MSIHANDLE(hInstall)))
}

// InstallWSL is a wrapper around InstallWSLImpl; this is the stub to be
// exported in the DLL. This only exists to limit cgo to this file so that
// editing on a machine that requires cross compilation can avoid needing a
// cross cgo toolchain.
//
//export InstallWSL
func InstallWSL(hInstall C.ulong) C.ulong {
return C.ulong(InstallWSLImpl(MSIHANDLE(hInstall)))
}

// UpdateWSL is a wrapper around UpdateWSLImpl; this is the stub to be exported
// in the DLL. This only exists to limit cgo to this file so that editing on a
// machine that requires cross compilation can avoid needing a cross cgo
Expand Down

0 comments on commit a083d59

Please sign in to comment.