| 1 |
# install-dependencies.ps1 - Install Windows dependencies for building Mercurial |
| 2 |
# |
| 3 |
# Copyright 2019 Gregory Szorc <[email protected]> |
| 4 |
# |
| 5 |
# This software may be used and distributed according to the terms of the |
| 6 |
# GNU General Public License version 2 or any later version. |
| 7 |
|
| 8 |
# This script can be used to bootstrap a Mercurial build environment on |
| 9 |
# Windows. |
| 10 |
# |
| 11 |
# The script makes a lot of assumptions about how things should work. |
| 12 |
# For example, the install location of Python is hardcoded to c:\hgdev\*. |
| 13 |
# |
| 14 |
# The script should be executed from a PowerShell with elevated privileges |
| 15 |
# if you don't want to see a UAC prompt for various installers. |
| 16 |
# |
| 17 |
# The script is tested on Windows 10 and Windows Server 2019 (in EC2). |
| 18 |
# |
| 19 |
# This script can be tested with Docker by installing Docker Desktop, and |
| 20 |
# creating a Dockerfile that looks like this: |
| 21 |
# |
| 22 |
# $ cat contrib/docker/windows/install-windows-deps-test.Dockerfile |
| 23 |
# escape=` |
| 24 |
# |
| 25 |
# FROM "mcr.microsoft.com/windows/servercore:ltsc2025" |
| 26 |
# SHELL [ ` |
| 27 |
# "powershell.exe", "-Command", ` |
| 28 |
# "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';" ` |
| 29 |
# ] |
| 30 |
# |
| 31 |
# COPY install-windows-dependencies.ps1 "C:/" |
| 32 |
# COPY vs2022-settings.json "C:/" |
| 33 |
# |
| 34 |
# RUN powershell.exe -executionpolicy bypass "C:/install-windows-dependencies.ps1" |
| 35 |
# |
| 36 |
# ... and then running this from the repository root: |
| 37 |
# |
| 38 |
# $ docker build -t install-test -f contrib\docker\windows\install-windows-deps-test.Dockerfile contrib |
| 39 |
# |
| 40 |
# Note that while the script runs quickly, the finalization of the image and the |
| 41 |
# returning of control back to the command prompt takes 2 hours or more. So, be |
| 42 |
# patient- if hasn't errored out, it's working (silently). |
| 43 |
|
| 44 |
|
| 45 |
$VS_BUILD_TOOLS_URL = "https://download.visualstudio.microsoft.com/download/pr/f2819554-a618-400d-bced-774bb5379965/cc7231dc668ec1fb92f694c66b5d67cba1a9e21127a6e0b31c190f772bd442f2/vs_BuildTools.exe" |
| 46 |
$VS_BUILD_TOOLS_SHA256 = "CC7231DC668EC1FB92F694C66B5D67CBA1A9E21127A6E0B31C190F772BD442F2" |
| 47 |
|
| 48 |
$PYTHON39_x86_URL = "https://www.python.org/ftp/python/3.9.13/python-3.9.13.exe" |
| 49 |
$PYTHON39_x86_SHA256 = "F363935897BF32ADF6822BA15ED1BFED7AE2AE96477F0262650055B6E9637C35" |
| 50 |
$PYTHON39_X64_URL = "https://www.python.org/ftp/python/3.9.13/python-3.9.13-amd64.exe" |
| 51 |
$PYTHON39_x64_SHA256 = "FB3D0466F3754752CA7FD839A09FFE53375FF2C981279FD4BC23A005458F7F5D" |
| 52 |
|
| 53 |
$PYTHON310_x86_URL = "https://www.python.org/ftp/python/3.10.11/python-3.10.11.exe" |
| 54 |
$PYTHON310_x86_SHA256 = "BD115A575E86E61CEA9136C5A2C47E090BA484DC2DEE8B51A34111BB094266D5" |
| 55 |
$PYTHON310_X64_URL = "https://www.python.org/ftp/python/3.10.11/python-3.10.11-amd64.exe" |
| 56 |
$PYTHON310_x64_SHA256 = "D8DEDE5005564B408BA50317108B765ED9C3C510342A598F9FD42681CBE0648B" |
| 57 |
|
| 58 |
# Final installer release for this version |
| 59 |
$PYTHON311_x86_URL = "https://www.python.org/ftp/python/3.11.9/python-3.11.9.exe" |
| 60 |
$PYTHON311_x86_SHA256 = "AF19E5E2F03E715A822181F2CB7D4EFEF4EDA13FA4A2DB6DA12E998E46F5CBF9" |
| 61 |
$PYTHON311_X64_URL = "https://www.python.org/ftp/python/3.11.9/python-3.11.9-amd64.exe" |
| 62 |
$PYTHON311_x64_SHA256 = "5EE42C4EEE1E6B4464BB23722F90B45303F79442DF63083F05322F1785F5FDDE" |
| 63 |
|
| 64 |
$PYTHON312_X86_URL = "https://www.python.org/ftp/python/3.12.10/python-3.12.10.exe" |
| 65 |
$PYTHON312_x86_SHA256 = "FDFE385B94F5B8785A0226A886979527FD26EB65DEFDBF29992FD22CC4B0E31E" |
| 66 |
$PYTHON312_x64_URL = "https://www.python.org/ftp/python/3.12.10/python-3.12.10-amd64.exe" |
| 67 |
$PYTHON312_x64_SHA256 = "67B5635E80EA51072B87941312D00EC8927C4DB9BA18938F7AD2D27B328B95FB" |
| 68 |
|
| 69 |
$PYTHON313_x86_URL = "https://www.python.org/ftp/python/3.13.9/python-3.13.9.exe" |
| 70 |
$PYTHON313_x86_SHA256 = "2EA6D14D994602C83306E39D792E74637612240CFA77096DA1AC5BA9BACF613C" |
| 71 |
$PYTHON313_X64_URL = "https://www.python.org/ftp/python/3.13.9/python-3.13.9-amd64.exe" |
| 72 |
$PYTHON313_x64_SHA256 = "200DDFF856BBFF949D2CC1BE42E8807C07538ABD6B6966D5113A094CF628C5C5" |
| 73 |
|
| 74 |
$PYTHON314_x86_URL = "https://www.python.org/ftp/python/3.14.0/python-3.14.0.exe" |
| 75 |
$PYTHON314_x86_SHA256 = "0320E7643FA81ED889D72756BC3B41143EA84C3F1F7F95F3AC541153FFF210FC" |
| 76 |
$PYTHON314_X64_URL = "https://www.python.org/ftp/python/3.14.0/python-3.14.0-amd64.exe" |
| 77 |
$PYTHON314_x64_SHA256 = "52CEB249F65009D936E6504F97CCE42870C11358CB6E48825E893F54E11620AA" |
| 78 |
|
| 79 |
# PIP 25.3. |
| 80 |
$PIP_URL = "https://raw.githubusercontent.com/pypa/get-pip/2b8ba34a7db06e95db117b5fd872ea7941d0777b/public/get-pip.py" |
| 81 |
$PIP_SHA256 = "DFFC3658BAADA4EF383F31C3C672D4E5E306A6E376CEE8BEE5DBDF1385525104" |
| 82 |
|
| 83 |
$UV_INSTALLER_URL = "https://github.com/astral-sh/uv/releases/download/0.9.10/uv-installer.ps1" |
| 84 |
$UV_INSTALLER_SHA256 = "5886C05017496FCB7ACE9964E0278D1643D2B1F4EB04D1DEC8389DCF321330C0" |
| 85 |
|
| 86 |
$GETTEXT_SETUP_URL = "https://github.com/mlocati/gettext-iconv-windows/releases/download/v0.26-v1.17/gettext0.26-iconv1.17-shared-64.exe" |
| 87 |
$GETTEXT_SETUP_SHA256 = "C6BB3EB85ED660E2366EDEBD83EED03074FC277F7C91527C511E52D9235711A7" |
| 88 |
|
| 89 |
$INNO_SETUP_URL = "http://files.jrsoftware.org/is/5/innosetup-5.6.1-unicode.exe" |
| 90 |
$INNO_SETUP_SHA256 = "27D49E9BC769E9D1B214C153011978DB90DC01C2ACD1DDCD9ED7B3FE3B96B538" |
| 91 |
|
| 92 |
$MINGW_BIN_URL = "https://www.mercurial-scm.org/release/windows/artifacts/MinGW.zip" |
| 93 |
$MINGW_BIN_SHA256 = "31E98CF5B8C1C58902317F4F592A1C4E0DAF0096008F10FD260CFBA9B3240540" |
| 94 |
|
| 95 |
$MERCURIAL_SETUP_URL = "https://mercurial-scm.org/release/windows/mercurial-7.1.2-x64.msi" |
| 96 |
$MERCURIAL_SETUP_SHA256 = "8D702D0ACAD169D52FD64924B36A0D2D5F9908ED44E005DDC0D6F893FFE334DA" |
| 97 |
|
| 98 |
$RUSTUP_INIT_URL = "https://static.rust-lang.org/rustup/archive/1.21.1/x86_64-pc-windows-gnu/rustup-init.exe" |
| 99 |
$RUSTUP_INIT_SHA256 = "d17df34ba974b9b19cf5c75883a95475aa22ddc364591d75d174090d55711c72" |
| 100 |
|
| 101 |
$PYOXIDIZER_URL = "https://github.com/indygreg/PyOxidizer/releases/download/pyoxidizer%2F0.17/PyOxidizer-0.17.0-x64.msi" |
| 102 |
$PYOXIDIZER_SHA256 = "85c3bc21a18eb5e2db4dad87cca29accf725c7d59dd364a853ab5099c272024b" |
| 103 |
|
| 104 |
# Writing progress slows down downloads substantially. So disable it. |
| 105 |
$progressPreference = 'silentlyContinue' |
| 106 |
|
| 107 |
function Secure-Download($url, $path, $sha256) { |
| 108 |
if (Test-Path -Path $path) { |
| 109 |
Get-FileHash -Path $path -Algorithm SHA256 -OutVariable hash |
| 110 |
|
| 111 |
if ($hash.Hash -eq $sha256) { |
| 112 |
Write-Output "SHA256 of $path verified as $sha256" |
| 113 |
return |
| 114 |
} |
| 115 |
|
| 116 |
Write-Output "hash mismatch on $path; downloading again" |
| 117 |
} |
| 118 |
|
| 119 |
Write-Output "downloading $url to $path" |
| 120 |
Invoke-WebRequest -Uri $url -OutFile $path |
| 121 |
Get-FileHash -Path $path -Algorithm SHA256 -OutVariable hash |
| 122 |
|
| 123 |
if ($hash.Hash -ne $sha256) { |
| 124 |
Remove-Item -Path $path |
| 125 |
throw "hash mismatch when downloading $url; got $($hash.Hash), expected $sha256" |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
function Invoke-Process($path, $arguments) { |
| 130 |
echo "$path $arguments" |
| 131 |
|
| 132 |
$p = Start-Process -FilePath $path -ArgumentList $arguments -Wait -PassThru -WindowStyle Hidden |
| 133 |
|
| 134 |
if ($p.ExitCode -ne 0) { |
| 135 |
# If the MSI is already installed, ignore the error |
| 136 |
if ($p.ExitCode -eq 1638) { |
| 137 |
Write-Output "program already installed; continuing..." |
| 138 |
} |
| 139 |
else { |
| 140 |
throw "process exited non-0: $($p.ExitCode)" |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
function Install-Python3($name, $installer, $dest, $pip) { |
| 146 |
Write-Output "installing $name" |
| 147 |
|
| 148 |
# We hit this when running the script as part of Simple Systems Manager in |
| 149 |
# EC2. The Python 3 installer doesn't seem to like per-user installs |
| 150 |
# when running as the SYSTEM user. So enable global installs if executed in |
| 151 |
# this mode. |
| 152 |
if ($env:USERPROFILE -eq "C:\Windows\system32\config\systemprofile") { |
| 153 |
Write-Output "running with SYSTEM account; installing for all users" |
| 154 |
$allusers = "1" |
| 155 |
} |
| 156 |
else { |
| 157 |
$allusers = "0" |
| 158 |
} |
| 159 |
|
| 160 |
Invoke-Process $installer "/quiet TargetDir=${dest} InstallAllUsers=${allusers} AssociateFiles=0 CompileAll=0 PrependPath=0 Include_doc=0 Include_launcher=1 InstallLauncherAllUsers=1 Include_pip=0 Include_test=0" |
| 161 |
Invoke-Process ${dest}\python.exe $pip |
| 162 |
Invoke-Process ${dest}\python.exe "-m pip install -U --user setuptools==80.9.0 packaging==25.0" |
| 163 |
} |
| 164 |
|
| 165 |
function Install-Rust($prefix) { |
| 166 |
Write-Output "installing Rust" |
| 167 |
$Env:RUSTUP_HOME = "${prefix}\rustup" |
| 168 |
$Env:CARGO_HOME = "${prefix}\cargo" |
| 169 |
|
| 170 |
Invoke-Process "${prefix}\assets\rustup-init.exe" "-y --default-host x86_64-pc-windows-msvc" |
| 171 |
Invoke-Process "${prefix}\cargo\bin\rustup.exe" "target add i686-pc-windows-msvc" |
| 172 |
Invoke-Process "${prefix}\cargo\bin\rustup.exe" "install 1.52.0" |
| 173 |
Invoke-Process "${prefix}\cargo\bin\rustup.exe" "component add clippy" |
| 174 |
} |
| 175 |
|
| 176 |
function Install-Dependencies($prefix) { |
| 177 |
if (!(Test-Path -Path $prefix\assets)) { |
| 178 |
New-Item -Path $prefix\assets -ItemType Directory |
| 179 |
} |
| 180 |
|
| 181 |
$pip = "${prefix}\assets\get-pip.py" |
| 182 |
|
| 183 |
Secure-Download $PYTHON39_x86_URL ${prefix}\assets\python39-x86.exe $PYTHON39_x86_SHA256 |
| 184 |
Secure-Download $PYTHON39_x64_URL ${prefix}\assets\python39-x64.exe $PYTHON39_x64_SHA256 |
| 185 |
Secure-Download $PYTHON310_x86_URL ${prefix}\assets\python310-x86.exe $PYTHON310_x86_SHA256 |
| 186 |
Secure-Download $PYTHON310_x64_URL ${prefix}\assets\python310-x64.exe $PYTHON310_x64_SHA256 |
| 187 |
Secure-Download $PYTHON311_x86_URL ${prefix}\assets\python311-x86.exe $PYTHON311_x86_SHA256 |
| 188 |
Secure-Download $PYTHON311_x64_URL ${prefix}\assets\python311-x64.exe $PYTHON311_x64_SHA256 |
| 189 |
Secure-Download $PYTHON312_x86_URL ${prefix}\assets\python312-x86.exe $PYTHON312_x86_SHA256 |
| 190 |
Secure-Download $PYTHON312_x64_URL ${prefix}\assets\python312-x64.exe $PYTHON312_x64_SHA256 |
| 191 |
Secure-Download $PYTHON313_x86_URL ${prefix}\assets\python313-x86.exe $PYTHON313_x86_SHA256 |
| 192 |
Secure-Download $PYTHON313_x64_URL ${prefix}\assets\python313-x64.exe $PYTHON313_x64_SHA256 |
| 193 |
Secure-Download $PYTHON314_x86_URL ${prefix}\assets\python314-x86.exe $PYTHON314_x86_SHA256 |
| 194 |
Secure-Download $PYTHON314_x64_URL ${prefix}\assets\python314-x64.exe $PYTHON314_x64_SHA256 |
| 195 |
|
| 196 |
Secure-Download $PIP_URL ${pip} $PIP_SHA256 |
| 197 |
Secure-Download $UV_INSTALLER_URL "${prefix}\assets\uv-installer.ps1" $UV_INSTALLER_SHA256 |
| 198 |
|
| 199 |
Secure-Download $VS_BUILD_TOOLS_URL ${prefix}\assets\vs_buildtools.exe $VS_BUILD_TOOLS_SHA256 |
| 200 |
Secure-Download $GETTEXT_SETUP_URL ${prefix}\assets\gettext.exe $GETTEXT_SETUP_SHA256 |
| 201 |
Secure-Download $INNO_SETUP_URL ${prefix}\assets\InnoSetup.exe $INNO_SETUP_SHA256 |
| 202 |
Secure-Download $MINGW_BIN_URL ${prefix}\assets\MinGW.zip $MINGW_BIN_SHA256 |
| 203 |
Secure-Download $MERCURIAL_SETUP_URL ${prefix}\assets\Mercurial.msi $MERCURIAL_SETUP_SHA256 |
| 204 |
Secure-Download $RUSTUP_INIT_URL ${prefix}\assets\rustup-init.exe $RUSTUP_INIT_SHA256 |
| 205 |
Secure-Download $PYOXIDIZER_URL ${prefix}\assets\PyOxidizer.msi $PYOXIDIZER_SHA256 |
| 206 |
|
| 207 |
Install-Python3 "Python 3.9 32-bit" ${prefix}\assets\python39-x86.exe ${prefix}\python39-x86 ${pip} |
| 208 |
Install-Python3 "Python 3.9 64-bit" ${prefix}\assets\python39-x64.exe ${prefix}\python39-x64 ${pip} |
| 209 |
Install-Python3 "Python 3.10 32-bit" ${prefix}\assets\python310-x86.exe ${prefix}\python310-x86 ${pip} |
| 210 |
Install-Python3 "Python 3.10 64-bit" ${prefix}\assets\python310-x64.exe ${prefix}\python310-x64 ${pip} |
| 211 |
Install-Python3 "Python 3.11 32-bit" ${prefix}\assets\python311-x86.exe ${prefix}\python311-x86 ${pip} |
| 212 |
Install-Python3 "Python 3.11 64-bit" ${prefix}\assets\python311-x64.exe ${prefix}\python311-x64 ${pip} |
| 213 |
Install-Python3 "Python 3.12 32-bit" ${prefix}\assets\python312-x86.exe ${prefix}\python312-x86 ${pip} |
| 214 |
Install-Python3 "Python 3.12 64-bit" ${prefix}\assets\python312-x64.exe ${prefix}\python312-x64 ${pip} |
| 215 |
Install-Python3 "Python 3.13 32-bit" ${prefix}\assets\python313-x86.exe ${prefix}\python313-x86 ${pip} |
| 216 |
Install-Python3 "Python 3.13 64-bit" ${prefix}\assets\python313-x64.exe ${prefix}\python313-x64 ${pip} |
| 217 |
Install-Python3 "Python 3.14 32-bit" ${prefix}\assets\python314-x86.exe ${prefix}\python314-x86 ${pip} |
| 218 |
Install-Python3 "Python 3.14 64-bit" ${prefix}\assets\python314-x64.exe ${prefix}\python314-x64 ${pip} |
| 219 |
|
| 220 |
Invoke-Process ${prefix}\python313-x64\python.exe "-m pip install --user pipx" |
| 221 |
Invoke-Process ${prefix}\python313-x64\python.exe "-m pipx ensurepath" |
| 222 |
Invoke-Process ${prefix}\python313-x64\python.exe "-m pipx install cibuildwheel==3.3.0" |
| 223 |
Invoke-Process ${prefix}\python313-x64\python.exe "-m pipx install black<24" |
| 224 |
|
| 225 |
Write-Output "installing uv" |
| 226 |
powershell -ExecutionPolicy Bypass "${prefix}\assets\uv-installer.ps1" |
| 227 |
|
| 228 |
Write-Output "installing Visual Studio 2022 Build Tools and SDKs" |
| 229 |
Invoke-Process ${prefix}\assets\vs_buildtools.exe "--quiet --wait --norestart --nocache --channelUri https://aka.ms/vs/17/release/channel --config $PSScriptRoot\vs2022-settings.json" |
| 230 |
|
| 231 |
Write-Output "installing PyOxidizer" |
| 232 |
Invoke-Process msiexec.exe "/i ${prefix}\assets\PyOxidizer.msi /l* ${prefix}\assets\PyOxidizer.log /quiet" |
| 233 |
|
| 234 |
Install-Rust ${prefix} |
| 235 |
|
| 236 |
Write-Output "installing GetText Setup" |
| 237 |
Invoke-Process ${prefix}\assets\gettext.exe "/SP- /VERYSILENT /SUPPRESSMSGBOXES" |
| 238 |
|
| 239 |
Write-Output "installing Inno Setup" |
| 240 |
Invoke-Process ${prefix}\assets\InnoSetup.exe "/SP- /VERYSILENT /SUPPRESSMSGBOXES" |
| 241 |
|
| 242 |
Write-Output "extracting MinGW archive" |
| 243 |
Expand-Archive -Path ${prefix}\assets\MinGW.zip -DestinationPath "${prefix}" -Force |
| 244 |
|
| 245 |
# Construct a virtualenv useful for bootstrapping. It conveniently contains a |
| 246 |
# Mercurial install. |
| 247 |
Write-Output "creating bootstrap virtualenv with Mercurial" |
| 248 |
Invoke-Process "$prefix\python39-x64\python.exe" "-m venv ${prefix}\venv-bootstrap" |
| 249 |
|
| 250 |
Invoke-Process msiexec.exe "/i ${prefix}\assets\Mercurial.msi /l* ${prefix}\assets\Mercurial.log /quiet" |
| 251 |
} |
| 252 |
|
| 253 |
function Clone-Mercurial-Repo($prefix, $repo_url, $dest) { |
| 254 |
Write-Output "cloning $repo_url to $dest" |
| 255 |
# TODO Figure out why CA verification isn't working in EC2 and remove |
| 256 |
# --insecure. |
| 257 |
Invoke-Process "$Env:PROGRAMFILES\Mercurial\hg.exe" "clone --insecure $repo_url $dest" |
| 258 |
|
| 259 |
# Mark repo as non-publishing by default for convenience. |
| 260 |
Add-Content -Path "$dest\.hg\hgrc" -Value "`n[phases]`npublish = false" |
| 261 |
} |
| 262 |
|
| 263 |
$prefix = "c:\hgdev" |
| 264 |
Install-Dependencies $prefix |
| 265 |
Clone-Mercurial-Repo $prefix "https://foss.heptapod.net/mercurial/mercurial-devel" $prefix\src |
| 266 |
|
| 267 |
Write-Output "Setup is complete. If a Docker image is building, it may take awhile longer." |