Building lzhuf on Microsoft Windows and GitHub Actions - wb8tyw/D-Rats Wiki
This is to document building the lzhuf binary on Microsoft Windows.
The goal is to be able to build that lzhuf binary on a GitHub Microsoft Windows runner and package it up in an MSI or equivalent module.
Of course that means we need to have a way to locally do the build using the hopefully the same tools to save cycles in the maintenance.
The GitHub runners are described at About GitHub Hosted Runners
The actual packages available are at Windows2022 Readme
For lzhuf, we want to build a native Windows MSI package for D-Rats to use.
As a secondary goal we will want to make a msys2 mingw64 installable package.
It turns out that while GitHub action runners can test the build and packaging, they are not as useful for actually creating distributed packages. You have to write a program to use the REST interface to download the artifact, and there are quota rules that must be complied with on the free plan. That will need to be looked at in the future.
Visual Studio Community edition appears to be the best choice for debugging.
It is downloaded from Microsoft Microsoft Visual Studio Community Edition
It is a 10 GB download, trying it on Windows 7, which it warns is not supported and may not fully work.
Then we need to create an MSBUILD XML file.
WIX is an Open Source Microsoft tool to create a MSI file.
The final part we need to determine is is how to make the package created by the GitHub action to be downloadable by users.
Building binaries locally
After a lot of trial and error, mostly error, I finally got the msbuild program to work. It does not work in a powershell session on Windows7, only the Command Prompt window.
The default directory is set to the checked out code.
I had to use the File->New->"Project from existing code" to run a wizard to create the lzhuf.vcxproj file. And then edit it based mostly on trial and error.
I still do not have everything right so that I can use defaults, and I can not find any documentation that clearly explains how to do a simple command line project like this. Some Microsoft documentations say to right click on something that I can not find to get a properties panel. Everything I right click on to get properties on has a blank property page nothing like displayed in the article.
First thing that needs to be done is add msbuild to your path. A batch script is provided.
"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VSDevCmd.bat"
Then you can built the win32 and x64 release targets. I guess the win32 is all that is really needed because lzhuf only using 32 bits internally.
msbuild lzhuf.vcxproj -t:build -p:Configuration=Release -p:Platform=Win32 msbuild lzhuf.vcxproj -t:build -p:Configuration=Release -p:Platform=x64
The Win32 build is put in the Release folder.
The x64 build is put in the x64\Release folder.
Now we can test to see if we actually got a working image.
W:\work\d-rats\lzhuf>Release\lzhuf e tests\test_data.ref test_data.lzh W:\work\d-rats\lzhuf>fc test_data.lzh tests/test_data.lzh_ref Comparing files test_data.lzh and TESTS/TEST_DATA.LZH_REF FC: no differences encountered W:\work\d-rats\lzhuf>x64\Release\lzhuf d test_data.lzh test_data.src W:\work\d-rats\lzhuf>fc test_data.src tests/test_data.ref Comparing files test_data.src and TESTS/TEST_DATA.REF FC: no differences encountered
Creating the MSI file
It seems that WIX tools are not part of visual Studio 2012.
They have to be installed from WiX Toolset Releases
There are two downloads, the toolkit and optionally the Visual Studio Extension.
You need to add the WIX tools to your PATH environment variable
# MSBUILD SETUP "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VSDevCmd.bat" # C:\Program Files (x86)\WiX Toolset v3.11\bin set PATH=%PATH%;C:\Program Files (x86)\WiX Toolset v3.11\bin
In creating the .wix files originally several guids need to be generated one time only.
Once the .wix files are created, one for x86 and one for x64, it is just two commands that are needed.
It is possible to use a single .wix file for both. I just have not learned how to do that.
w:\work\d-rats\lzhuf>candle lzhuf_x86.wxs Windows Installer XML Toolset Compiler version 188.8.131.5216 Copyright (c) .NET Foundation and contributors. All rights reserved. lzhuf_x86.wxs w:\work\d-rats\lzhuf>light.exe lzhuf_x86.wixobj Windows Installer XML Toolset Linker version 184.108.40.20616 Copyright (c) .NET Foundation and contributors. All rights reserved.
For 64 Bit note that -arch x64 is needed.
w:\work\d-rats\lzhuf>candle -arch x64 lzhuf_x64.wxs Windows Installer XML Toolset Compiler version 220.127.116.1116 Copyright (c) .NET Foundation and contributors. All rights reserved. lzhuf_x64.wxs w:\work\d-rats\lzhuf>light.exe lzhuf_x64.wixobj Windows Installer XML Toolset Linker version 18.104.22.16816 Copyright (c) .NET Foundation and contributors. All rights reserved.