Skip to content

Commit c3efb02

Browse files
feat(installer/windows): add wix installer
1 parent 7e95d53 commit c3efb02

File tree

6 files changed

+233
-2
lines changed

6 files changed

+233
-2
lines changed

.github/workflows/ci-windows.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ jobs:
236236
# Clean up
237237
Remove-Item -Path doxygen-setup.exe
238238
239+
- name: Setup dotnet # needed for wix
240+
uses: actions/setup-dotnet@v4
241+
with:
242+
dotnet-version: '9.x'
243+
239244
- name: Setup python
240245
id: setup-python
241246
uses: actions/setup-python@v5
@@ -282,12 +287,19 @@ jobs:
282287
283288
# package
284289
cpack -G NSIS
290+
cpack -G WIX
285291
cpack -G ZIP
286292
287293
# move
288294
mv ./cpack_artifacts/Sunshine.exe ../artifacts/Sunshine-${{ matrix.name }}-installer.exe
295+
mv ./cpack_artifacts/Sunshine.msi ../artifacts/Sunshine-${{ matrix.name }}-installer.msi
289296
mv ./cpack_artifacts/Sunshine.zip ../artifacts/Sunshine-${{ matrix.name }}-portable.zip
290297
298+
- name: Debug wix
299+
if: always()
300+
shell: msys2 {0}
301+
run: cat /d/a/Sunshine/Sunshine/build/cpack_artifacts/_CPack_Packages/win64/WIX/wix.log
302+
291303
- name: Run tests
292304
id: test
293305
shell: msys2 {0}

cmake/packaging/windows_wix.cmake

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,73 @@
11
# WIX Packaging
22
# see options at: https://cmake.org/cmake/help/latest/cpack_gen/wix.html
33

