I recently needed to compile LibreOffice for Windows. And LibreOffice is relying on the MSVC compiler for that, so the straightforward way is to boot up a Windows.
If you have a nice howto for running Visual Studio under Wine / CrossOver / Proton, feel free to send me a link 😉
I’ve heard there used to be MinGW support. But it was dumped because it was ABI incompatible and maintaining two build setups was too much work.
Since I mostly work on Debian GNU/Linux since many years, I had quite some aversion clicking trough Windows setup wizards. I’m trying to keep this howto as short as possible. So here’s the solution I ended up with.
All code snippets posted here are MPLv2/LGPLv3+ dual licensed.
Many bits come from these URLs:
https://wiki.documentfoundation.org/Development/BuildingOnWindows
https://wiki.documentfoundation.org/Development/lode
I put some additional recommendations in italic. But you might ignore them.
1. Windows VM
https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/
I’ve done this with a Windows 11 2024-07 VirtualBox image, extracted it with ZIP and TAR and did a qemu-img convert img.vmdk img.qcow2
to run it tough Qemu/KVM with -bios
pointing to OVMF.fd for UEFI boot (no TPM needed). And I added a second virtual drive with fast if=virtio,cache=unsafe
Qemu settings for the build environment, so I can easily replace a broken Windows drive.
Disable the Windows Defender Real Time Protection. It would likely break the build process.
Admin Powershell:
## Maybe Windows' "Tamper Protection" prevents making some changes via the shell. # disable Windows Defender antivirus (MAPS is cloud protection) Set-MpPreference -DisableRealtimeMonitoring $true Set-MpPreference -MAPSReporting 0 # gpedit.msc > Computer Configuration > Administrative Templates # > Windows Components > Microsoft Defender Antivirus > Real-time Protection # Turn off real-time protection: Enabled # Turn off behaviour monitoring: Enabled # Scan all downloaded files and attachments: Disabled # Monitor file and program activity on your computer: Disabled # Turn of process scanning whenever real-time protection is enabled: Disabled # Turn on script scanning: Disabled # Alternatives: ## https://github.com/ionuttbara/windows-defender-remover ## https://community.chocolatey.org/packages/disabledefender-winconfig ## choco install disabledefender-winconfig ## # after installing Chocolatey, see below
You might like to enable the Qemu SMB guest share.
Enable accessing guest shares in Windows a PowerShell in admin mode:
Set-SmbClientConfiguration -EnableInsecureGuestLogons $true -Force
net use Z: "\\10.0.2.4\qemu" /persistent:yes
Z: will only be visible for processes in admin mode when set up via a PowerShell in admin mode and vice versa.
Finally adjust some helpful things.
1. Disable timed standby / power saving in the Windows settings.
2. Disable Windows password expiration.
cmd: wmic UserAccount where Name="User" set PasswordExpires=False
3. Optional: Install VM guest drivers (Qemu link).
4. Optional: Set keyboard layout and timezone.
2. OpenSSH Installation
Get an OpenSSH server for Windows, so we can do most work from our Unix desktop.
Put this into a PowerShell in admin mode:
Get-WindowsCapability -Online | Where-Object Name -like ‘OpenSSH.Server*’ | Add-WindowsCapability –Online Set-Service -Name sshd -StartupType 'Automatic' New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 Add-Content -Force -Path $env:ProgramData\ssh\administrators_authorized_keys -Value 'YOUR_SSH_PUBKEY_LINE' # AFTER creating the administrators_authorized_keys file icacls.exe "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F" restart-service sshd
3. Cygwin Installation
Download the Cygwin loader to the second drive, called E:
here.
(Cygwin will cache packages for later use in the folder the setup is placed in)
You might need to do this locally, not trough SSH. And again use a PowerShell in admin mode.
setup-x86_64.exe --no-verify --site http://ctm.crouchingtigerhiddenfruitbat.org/pub/cygwin/circa/64bit/2024/01/31/234856 -P autoconf -P automake -P bison -P cabextract -P doxygen -P flex -P gcc-g++ -P gettext-devel -P git -P gnupg -P gperf -P make -P mintty -P nasm -P openssh -P openssl -P patch -P perl -P python -P python3 -P pkg-config -P rsync -P unzip -P vim -P wget -P zip -P perl-Archive-Zip -P perl-Font-TTF -P perl-IO-String -P procps-ng -P screen -P tmux
I recommend installing this to the
As of 2024-07 LibreOffice developers say, that Cygwin-3.4.10 may work better then the current Cygwin-3.5.x. (old releases)
I’ve added some packages at the end, additionally to the recommended ones. procps
contains Htop. For Tmux and Screen see below.
Alternatives for Cygwin installation: PowerShell install script, Chocolatey package
Now configure Windows to start a Tmux session on boot, so we can attach to it via SSH and open windows on the local desktop.
Start Menu -> Search: Task Scheduler -> right click „Task Scheduler Library“ -> Create Task…
Name: tmux
Run with highest privileges: yes
Triggers -> New… ->
— Begin the task: At log on
— Settings: Specific user (should select the normal user)
Actions -> New… -> Action: Start a program, Program/script: E:\cygwin\bin\mintty.exe
— Add arguments:
/Cygwin-Terminal.ico --window max --exec /bin/bash --login -c "while true; do tmux new -As t1; done"
The reboot and see if Cygwin starts :-)
4. Connect to SSH
It’s finally time to leave the Windows UI ;-)
Unfortunately Tmux doesn’t like to start in an Windows SSH session and Screen can’t attach to existing sessions. So the easiest solution was to combine them to compensate 🤪
Connect from your Unix machine with this line:
ssh user@VM_IP_ADDRESS cmd.exe /c 'E:\cygwin\bin\bash.exe' --login -c '"exec env HOME=/home/User screen -S s1 tmux attach -t t1"'
5. Setup JDK, MSVC and more
Through the SSH connection you should be able to install the remaining needed software without hassle. Just use these commands.
First you may disable the annoying Windows updates permanently.
sc config wuauserv start=disabled
I chose to install JDK and some other software trough the Chocolatey package manager.
# Install Chocolatey Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) choco install microsoft-openjdk Gpg4win git ConEmu
git
installs from GitForWindows.org which works faster then the Cygwin build in Git.
Gpg4Win is needed for OpenPGP ODF encryption in LibreOffice.
ConEmu is for convenience if you need to run stuff from the Windows UI.
You may skip the next step and install MSVC (you’ll need to look into the command line options).
MSVC (unfortunately the preinstalled is without C++):
wget https://aka.ms/vs/17/release/vs_community.exe I_PATH='C:\Program Files\Microsoft Visual Studio\2022\Community' ./vs_community.exe modify --passive --installPath "$I_PATH" Microsoft.VisualStudio.Component.NuGet \ Microsoft.VisualStudio.Component.VC.Tools.x86.x64 \ Microsoft.VisualStudio.Component.VC.CoreIde \ Microsoft.VisualStudio.Component.VC.ATL \ Microsoft.Net.Component.4.8.SDK \ Microsoft.VisualStudio.Component.VC.Redist.MSM \ Microsoft.VisualStudio.Component.VC.Llvm.Clang \ Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset \ Microsoft.VisualStudio.Component.Windows11SDK.22000 \ Microsoft.VisualStudio.Component.VC.v142.ATL \ Microsoft.VisualStudio.ComponentGroup.VC.Tools.142.x86.x64 \ Microsoft.VisualStudio.Workload.NativeDesktop ./vs_community.exe modify --passive --wait --installPath "$I_PATH" --addProductLang En-us ./vs_community.exe modify --passive --wait --installPath "$I_PATH" --removeProductLang De-de
6. Build LibreOffice
Finally :-)
git clone https://git.libreoffice.org/core libreoffice cd libreoffice ./autogen.sh --with-visual-studio=2022 --disable-ccache --without-doxygen --enable-debug --with-parallelism=$(nproc --ignore=1) && time nice make # run LibreOffice :-) ./instdir/program/soffice.exe
When you’ve had enough from Windows you may shut it down via: shutdown /r /t 10
Abort shutdown via: shutdown /a