From 1e86bc674b332a774c507b751650dd0ade879f97 Mon Sep 17 00:00:00 2001 From: Max Gaukler Date: Sun, 30 Jun 2024 20:00:06 +0200 Subject: [PATCH] Windows: Automate installing build dependencies Building Inkscape on Windows currently takes much more manual effort than on Linux. A new script `buildtools/windows-deps-clickHere.bat` reduces the effort because it automates the installation steps described on the "Compiling Inkscape on Windows" wiki page: - Install MSYS and WiX v4 (incl. DotNet SDK) using WinGet - Run all MSYS upgrades - Run msys2installdeps.sh in UCRT64 shell. Within this script, NSIS and 7zip were added. The script can also be run again later to install MSYS updates. --- buildtools/.gitattributes | 3 ++ buildtools/msys2installdeps.sh | 6 +++ buildtools/windows-deps-clickHere.bat | 34 ++++++++++++ buildtools/windows-deps-install-wix4.ps1 | 48 ++++++++--------- buildtools/windows-deps-part2.ps1 | 69 ++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 24 deletions(-) create mode 100644 buildtools/.gitattributes create mode 100644 buildtools/windows-deps-clickHere.bat create mode 100644 buildtools/windows-deps-part2.ps1 diff --git a/buildtools/.gitattributes b/buildtools/.gitattributes new file mode 100644 index 0000000000..88fa462db9 --- /dev/null +++ b/buildtools/.gitattributes @@ -0,0 +1,3 @@ +windows-deps-*.bat eol=crlf +windows-deps-*.ps1 eol=crlf + diff --git a/buildtools/msys2installdeps.sh b/buildtools/msys2installdeps.sh index 02b06e8bf5..62e6a2de6d 100644 --- a/buildtools/msys2installdeps.sh +++ b/buildtools/msys2installdeps.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e # ------------------------------------------------------------------------------- # This script installs all dependencies required for building Inkscape with MSYS2. # @@ -69,6 +70,11 @@ $ARCH-gtk4 \ $ARCH-gtk-doc \ $ARCH-gtkmm4 +# install packaging tools (required for dist-win-* targets) +eval pacman -S $PACMAN_OPTIONS \ +$ARCH-7zip \ +$ARCH-nsis + # install Inkscape dependencies (optional) eval pacman -S $PACMAN_OPTIONS \ $ARCH-poppler \ diff --git a/buildtools/windows-deps-clickHere.bat b/buildtools/windows-deps-clickHere.bat new file mode 100644 index 0000000000..0941970b27 --- /dev/null +++ b/buildtools/windows-deps-clickHere.bat @@ -0,0 +1,34 @@ +:: SPDX-License-Identifier: GPL-v2-or-later +:: +:: This script installs/upgrades everything needed to compile Inkscape on Windows with one click. +:: It automates the dependency installation described on the "Compiling Inkscape on Windows" wiki page. +:: See the "echo" lines at the start of the script for details. +:: +:: Limitations: +:: - Only suitable for interactive use because it asks for user input in a few cases (before script exit, and at certain errors). +:: - Error checking is not implemented, the script will often just silently try to continue. +:: - Only for MINGW64 (x86_64) architecture +:: +:: To run the script, just double-click on the windows-deps-clickHere.bat file. +:: +@echo off +echo Automatic installation/update of Inkscape build dependencies for Windows. +echo. +echo This script will download the following software and install it, partly with Administrator rights: +echo - MSYS2 https://msys2.org/ +echo - many MSYS2 packages, see ./msys2installdeps.sh +echo - Microsoft DotNet SDK +echo - WiX https://wixtoolset.org/ +echo. +echo Do you want to continue? Press Enter to continue. Close the window to abort. +echo. +pause + +:: set $CDSHORTPATH to the DOS 8.3 shortpath of the current directory (to get rid of spaces) +FOR %%I IN ("%CD%") DO SET "cdshortpath=%%~sI" + +echo "Starting part 2 with Administrator rights..." +:: We don't use -Wait because sometimes, at the end of the powershell script, the PS window closes but the process doesn't exit. +powershell -Command "Start-Process powershell -Verb runAs -ArgumentList '-ExecutionPolicy','bypass','-File','%cdshortpath%\windows-deps-part2.ps1'" + +timeout 5 diff --git a/buildtools/windows-deps-install-wix4.ps1 b/buildtools/windows-deps-install-wix4.ps1 index d7361f4f7c..bdc0d2e5c3 100644 --- a/buildtools/windows-deps-install-wix4.ps1 +++ b/buildtools/windows-deps-install-wix4.ps1 @@ -1,24 +1,24 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# -# Installation of WiX v4 toolset for building Windows .MSI packages. -# -# Run this as admin! - -# Install DotNet runtime -winget install --accept-package-agreements --accept-source-agreements Microsoft.DotNet.SDK.8 - -# determine path to MSYS. For normal developers, it is C:\msys64. For CI it is C:\%IDW_NAME%. Other values can be set with the MSYS environment variable. -$MSYS = $Env:MSYS -if (-not $MSYS) { - if ($Env:IDW_NAME) { - $MSYS = "C:\" + $Env:IDW_NAME - } else { - $MSYS = "C:\msys64" - } -} - -# install WiX in a path where MSYS finds it -$WIXPATH = $MSYS + "\usr\local\bin\" -$Env:DOTNET_CLI_TELEMETRY_OPTOUT = "1" -dotnet tool install wix --version 4.0.4 --tool-path $WIXPATH -& "$WIXPATH\wix" extension add --global WixToolset.UI.wixext/4.0.4 +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Installation of WiX v4 toolset for building Windows .MSI packages. +# +# This script is used both by the CI (.gitlab-ci.yml) and for manual installation (main script: windows-deps-clickHere.bat) + +# Install DotNet runtime +winget install --accept-package-agreements --accept-source-agreements Microsoft.DotNet.SDK.8 + +# determine path to MSYS. For normal developers, it is C:\msys64. For CI it is C:\%IDW_NAME%. Other values can be set with the MSYS environment variable. +$MSYS = $Env:MSYS +if (-not $MSYS) { + if ($Env:IDW_NAME) { + $MSYS = "C:\" + $Env:IDW_NAME + } else { + $MSYS = "C:\msys64" + } +} + +# install WiX in a path where MSYS finds it +$WIXPATH = $MSYS + "\usr\local\bin\" +$Env:DOTNET_CLI_TELEMETRY_OPTOUT = "1" +dotnet tool install wix --version 4.0.4 --tool-path $WIXPATH +& "$WIXPATH\wix" extension add --global WixToolset.UI.wixext/4.0.4 diff --git a/buildtools/windows-deps-part2.ps1 b/buildtools/windows-deps-part2.ps1 new file mode 100644 index 0000000000..e2bc330015 --- /dev/null +++ b/buildtools/windows-deps-part2.ps1 @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: GPL-v2-or-later +# +# Part of the Inkscape Windows dependency installation. +# For the main script, see windows-deps-clickHere.bat +# +# This script assumes to be started with Admin permissions. + + +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +cd $scriptDir + + +echo "Part 2. Installing MSYS2" +winget install --accept-package-agreements --accept-source-agreements MSYS2.MSYS2 + +echo "Installing WiX v4 and DotNetSDK (for building MSI installer)" +& .\windows-deps-install-wix4.ps1 + +function RunInMsys { + # Run command in msys terminal window and wait for it to to finish + param ( + # MSYS architecture: MSYS2 / UCRT64 / MINGW64 + $msysArch, + # shell command to be run + $cmd + ) + # Ensure no mintty.exe is running -- otherwise the check later will be stuck + while (Get-Process mintty -ErrorAction SilentlyContinue) { + Start-Sleep 1 + echo "Please close all open MSYS terminals so that this script can continue." + } + + echo "Running in MSYS $msysArch terminal: $cmd" + + $cmd = $cmd + " && echo Ok. The window will close in 5 seconds. && sleep 5 || (echo Error. Press Enter to exit; read)" + &"C:\msys64\${msysArch}.exe" bash -c $cmd + # wait until mintty window has opened (dirty hack) + Start-Sleep 5 + # Wait until mintty (terminal window) spawned by MSYS has finished + echo "Waiting until all MSYS tasks have finished..." + while (Get-Process mintty -ErrorAction SilentlyContinue) { + Start-Sleep 1 + } +} + +# call MSYS system upgrade repeatedly. If the dependencies were already installed before, then this will upgrade everything. Repeating is needed because sometimes MSYS doesn't upgrade everything at once. +Echo "Running MSYS system upgrade multiple times..." +For ($i=0; $i -lt 5; $i += 1) +{ + RunInMsys "MSYS2" "pacman --noconfirm -Syuu" +} + +# start msys2installdeps.sh +Echo "Installing Inkscape build dependencies" +RunInMsys "UCRT64" "./msys2installdeps.sh" + +Write-Host "" +Write-Host "" +Write-Host "" +Write-Host "Everything is installed that you need to compile Inkscape." -ForegroundColor Green +Write-Host "" +Write-Host "Done :-) Press Enter to exit." -ForegroundColor Green + +# Print some empty lines because Windows sometimes places the PS window such that the bottom is hidden by the taskbar. +For ($i=0; $i -lt 10; $i += 1) +{ + echo "" +} +Read-Host -- GitLab