4-
# TODO: Replace nsis with wix
4+
set(CPACK_WIX_VERSION 4)
5+
set(WIX_VERSION 4.0.4)
6+
set(WIX_UI_VERSION 4.0.4) # extension versioning is independent of the WiX version
7+
set(WIX_BUILD_PARENT_DIRECTORY "${CPACK_PACKAGE_DIRECTORY}/_CPack_Packages/win64")
8+
set(WIX_BUILD_DIRECTORY "${WIX_BUILD_PARENT_DIRECTORY}/WIX")
9+
10+
# Download and install WiX tools locally in the build directory
11+
set(WIX_TOOL_PATH "${CMAKE_BINARY_DIR}/.wix")
12+
file(MAKE_DIRECTORY ${WIX_TOOL_PATH})
13+
14+
# find dotnet
15+
find_program(DOTNET_EXECUTABLE dotnet REQUIRED HINTS "C:/Program Files/dotnet")
16+
17+
# Install WiX locally using dotnet
18+
execute_process(
19+
COMMAND ${DOTNET_EXECUTABLE} tool install --tool-path ${WIX_TOOL_PATH} wix --version ${WIX_VERSION}
20+
ERROR_VARIABLE WIX_INSTALL_OUTPUT
21+
RESULT_VARIABLE WIX_INSTALL_RESULT
22+
)
23+
24+
if(NOT WIX_INSTALL_RESULT EQUAL 0)
25+
message(FATAL_ERROR "Failed to install WiX tools locally.
26+
WiX packaging may not work correctly, error: ${WIX_INSTALL_OUTPUT}")
27+
endif()
28+
29+
# Install WiX UI Extension
30+
execute_process(
31+
COMMAND "${WIX_TOOL_PATH}/wix" extension add WixToolset.UI.wixext/${WIX_UI_VERSION}
32+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
33+
ERROR_VARIABLE WIX_UI_INSTALL_OUTPUT
34+
RESULT_VARIABLE WIX_UI_INSTALL_RESULT
35+
)
36+
37+
if(NOT WIX_UI_INSTALL_RESULT EQUAL 0)
38+
message(FATAL_ERROR "Failed to install WiX UI extension, error: ${WIX_UI_INSTALL_OUTPUT}")
39+
endif()
40+
41+
# Set WiX-specific variables
42+
set(CPACK_WIX_ROOT "${WIX_TOOL_PATH}")
43+
set(CPACK_WIX_UPGRADE_GUID "512A3D1B-BE16-401B-A0D1-59BBA3942FB8")
44+
45+
# Help/Support URLs
46+
set(CPACK_WIX_HELP_LINK "https://docs.lizardbyte.dev/projects/sunshine/latest/md_docs_2getting__started.html")
47+
set(CPACK_WIX_PRODUCT_URL "${CMAKE_PROJECT_HOMEPAGE_URL}")
48+
set(CPACK_WIX_PROGRAM_MENU_FOLDER "LizardByte")
49+
50+
set(CPACK_WIX_EXTENSIONS
51+
"WixToolset.UI.wixext"
52+
)
53+
54+
message(STATUS "cpack package directory: ${CPACK_PACKAGE_DIRECTORY}")
55+
56+
# copy custom wxs files to the build directory
57+
file(COPY "${CMAKE_CURRENT_LIST_DIR}/wix_resources/"
58+
DESTINATION "${WIX_BUILD_PARENT_DIRECTORY}/")
59+
60+
set(CPACK_WIX_EXTRA_SOURCES
61+
"${WIX_BUILD_PARENT_DIRECTORY}/main.wxs"
62+
"${WIX_BUILD_PARENT_DIRECTORY}/custom-actions.wxs"
63+
"${WIX_BUILD_PARENT_DIRECTORY}/custom-shortcuts.wxs"
64+
)
65+
66+
# Copy root LICENSE and rename to have .txt extension
67+
file(COPY "${CMAKE_SOURCE_DIR}/LICENSE"
68+
DESTINATION "${CMAKE_BINARY_DIR}")
69+
file(RENAME "${CMAKE_BINARY_DIR}/LICENSE" "${CMAKE_BINARY_DIR}/LICENSE.txt")
70+
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_BINARY_DIR}/LICENSE.txt") # cpack will covert this to an RTF if it is txt
71+
72+
# https://cmake.org/cmake/help/latest/cpack_gen/wix.html#variable:CPACK_WIX_ARCHITECTURE
73+
set(CPACK_WIX_ARCHITECTURE "x64")
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?include "WIX/cpack_variables.wxi"?>
4+
5+
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
6+
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
7+
<Fragment Id="CustomActionsFragment">
8+
<CustomAction Id='InstallService'
9+
ExeCommand='cmd.exe /c "[INSTALL_ROOT]scripts\install-service.bat"'
10+
Directory='INSTALL_ROOT'
11+
Execute='deferred'
12+
Return='check'
13+
Impersonate='no' />
14+
15+
<CustomAction Id='ConfigFirewall'
16+
ExeCommand='cmd.exe /c "[INSTALL_ROOT]scripts\add-firewall-rule.bat"'
17+
Directory='INSTALL_ROOT'
18+
Execute='deferred'
19+
Return='check'
20+
Impersonate='no' />
21+
22+
<CustomAction Id='InstallGamepad'
23+
ExeCommand='cmd.exe /c "[INSTALL_ROOT]scripts\install-gamepad.bat"'
24+
Directory='INSTALL_ROOT'
25+
Execute='deferred'
26+
Return='check'
27+
Impersonate='no' />
28+
29+
<CustomAction Id='AutostartService'
30+
ExeCommand='cmd.exe /c "[INSTALL_ROOT]scripts\autostart-service.bat"'
31+
Directory='INSTALL_ROOT'
32+
Execute='deferred'
33+
Return='check'
34+
Impersonate='no' />
35+
36+
<CustomAction Id='MigrateConfig'
37+
ExeCommand='cmd.exe /c "[INSTALL_ROOT]scripts\migrate-config.bat"'
38+
Directory='INSTALL_ROOT'
39+
Execute='deferred'
40+
Return='check'
41+
Impersonate='no' />
42+
43+
<CustomAction Id='UpdatePath'
44+
ExeCommand='cmd.exe /c "[INSTALL_ROOT]scripts\update-path.bat add"'
45+
Directory='INSTALL_ROOT'
46+
Execute='deferred'
47+
Return='check'
48+
Impersonate='no' />
49+
50+
<CustomAction Id='ResetPermissions'
51+
ExeCommand='cmd.exe /c "icacls \"[INSTALL_ROOT]\" /reset"'
52+
Directory='INSTALL_ROOT'
53+
Execute='deferred'
54+
Return='check'
55+
Impersonate='no' />
56+
57+
<CustomAction Id='UninstallService'
58+
ExeCommand='cmd.exe /c "[INSTALL_ROOT]scripts\uninstall-service.bat"'
59+
Directory='INSTALL_ROOT'
60+
Execute='deferred'
61+
Return='check'
62+
Impersonate='no' />
63+
64+
<CustomAction Id='RemoveFirewall'
65+
ExeCommand='cmd.exe /c "[INSTALL_ROOT]scripts\delete-firewall-rule.bat"'
66+
Directory='INSTALL_ROOT'
67+
Execute='deferred'
68+
Return='check'
69+
Impersonate='no' />
70+
71+
<CustomAction Id='RestoreNvPrefs'
72+
ExeCommand='cmd.exe /c "[INSTALL_ROOT]$(var.CPACK_PACKAGE_NAME).exe --restore-nvprefs-undo"'
73+
Directory='INSTALL_ROOT'
74+
Execute='deferred'
75+
Return='check'
76+
Impersonate='no' />
77+
78+
<CustomAction Id='RemovePathUpdate'
79+
ExeCommand='cmd.exe /c "[INSTALL_ROOT]scripts\update-path.bat remove"'
80+
Directory='INSTALL_ROOT'
81+
Execute='deferred'
82+
Return='check'
83+
Impersonate='no' />
84+
85+
<InstallExecuteSequence>
86+
<Custom Action='ResetPermissions' After='InstallFiles' Condition="NOT Installed" />
87+
<Custom Action='UpdatePath' After='ResetPermissions' Condition="NOT Installed" />
88+
<Custom Action='MigrateConfig' After='UpdatePath' Condition="NOT Installed" />
89+
<Custom Action='ConfigFirewall' After='MigrateConfig' Condition="NOT Installed" />
90+
<Custom Action='InstallGamepad' After='ConfigFirewall' Condition="NOT Installed" />
91+
<Custom Action='InstallService' After='InstallGamepad' Condition="NOT Installed" />
92+
<Custom Action='AutostartService' After='InstallService' Condition="NOT Installed" />
93+
94+
<Custom Action='RemoveFirewall' Before='RemoveFiles' Condition="REMOVE" />
95+
<Custom Action='UninstallService' Before='RemoveFiles' Condition="REMOVE" />
96+
<Custom Action='RestoreNvPrefs' Before='RemoveFiles' Condition="REMOVE" />
97+
<Custom Action='RemovePathUpdate' Before='RemoveFiles' Condition="REMOVE" />
98+
</InstallExecuteSequence>
99+
</Fragment>
100+
</Wix>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
3+
<?include "WIX/cpack_variables.wxi"?>
4+
5+
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
6+
<Fragment Id="CustomShortcutsFragment">
7+
<StandardDirectory Id='ProgramMenuFolder'>
8+
<Directory Id='ApplicationProgramsFolder' Name='$(var.CPACK_PACKAGE_VENDOR)'>
9+
<Component Id='ApplicationShortcut' Guid='*'>
10+
<Shortcut Id='ApplicationStartMenuShortcut'
11+
Name='$(var.CPACK_PACKAGE_NAME)'
12+
Description='Self-hosted game stream host for Moonlight'
13+
Target='[INSTALL_ROOT]$(var.CPACK_PACKAGE_NAME).exe'
14+
Arguments='--shortcut'
15+
WorkingDirectory='INSTALL_ROOT'/>
16+
<RemoveFolder Id='ApplicationProgramsFolder' On='uninstall'/>
17+
<RegistryValue Root='HKCU' Key='Software\\LizardByte\\$(var.CPACK_PACKAGE_NAME)'
18+
Name='installed' Type='integer' Value='1' KeyPath='yes'/>
19+
</Component>
20+
</Directory>
21+
</StandardDirectory>
22+
</Fragment>
23+
</Wix>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?include "WIX/cpack_variables.wxi"?>
4+
5+
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
6+
<Package Name="$(var.CPACK_PACKAGE_NAME)"
7+
Version="$(var.CPACK_PACKAGE_VERSION)"
8+
Manufacturer="$(var.CPACK_PACKAGE_VENDOR)"
9+
UpgradeCode="$(var.CPACK_WIX_UPGRADE_GUID)">
10+
11+
<SummaryInformation Description='Self-hosted game stream host for Moonlight' />
12+
13+
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
14+
15+
<MediaTemplate EmbedCab="yes" />
16+
17+
<!-- Reference the custom actions Fragment -->
18+
<FragmentRef Id="CustomActionsFragment" />
19+
20+
<!-- Reference the shortcuts Fragment -->
21+
<FragmentRef Id="CustomShortcutsFragment" />
22+
23+
</Package>
24+
</Wix>

docs/building.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ ninja -C build
138138
```}
139139
}}
140140
@tab{Windows | @tabs{
141-
@tab{Installer | ```bash
141+
@tab{NSIS Installer | ```bash
142142
cpack -G NSIS --config ./build/CPackConfig.cmake
143143
```}
144+
@tab{WiX Installer | ```bash
145+
cpack -G WIX --config ./build/CPackConfig.cmake
146+
```}
144147
@tab{Portable | ```bash
145148
cpack -G ZIP --config ./build/CPackConfig.cmake
146149
```}

0 commit comments

Comments
 (0)