From f2c09c025080b61250c10781ebf4977ef4d63a87 Mon Sep 17 00:00:00 2001 From: Max Gaukler Date: Sun, 2 Nov 2025 10:18:26 +0100 Subject: [PATCH 1/3] Refactor windows build dependency installer Refactor `windows-deps-part2.ps1` to make it easier to automate --- buildtools/windows-deps-clickHere.bat | 2 +- buildtools/windows-deps-part2.ps1 | 33 +++++++++------------------ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/buildtools/windows-deps-clickHere.bat b/buildtools/windows-deps-clickHere.bat index 0941970b27..791467cce5 100644 --- a/buildtools/windows-deps-clickHere.bat +++ b/buildtools/windows-deps-clickHere.bat @@ -29,6 +29,6 @@ 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'" +powershell -Command "Start-Process powershell -Verb runAs -ArgumentList '-NoExit','-ExecutionPolicy','bypass','-File','%cdshortpath%\windows-deps-part2.ps1'" timeout 5 diff --git a/buildtools/windows-deps-part2.ps1 b/buildtools/windows-deps-part2.ps1 index e2bc330015..b597468f97 100644 --- a/buildtools/windows-deps-part2.ps1 +++ b/buildtools/windows-deps-part2.ps1 @@ -17,29 +17,19 @@ 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 + # Run command in msys shell param ( - # MSYS architecture: MSYS2 / UCRT64 / MINGW64 - $msysArch, - # shell command to be run - $cmd + # MSYS architecture: MSYS2 / UCRT64 / MINGW64 + $MSYSVariant, + # shell command to be run + $Command ) - # 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 + echo "Running in MSYS $MSYSVariant terminal: $Command" + + & C:/msys64/usr/bin/env.exe CHERE_INVOKING=1 MSYSTEM=$MSYSVariant /usr/bin/bash -lc "$Command" + if (-Not $?) { + throw "Running command in MSYS $MSYSVariant shell failed: $Command" } } @@ -59,11 +49,10 @@ 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 +Write-Host "Done :-) Close the window 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 From 2e4f6cd1c77b841ac2b40903ba9596780db9c9ce Mon Sep 17 00:00:00 2001 From: Max Gaukler Date: Sun, 2 Nov 2025 10:18:36 +0100 Subject: [PATCH 2/3] Add script to setup full Windows dev environment Add a reproducible "one-click" alternative available to set up a whole development environment for Inkscape on Windows: 1. Set up VSCode 2. Set up Inkscape dependencies 3. Check out and compile Inkscape We offer a script to run on any Windows PC, and also a VM configuration for Vagrant to set up a complete Win11 development VM from scratch. **Motivation**: Users have to follow several manual steps to get started with Inkscape development on Windows or to reproduce problems with the Windows build dependencies. Before this change, only the dependency installation (step 2 from the above list) was automated, the rest was manual. Now, we offer a script that does everything. Use-Cases: 1. As an experienced developer, I want to triage issues that the build instructions are not working: Just run a one-line command `vagrant destroy; vagrant up`. After two hours of waiting I have a fresh VM with the same result as if I had manually followed through all the instructions in `windows.md`. 2. As a new and unexperienced developer, I want to play around debugging Inkscape on Windows but I am overwhelmed by the long instructions. Now I can just click on `windows-installFullDevEnv-clickHere.bat`, do something else for two hours, and come back to a VSCode window with Inkscape source and press F5 to start debugging. 3. I don't want to use the new magic stuff but still do it manually. This is still possible. --- buildtools/windows-dev-vm/.gitignore | 1 + buildtools/windows-dev-vm/README.md | 83 +++++++ buildtools/windows-dev-vm/Vagrantfile | 168 ++++++++++++++ .../windows-installFullDevEnv-clickHere.bat | 42 ++++ .../windows-installFullDevEnv-part2.ps1 | 211 ++++++++++++++++++ doc/building/windows.md | 63 +++++- 6 files changed, 558 insertions(+), 10 deletions(-) create mode 100644 buildtools/windows-dev-vm/.gitignore create mode 100644 buildtools/windows-dev-vm/README.md create mode 100644 buildtools/windows-dev-vm/Vagrantfile create mode 100644 buildtools/windows-installFullDevEnv-clickHere.bat create mode 100644 buildtools/windows-installFullDevEnv-part2.ps1 diff --git a/buildtools/windows-dev-vm/.gitignore b/buildtools/windows-dev-vm/.gitignore new file mode 100644 index 0000000000..a977916f65 --- /dev/null +++ b/buildtools/windows-dev-vm/.gitignore @@ -0,0 +1 @@ +.vagrant/ diff --git a/buildtools/windows-dev-vm/README.md b/buildtools/windows-dev-vm/README.md new file mode 100644 index 0000000000..d7071b8896 --- /dev/null +++ b/buildtools/windows-dev-vm/README.md @@ -0,0 +1,83 @@ +# Development environment VM for Inkscape on Windows 11 + +*Experimental. Only recommended for advaced developers.* This page explains how to *automatically* set up a *reproducible* Windows VM for developing Inkscape, using [Vagrant](https://developer.hashicorp.com/vagrant/install). + +The automatic setup includes: +- Creating a new VM +- Installing Windows +- Running `buildtools/windows-installFullDevEnv-clickHere.bat` to set up the [development environment for Inkscape on Windows](../../doc/building/windows.md), which includes: +- Installing all build dependencies +- Compiling Inkscape and running it +- Setting up VSCode and opening it + +The benefit is that you can destroy and re-create the environment with just one command. This is especially helpful for reproducing bugs in the build instructions. The downside is that you need extra tools and add another layer of complexity. + +As a manual alternative, simply follow the instructions for [Compiling Inkscape on Windows](../../doc/building/windows.md) by hand. + +# Basic Information + +## Requirements +- Windows or Linux Host PC with at least 16 GB RAM, 100 GB free disk space, CPU new enough to run latest Windows +- It may work with less. + +## Caution +- You agree to the license terms of the used dependencies, especially of Windows, VirtualBox and Vagrant. +- The VM is based on a Vagrant image from a third party. It seems that Vagrant does not guarantee isolation of the host from malicious Vagrant images. If you are paranoid you could put Vagrant itself inside a VM (nested virtualization). + +## Hyper-V vs. VirtualBox / Limitations for Windows Hosts +You can use VirtualBox or Microsoft Hyper-V as virtualization tool. The following instructions explain both. + +*If your (host) PC is running Linux:* Use VirtualBox. Note that VirtualBox does not work together with KVM-based virtualization. The instructions here do not yet support KVM. + +*If your (host) PC is running Windows:* + +Using VirtualBox is easier but typically much slower than Hyper-V. + +VirtualBox conflicts with the Microsoft Hyper-V virtualization tool that is part of Windows. The "slow mode" of VirtualBox is shown by a green turtle icon in the bottom of the VirtualBox window. Disabling Hyper-V is possible but [quite complicated with newer versions of Windows](https://superuser.com/questions/1778061/green-turtle-snail-mode-slow-performance-indicator-on-virtualbox-vm) and can disable other Windows features such as WSL. + + +Hyper-V is more difficult because it is not well supported by Vagrant, the tool that we use to automate setting up the VM. The loosely related project ["chocolatey-test-environment"](https://github.com/chocolatey-community/chocolatey-test-environment/blob/ba08f73a1a3c07974ff8872ba0c0ad04fb4acb34/ReadMe.md#using-hyper-v-instead-of-virtualbox) can be a starting point for research. + +## Initial setup +0. Install [VirtualBox](https://www.virtualbox.org/wiki/Downloads) or [Hyper-V](https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/get-started/Install-Hyper-V?tabs=powershell&pivots=windows) - choose as described above. +0. Install [Vagrant](https://developer.hashicorp.com/vagrant/install) +0. Get the `buildtools/windows-dev-vm` folder of the Inkscape repository +0. Open a terminal in that folder + - For Hyper-V: Use administrative Terminal (right click on the start menu and select "Terminal (Administrator)"). +0. Set up the dev VM: + - For VirtualBox: Set up the dev VM with `vagrant up` (VirtualBox). Progress output will mostly be shown in the terminal. Some messages will also be shown in the graphical VM itself. A VirtualBox window will open automatically and show the screen of the VM. + - For Hyper-V: Similar to VirtualBox, but: + - Start the VM with `vagrant up --provider hyperv`. + - In the start menu, start "Hyper-V manager" and open the newly created VM to see its screen.) +0. If everything is successful, the command will finish and show "Done." as last line. +0. VSCode will open with the Inkscape project. Please accept "Yes, I trust the authors" (of the Inkscape folder) when asked by VSCode. +0. The compiled Inkscape will open. + +## Usage after setup +(If you use Hyper-V, add ` --provider hyperv` to all `vagrant up` commands in the following explanations.) + +### Start +- If the VM is not running, use `vagrant up` to start it. Log in with password "vagrant". +- The Inkscape git repository is in `C:/Users/Vagrant/inkscape`. Note that this folder is called `master` in the Inkscape developer documentation. +- VSCode: Open that folder. +- or: Command line: Open "UCRT64" from the start menu and `cd /c/Users/Vagrant/inkscape` +- The compiled Inkscape EXE is in `C:/Users/Vagrant/inkscape/install_dir/bin/inkscape.exe` +- To connect into the VM (like SSH): `vagrant ssh`, then `powershell` + +### Reset +- Re-trigger the setup with `vagrant up; vagrant provision`. This is a "quick-and-dirty" approach --- it tries to continue from the previous state but will not always do that reliably. +- To recreate the VM from scratch, deleting all data inside the VM (!!!): `vagrant destroy; vagrant up`. This is cleanly reproducible. **Caution**: Any changes to the Inkscape sourcecode that you did inside the VM will be lost. Double-check that you committed and pushed them or have some other backup. + +### Stop / Uninstall +- Shut down the VM graphically or with `vagrant halt`. +- To delete the VM (including all data !!!): `vagrant destroy`. **Caution**: Any changes to the Inkscape sourcecode that you did inside the VM will be lost. +- To also free the disk space taken by the the VM base image: `vagrant box remove gusztavvargadr/windows-11` + +# Advanced Information + +## Customization +- Optionally, edit the `Vagrantfile` to adjust VM settings like RAM, CPU, clipboard, drag-and-drop and shared folders. + - For Hyper-V: when using shared folders, Vagrant will ask you for the username and password of your host PC to set up the shares. +- For non-english keyboard layout, search for "keyboard" in the Vagrantfile and adjust accordingly. + +## Troubleshooting diff --git a/buildtools/windows-dev-vm/Vagrantfile b/buildtools/windows-dev-vm/Vagrantfile new file mode 100644 index 0000000000..7447a70f46 --- /dev/null +++ b/buildtools/windows-dev-vm/Vagrantfile @@ -0,0 +1,168 @@ +# -*- mode: ruby -*- +# SPDX-License-Identifier: Apache-2.0 +# vi: set ft=ruby : + +# Partly based on chocolatey-test-environment Vagrantfile +# https://github.com/chocolatey-community/chocolatey-test-environment/blob/master/Vagrantfile +# which is (C) Present RealDimensions Software, LLC and licensed Apache-2.0 + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://vagrantcloud.com/search. + config.vm.box = "gusztavvargadr/windows-11" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # NOTE: This will enable public access to the opened port + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine and only allow access + # via 127.0.0.1 to disable public access + # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + # config.vm.synced_folder "../data", "/vagrant_data" + + # Disable the default share of the current code directory. Doing this + # provides improved isolation between the vagrant box and your host + # by making sure your Vagrantfile isn't accessible to the vagrant box. + # If you use this you may want to enable additional shared subfolders as + # shown above. + config.vm.synced_folder ".", "/vagrant", disabled: true, SharedFoldersEnableSymlinksCreate: false + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + # config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + # vb.memory = "1024" + # end + + # a long boot timeout is needed for slow host systems + config.vm.boot_timeout = 1800 + # to avoid WinRM errors in the middle of booting, we ensure that (max_tries * retry_delay) > boot_timeout: + config.winrm.max_tries = 900 + config.winrm.retry_delay = 2 + + # http://docs.vagrantup.com/v2/providers/configuration.html + # http://docs.vagrantup.com/v2/virtualbox/configuration.html + # Configuration when using VirtualBox + config.vm.provider :virtualbox do |v, override| + # Show the GUI + v.gui = true + # 10GB RAM + v.customize ["modifyvm", :id, "--memory", "10000"] + # 2 CPUs (note: with more CPUs you may need even more RAM) + v.customize ["modifyvm", :id, "--cpus", "2"] + # Video RAM is 32 MB + v.customize ["modifyvm", :id, "--vram", 32] + # For better DNS resolution + v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] + # No audo + v.customize ["modifyvm", :id, "--audio", "none"] + + v.customize ["modifyvm", :id, "--clipboard", "disabled"] + v.customize ["modifyvm", :id, "--draganddrop", "disabled"] + # Clipboard enabled + # v.customize ["modifyvm", :id, "--clipboard", "bidirectional"] + # v.customize ["modifyvm", :id, "--draganddrop", "hosttoguest"] + # For performance + v.customize ["modifyvm", :id, "--usb", "off"] + # Huge performance gain here + v.linked_clone = true if Vagrant::VERSION >= '1.8.0' + end + + # Configuration when using Hyper-V + # https://www.vagrantup.com/docs/hyperv/configuration.html + # https://technet.microsoft.com/en-us/library/dn798297(v=ws.11).aspx + config.vm.provider :hyperv do |v, override| + # 4GB RAM + v.memory = 10000 + v.maxmemory = nil + # 2 CPUs + v.cpus = 2 + # The time in seconds to wait for the virtual machine to report an IP address + v.ip_address_timeout = 240 + # Use differencing disk instead of cloning whole VHD + if Vagrant::VERSION >= '2.1.2' + v.linked_clone = true + else + v.differencing_disk = true + end + v.vm_integration_services = { + guest_service_interface: true, + heartbeat: true, + key_value_pair_exchange: true, + shutdown: true, + time_synchronization: true, + vss: true + } + end + + # + # View the documentation for the provider you are using for more + # information on available options. + + # Enable provisioning with a shell script. Additional provisioners such as + # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the + # documentation for more information about their specific syntax and use. + # config.vm.provision "shell", inline: <<-SHELL + # apt-get update + # apt-get install -y apache2 + # SHELL + + # Enable auto login + script_autologin = <<'SHELL' + Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'AutoAdminLogon' -Value '1'; + Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'DefaultUserName' -Value 'Vagrant'; + Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'DefaultPassword' -Value 'vagrant'; + Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'AutoLogonCount' -Value '9999999999999'; +SHELL + config.vm.provision "shell", inline: script_autologin, powershell_elevated_interactive: true + + + # Set keyboard layout and language (Example: German keyboard but English language in Windows = en-DE) + # --> Adjust the following line to your need (replacing 'en-DE') and remove the comment sign '#'. + # The keyboard layout will become active after the next reboot. + # config.vm.provision "shell", inline: "Set-WinUserLanguageList -Force -LanguageList en-DE" + + + # Copy Inkscape buildtools folder + # WORKAROUND Vagrant bug: ensure the folder already exists (otherwise the content gets copied into the destionation folder at first run, and at second runs into the buildtools/ subfolder of the destination) + config.vm.provision "shell", inline: "mkdir -force C:/inkscape-buildtools-tmp/" + config.vm.provision "file", source: "..", destination: "C:/inkscape-buildtools-tmp" + + # Setup Inkscape development environment + config.vm.provision "shell", inline: "& C:/inkscape-buildtools-tmp/buildtools/windows-installFullDevEnv-part2.ps1", powershell_elevated_interactive: true +end diff --git a/buildtools/windows-installFullDevEnv-clickHere.bat b/buildtools/windows-installFullDevEnv-clickHere.bat new file mode 100644 index 0000000000..2118481888 --- /dev/null +++ b/buildtools/windows-installFullDevEnv-clickHere.bat @@ -0,0 +1,42 @@ +:: SPDX-License-Identifier: GPL-v2-or-later +:: +:: This script sets up a whole Inkscape development environment on Windows, including VSCode, and compiles Inkscape. +:: +:: To run the script, just double-click on this .bat file. +:: +:: For customization, please edit the configuration in windows-installFullDevEnv-part2.ps1 . +:: +:: For more information please read the following "echo" lines: +:: +@echo off +echo Automatic installation/update of Inkscape development environment, including VSCode. +echo. +echo For documentation please see doc/building/windows.md and windows-installFullDevEnv-part2.ps1 . +echo. +echo This script will set up a complete Inkscape development environment. +echo - Get sourcecode +echo - Install dependencies +echo - Compile and run Inkscape +echo - Install and set up VSCode +echo. +echo This script will download the following software and install it, partly with Administrator rights: +echo - Microsoft WinGet +echo - Git for Windows +echo - Microsoft VSCode and its CPP Extension Pack +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 '-NoExit','-ExecutionPolicy','bypass','-File','%cdshortpath%\windows-installFullDevEnv-part2.ps1'" + +timeout 5 diff --git a/buildtools/windows-installFullDevEnv-part2.ps1 b/buildtools/windows-installFullDevEnv-part2.ps1 new file mode 100644 index 0000000000..8f7f290a1d --- /dev/null +++ b/buildtools/windows-installFullDevEnv-part2.ps1 @@ -0,0 +1,211 @@ +# SPDX-License-Identifier: GPL-v2-or-later +# Set up a complete development environment for Inkscape on Windows: +# - Install all build dependencies +# - Download and compile latest Inkscape source +# - Run the compiled Inkscape +# - Install and setup VSCode +# +# This script must be started with Admin permissions. + + +###################### +# USER CONFIGURATION +###################### + +# Note: The script works out of the box without any changes. +# The default values give a result as if you follow the compilation instructions manually. (See doc/building/windows.md) +# If you have special wishes, you can change the configuration here. + +# Git URL to Inkscape repository +$InkscapeGitURL = "https://gitlab.com/inkscape/inkscape.git" + +# Git Branch of Inkscape repository +$InkscapeGitBranch = "master" + +# Local folder for Inkscape source repository. +# If the folder does not exist yet, the repository will be downloaded automatically. +# Default: C:\msys64\home\your_username\inkscape +$InkscapeRepository = "C:/msys64/home/$env:USERNAME/master/" + +# Install VSCode and copy the configuration for Inkscape? +$SetupVSCode = $true + +# Install latest Inkscape dependencies via MSYS? +$SetupMSYS = $true +# Path to MSYS installation or to prepackaged inkscape dependencies (unpack .7Z file from https://gitlab.com/inkscape/infra/inkscape-ci-windows/-/releases .) +# (Do NOT modify if $SetupMSYS == true) +# TODO: Add option to automatically download the prepackaged 7Z +$MSYSPath = "C:/msys64/" +# MSYS Environment variant, e.g. UCRT64 https://www.msys2.org/docs/environments/ +$MSYSVariant = "UCRT64" + + +###################### +# PowerShell general configuration +###################### + +$ErrorActionPreference = "Stop" +$PSNativeCommandUseErrorActionPreference = $true +Set-PSDebug -Trace 1 + +###################### +# Auxiliary functions +###################### + +# Test if a command (e.g., "git") is available on the PATH +function Test-CommandExists { + param ( + $Command + ) + [bool] (Get-Command -ErrorAction Ignore -Type Application $Command) +} + +# Run in MSYS shell +function Start-MsysCommand { + param ( + $Command + ) + echo "Running command in MSYS $MSYSVariant shell: $Command" + & $MSYSPath/usr/bin/env.exe CHERE_INVOKING=1 MSYSTEM=$MSYSVariant /usr/bin/bash -lc "$Command" + if (-Not $?) { + throw "Running command in MSYS $MSYSVariant shell failed: $Command" + } +} + +###################### +# 0. Compatibility Check +###################### + +if (-Not ($env:PROCESSOR_ARCHITECTURE -eq "AMD64")) { + throw "This script currently only works on x64 architecture. (FIXME: Auto-detect and set MSYSVariant, then remove this check)" +} + + +###################### +# 1. Dependencies and Inkscape source +###################### + +# Install WinGet +if (-Not (Test-CommandExists winget)) { + # see https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget + Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe +} + +# Install Git for Windows, outside MSYS (needed by VSCode) +If (-Not (Test-CommandExists git)) { + winget install --accept-package-agreements --accept-source-agreements git.git + # work around a bug in winget https://github.com/microsoft/winget-cli/issues/222 (fixed in the latest beta) + $env:PATH += ";C:/Program Files/git/cmd/" +} + +# Run the core part of buildtools/windows-deps-clickHere.bat +# Note: We use the version from the directory of the current script, not the version from the Inkscape git repo. +# This is to simplify local development of this script. +& $PSScriptRoot/windows-deps-part2.ps1 + +# Clone Inkscape git repo if it doesn't exist yet +if (-Not (Test-Path $InkscapeRepository/)) { + & git clone --recurse-submodules "$InkscapeGitURL" --branch "$InkscapeGitBranch" "$InkscapeRepository" + if (-Not $?) { + throw "git clone failed" + } +} +# Check for complete checkout - are the files inside the submodules also available? +if (-Not (Test-Path $InkscapeRepository/share/extensions/README.md)) { + throw "Repository folder $InkscapeRepository exists but is not a complete Inkscape source repository (including submodules). Suggested solution: Delete (or rename) the folder and restart the script, so that the repository is downloaded again." +} + + +###################### +# 2. Setup VSCode +###################### + +if ($SetupVSCode) { + # Install VSCode if not yet installed + if (-Not (Test-CommandExists "code")) { + winget install --accept-package-agreements --accept-source-agreements Microsoft.VisualStudioCode + # work around a bug in winget https://github.com/microsoft/winget-cli/issues/222 (fixed in the latest beta) + $env:PATH += ";$env:LOCALAPPDATA/Programs/Microsoft VS Code/bin/" + } + + # Copy VSCode configuration to .vscode in repository if not already present + cd $InkscapeRepository + if (-Not (Test-Path .vscode/launch.json)) { + mkdir -force .vscode + cp doc/vscode/*.json .vscode/ + } + + code --install-extension ms-vscode.cpptools-extension-pack +} + +###################### +# 3. Compile Inkscape +###################### + +# Build Inkscape +cd $InkscapeRepository +mkdir -force build +cd build + +Start-MsysCommand 'cmake -G Ninja -DCMAKE_INSTALL_PREFIX="${PWD}/install_dir" -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DWITH_INTERNAL_2GEOM=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..' +try { + Start-MsysCommand "ninja install" +} catch { + # If compiling fails, we may have hit the RAM limit. This happens e.g. if you have 6 CPU cores but only 10 GB RAM. + # Retry with just one parallel job. + Start-MsysCommand "ninja -j1 install" +} +if (-Not (Test-Path install_dir/bin/inkscape.exe)) { + throw "Compilation failed." +} + + + +###################### +# 4. Open Inkscape in VSCode +###################### + +if ($SetupVSCode) { + & code $InkscapeRepository +} + +###################### +# 5. Run Inkscape +###################### + +# Check that Inkscape can be launched +If (-Not (./install_dir/bin/inkscape.com --version | Select-String -Pattern "Inkscape")) { + # open the bin folder with Explorer + Invoke-Item ./install_dir/bin/ + throw "Inkscape was compiled but can not be started. Please try to start $InkscapeRepository/build/install_dir/bin/inkscape.exe manually and check for error messages." +} + +# Open Inkscape GUI +& ./install_dir/bin/inkscape.exe + +###################### +# 6. Show success message +###################### + +Set-PSDebug -Trace 0 + +$doneMessage = @" + +Inkscape source code is in $InkscapeRepository . +Inkscape binary was compiled and is in $InkscapeRepository/install_dir/bin/inkscape.exe + +VSCode: Open $InkscapeRepository with VSCode. + +MSYS Commandline: MSYS $MSYSVariant Shell is in $MSYSPath/$MSYSVariant.exe . +(Note: Within MSYS, the windows path C:\...\ must be written as '/c/.../' . ). + +Done :-) -- Close the window to exit. +"@ + +Write-Host "$doneMessage" -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 "" +} diff --git a/doc/building/windows.md b/doc/building/windows.md index fcd80aec66..5c60a9f507 100644 --- a/doc/building/windows.md +++ b/doc/building/windows.md @@ -4,9 +4,43 @@ This page explains how to compile Inkscape on Windows. We use [**MSYS2**](http://www.msys2.org/), which provides all necessary build tools and dependencies. -## Installing Build Dependencies Easily +You have the choice between doing this automatically in one click or manually step-by-step. + +## Automatic "One-Click Solution" + +To quickly set up a complete development environment and compile Inkscape, we offer a one-click script. + +This will automatically perform all steps explained in the following chapters, with the same result as if you followed them manually: + +- Install build dependencies +- Obtain Inkscape sourcecode +- Build Inkscape +- Run Inkscape +- Set up VSCode as editor -In the basic case, you can install all the needed tools with a one-click script. This is supported for Inkscape 1.5 or newer, running on standard 64bit Windows (not ARM). In other cases, please see below "Installing Build Dependencies Manually". + +1. Get the buildtools folder from the Inkscape git repository. One way to do this is the following: + * Download the following ZIP [https://gitlab.com/inkscape/inkscape/-/archive/master/inkscape-master.zip?path=buildtools](https://gitlab.com/inkscape/inkscape/-/archive/master/inkscape-master.zip?path=buildtools) + * Unpack it +2. Double-click on `windows-installFullDevEnv-clickHere.bat` + * If you get a warning "Windows protected your PC. Microsoft Defender prevented an unrecognized app from starting.", click on "More information" and "Run anyway". + * Follow the instructions in the Terminal window. (Press Enter to confirm.) + * Confirm Administrator rights if Windows asks you to +3. Wait many hours until the script says Done. During this time **please read the Chapter "Manually, Step-by-step" to understand what the script does and where you can find the output. + +### Development VM + +*Only for advanced developers:* + +If want a completely reproducible development environment that can be easily destroyed and re-created, you can also [automatically set up a virtual machine](../buildtools/windows-dev-vm/README.md). + +## Manually Step by Step + +For better understanding, you can do the parts step by step. + +### Installing Build Dependencies Easily + +In the basic case, you can install all the tools needed for compiling Inkscape with a one-click script. This is supported for Inkscape 1.5 or newer, running on standard 64bit Windows (not ARM). In other cases, please see below "Installing Build Dependencies Manually". 1. Get the buildtools folder from the Inkscape git repository. One way to do this is the following: * Download the following ZIP [https://gitlab.com/inkscape/inkscape/-/archive/master/inkscape-master.zip?path=buildtools](https://gitlab.com/inkscape/inkscape/-/archive/master/inkscape-master.zip?path=buildtools) @@ -17,7 +51,7 @@ In the basic case, you can install all the needed tools with a one-click script. * Confirm Administrator rights if Windows asks you to 3. Wait a few hours until the script says Done. Then you can compile Inkscape as described below. -## Obtaining Inkscape Source +### Obtaining Inkscape Source As MSYS2 provides the version control software Git, you do not need to download it separately. @@ -38,7 +72,7 @@ You can later update it with: git pull --recurse-submodules ``` -## Building Inkscape with MSYS2 +### Building Inkscape with MSYS2 * **Read carefully:** To compile Inkscape open the MSYS2 **UCRT64** (!!!) shell from the start menu (or launch C:\\msys64\\ucrt64.exe) * ⚠️ _Warning:_ Using the right shell type is important so that the right type of Inkscape is built and the right dependencies are installed: @@ -81,11 +115,13 @@ ninja install _**That's it!**_ Afterwards, you should have a complete binary distribution of Inkscape in the folder "build/install_dir/" that can be run on any machine running Windows 8.1 or later. -## Running Inkscape +### Running Inkscape Simply execute `inkscape.exe` from the "build/**install_dir**/bin" directory (not "build/bin") created in the previous step. (The `ninja install` command takes care of copying all required files into this directory.) -## Packaging +## Optional Steps + +### Packaging If you only want to run Inkscape, you do _not_ need to follow these instructions. See "Running Inkscape" above. @@ -98,16 +134,22 @@ To package those files for distribution (to give it to other people, or make a s For some additional details which have not been incorporated into this page yet, see the previous instructions at https://wiki.inkscape.org/wiki/Compiling_Inkscape_on_Windows_32-bit#Creating_an_installer (mostly outdated). -## Installing +### Installing To install the self-built Inkscape, generate an EXE or MSI installer as described above and run it. +## Setting up VSCode as Editor + +See [VSCode Configuration](../vscode/readme.md). + ## See also - [Contributing and Developing](../../CONTRIBUTING.md) - [Advanced Information on Compiling Inkscape](doc/build/general_advanced.md) ## Troubleshooting +☎ _If you can't solve your issue, please [ask in the chat](https://chat.inkscape.org/channel/team_devel) or [report a bug](https://inkscape.org/report)_. + ### Issues with MSYS2 The MSYS2 shell does not open. @@ -123,14 +165,15 @@ Try rebooting. ### Issues with building Inkscape -The command \`ninja\` errors out after an MSYS2 update or after pulling new changes from the source reposiotry +**The command \`ninja\` errors** out after an MSYS2 update or after pulling new changes from the source reposiotry Re-run CMake using `rm -rf CMakeCache.txt && cmake -G Ninja ..`. The first command will delete cached and potentially stale info from the previous run, the second command will run CMake again to update the ninja files. - -☎ _If you can't solve your issue with the information above, please [ask in the chat](https://chat.inkscape.org/channel/team_devel) or [report a bug](https://inkscape.org/report)_. +**Memory exhausted** when running `ninja` + +Ninja runs as many tasks in parallel as you have CPU cores. This can use up all RAM. Use `ninja -j1` instead of `ninja` so that only one (`1`) task is run at the same time. ## Installing Build Dependencies Manually -- GitLab From 5eb6168cb5db736f774729f3824bac407ba60d88 Mon Sep 17 00:00:00 2001 From: Max Gaukler Date: Sun, 2 Nov 2025 10:18:47 +0100 Subject: [PATCH 3/3] Simplify Windows VSCode instructions (1) Avoid manual copy-and-paste of the terminal settings: Put them into a pre-made `settings.json` file. This also allows for a fully automatic setup of the VSCode environment in `windows-installFullDevEnv-clickHere.bat`. (2) Save extension recommendation to `extensions.json`. Then, VSCode will automatically ask the user to install the needed extension. --- doc/vscode/extensions.json | 5 +++++ doc/vscode/readme.md | 26 +++++--------------------- doc/vscode/settings.json | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 doc/vscode/extensions.json create mode 100644 doc/vscode/settings.json diff --git a/doc/vscode/extensions.json b/doc/vscode/extensions.json new file mode 100644 index 0000000000..8e01ab3cd0 --- /dev/null +++ b/doc/vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "ms-vscode.cpptools-extension-pack", + ] +} diff --git a/doc/vscode/readme.md b/doc/vscode/readme.md index 6f6aa15718..2181c94e10 100644 --- a/doc/vscode/readme.md +++ b/doc/vscode/readme.md @@ -10,33 +10,17 @@ 0. In your clone of the repository (called `master` in the compilation tutorial), make a new folder named: `.vscode` -0. Copy [c_cpp_properties.json](./c_cpp_properties.json), [launch.json](./launch.json), and [tasks.json](./tasks.json) from `doc/vscode` to that folder. +0. Copy all `.json` files from `doc/vscode` to that folder. This is the Inkscape-specific configuration of VSCode for the repository. Details about these files (c_cpp_properties.json, settings.json, tasks.json, launch.json) will be explained later. 0. Install [Visual Studio Code](https://code.visualstudio.com/) if you haven't. -0. Launch VS Code and install [the official C/C++ extension pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack) or at least [the main extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools). This is easily done via the extensions panel (Ctrl + Shift + X). +0. Launch VSCode. -0. Open the command palette (Ctrl + Shift + P) and enter `> Open User Settings (JSON)`. - -0. In the file that opens, add the following. This will allow you to launch the relevant MSYS2 terminals from within VS Code (Ctrl + \`) for convenience. If `terminal.integrated.profiles.windows` already exists, just add the items `UCRT` and `MSYS` to it. Note the presence of commas between adjacent list items. - ```json - "terminal.integrated.profiles.windows": { - "UCRT": { - "path": "cmd.exe", - "args": [ "/c", "C:/msys64/msys2_shell.cmd -defterm -here -no-start -ucrt64" ], - "overrideName": true - }, - "MSYS": { - "path": "cmd.exe", - "args": [ "/c", "C:/msys64/msys2_shell.cmd -defterm -here -no-start -msys" ], - "overrideName": true - } - } - ``` +0. Open the folder with your clone of the Inkscape repository. You can open a folder with `File > Open Folder...`. -0. Save and close `settings.json`. +0. When asked "Do you want to install the recommended installations for this repository", accept by clicking "Install". You can also do this later by installing [the official C/C++ extension pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack) or at least [the main extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) via the extensions panel (Ctrl + Shift + X). -0. Open the folder with your clone of the Inkscape repository. You can open a folder with `File > Open Folder...`. +0. [settings.json](./settings.json) defines terminal profiles that you need for running Inkscape build commands inside the VS Code terminal: UCRT (normal) and MSYS2 (special cases only). To launch the relevant MSYS2 terminals press Ctrl + \`. 0. To build Inkscape, I recommend trying via the terminal first to make it easier to troubleshoot. You can do that in VS Code: in the command palette, enter `> Create New Terminal (With Profile)` and choose `UCRT`. diff --git a/doc/vscode/settings.json b/doc/vscode/settings.json new file mode 100644 index 0000000000..34fd263ec7 --- /dev/null +++ b/doc/vscode/settings.json @@ -0,0 +1,14 @@ +{ + "terminal.integrated.profiles.windows": { + "UCRT": { + "path": "cmd.exe", + "args": [ "/c", "C:/msys64/msys2_shell.cmd -defterm -here -no-start -ucrt64" ], + "overrideName": true + }, + "MSYS": { + "path": "cmd.exe", + "args": [ "/c", "C:/msys64/msys2_shell.cmd -defterm -here -no-start -msys" ], + "overrideName": true + } + } +} -- GitLab