|
| 1 | +######################################################################## |
| 2 | +# Build ITK Python wheel tarballs (build cache) on Windows. |
| 3 | +# |
| 4 | +# This is the Windows PowerShell equivalent of make_tarballs.sh. |
| 5 | +# POSIX shell is not supported for this workflow on Windows. |
| 6 | +# |
| 7 | +# This script builds the ITK core cache only — it has no knowledge of |
| 8 | +# external modules. Module-specific flags (--module-source-dir, |
| 9 | +# --module-dependencies-root-dir, --itk-module-deps, --lib-paths) are |
| 10 | +# intentionally absent; they belong only in the module wheel build script. |
| 11 | +# |
| 12 | +# Directory names are intentionally kept short to avoid Windows MAX_PATH |
| 13 | +# issues during deep CMake/compiler builds. Everything lives under one |
| 14 | +# root directory (C:\BDR) so no build artifacts are scattered at C:\: |
| 15 | +# ITKPythonPackage -> C:\BDR\IPP (scripts clone) |
| 16 | +# ITK source -> C:\BDR\ITK (ITK git checkout) |
| 17 | +# build root -> C:\BDR (build_wheels.py root; cached build lands at C:\BDR\build\ITK-windows-...) |
| 18 | +# |
| 19 | +# This script MUST be run from the canonical location: |
| 20 | +# C:\BDR\IPP\scripts\make_tarballs.ps1 |
| 21 | +# |
| 22 | +# Typical usage: |
| 23 | +# > $env:ITK_GIT_TAG = "v6.0b02" |
| 24 | +# > .\make_tarballs.ps1 |
| 25 | +# |
| 26 | +# Restrict to specific python versions by passing them as arguments: |
| 27 | +# > .\make_tarballs.ps1 py311 |
| 28 | +# |
| 29 | +# ----------------------------------------------------------------------- |
| 30 | +# Environment variables: |
| 31 | +# |
| 32 | +# `$env:ITK_GIT_TAG` |
| 33 | +# ITK git tag to build from. Falls back to v6.0b02 with loud warnings |
| 34 | +# if unset, matching the bash script behaviour. |
| 35 | +# |
| 36 | +######################################################################## |
| 37 | +param ( |
| 38 | + [Parameter(ValueFromRemainingArguments)] |
| 39 | + [string[]]$pyenvs |
| 40 | +) |
| 41 | + |
| 42 | +Set-StrictMode -Version Latest |
| 43 | +$ErrorActionPreference = "Stop" |
| 44 | + |
| 45 | +# Resolve python environments |
| 46 | +if (-not $pyenvs -or $pyenvs.Count -eq 0) { |
| 47 | + $pyenvs = @("py310", "py311") |
| 48 | +} |
| 49 | +echo "Building for python environments: $($pyenvs -join ', ')" |
| 50 | + |
| 51 | +# Resolve ITK_GIT_TAG — loud warning if unset, matching bash behaviour |
| 52 | +$DEFAULT_ITK_GIT_TAG = "v6.0b02" |
| 53 | +if (-not $env:ITK_GIT_TAG) { |
| 54 | + $warningLine = "===== WARNING: ITK_GIT_TAG not set, so defaulting to $DEFAULT_ITK_GIT_TAG" |
| 55 | + echo "=============================================================================" |
| 56 | + 1..29 | ForEach-Object { echo $warningLine } |
| 57 | + echo "=============================================================================" |
| 58 | + $env:ITK_GIT_TAG = $DEFAULT_ITK_GIT_TAG |
| 59 | +} |
| 60 | +$ITK_GIT_TAG = $env:ITK_GIT_TAG |
| 61 | +echo "ITK_GIT_TAG : $ITK_GIT_TAG" |
| 62 | + |
| 63 | +# Compute paths from this script's location. |
| 64 | +# Everything is contained under C:\BDR to keep all build artifacts in one |
| 65 | +# place and avoid spreading directories across the drive root. |
| 66 | +# |
| 67 | +# C:\BDR\ <- $BDR (single root for all build content) |
| 68 | +# C:\BDR\IPP\scripts\ <- $ScriptsDir (this file) |
| 69 | +# C:\BDR\IPP\ <- $IPPDir (ITKPythonPackage clone) |
| 70 | +# C:\BDR\ITK\ <- $ItkSourceDir (ITK git checkout) |
| 71 | +# C:\BDR\ <- $BuildDirRoot (build root; cached build lands at C:\BDR\build\ITK-windows-...) |
| 72 | +# C:\BDR\.pixi\ <- pixi home |
| 73 | +$BDR = "C:\BDR" |
| 74 | +$ScriptsDir = Split-Path -Parent $MyInvocation.MyCommand.Path |
| 75 | +$IPPDir = Split-Path -Parent $ScriptsDir |
| 76 | +$BuildScript = Join-Path $ScriptsDir "build_wheels.py" |
| 77 | +$ItkSourceDir = Join-Path $BDR "ITK" |
| 78 | +$BuildDirRoot = $BDR |
| 79 | + |
| 80 | +echo "BDR : $BDR" |
| 81 | +echo "IPPDir : $IPPDir" |
| 82 | +echo "ScriptsDir : $ScriptsDir" |
| 83 | +echo "ItkSourceDir : $ItkSourceDir" |
| 84 | +echo "BuildDirRoot : $BuildDirRoot" |
| 85 | + |
| 86 | +# Validate script is running from the expected canonical location |
| 87 | +$ExpectedScriptsDir = Join-Path $BDR "IPP\scripts" |
| 88 | +if ($ScriptsDir -ne $ExpectedScriptsDir) { |
| 89 | + Write-Error @" |
| 90 | +ERROR: GitHub CI requires a rigid directory structure. |
| 91 | +Script found at : $ScriptsDir |
| 92 | +Expected location: $ExpectedScriptsDir |
| 93 | +
|
| 94 | + RUN: cd $BDR |
| 95 | + RUN: git clone git@github.com:<org>/ITKPythonPackage.git $BDR\IPP |
| 96 | + FOR DEVELOPMENT: git checkout python_based_build_scripts |
| 97 | + RUN: $ExpectedScriptsDir\make_windows_zip.ps1 |
| 98 | +"@ |
| 99 | + exit 1 |
| 100 | +} |
| 101 | + |
| 102 | +if (-not (Test-Path -LiteralPath $BuildScript)) { |
| 103 | + throw "build_wheels.py not found at: $BuildScript" |
| 104 | +} |
| 105 | + |
| 106 | +# Create BDR if it doesn't exist |
| 107 | +# (may require administrator credentials on a fresh machine) |
| 108 | +if (-not (Test-Path -LiteralPath $BDR)) { |
| 109 | + echo "Creating directory: $BDR" |
| 110 | + New-Item -ItemType Directory -Path $BDR -Force | Out-Null |
| 111 | +} |
| 112 | + |
| 113 | +# Install pixi if not already present. |
| 114 | +# Python, Doxygen, and all build tools are provided by the pixi environment. |
| 115 | +$env:PIXI_HOME = "$BDR\.pixi" |
| 116 | +if (-not (Test-Path "$env:PIXI_HOME\bin\pixi.exe")) { |
| 117 | + echo "Installing pixi..." |
| 118 | + Invoke-WebRequest -Uri "https://pixi.sh/install.ps1" -OutFile "install-pixi.ps1" |
| 119 | + powershell -ExecutionPolicy Bypass -File "install-pixi.ps1" |
| 120 | +} |
| 121 | +$env:Path = "$env:PIXI_HOME\bin;$env:Path" |
| 122 | + |
| 123 | +# Build each requested python environment. |
| 124 | +# Push-Location/finally ensures we always restore the caller's directory. |
| 125 | +Push-Location $IPPDir |
| 126 | +try { |
| 127 | + foreach ($pyenv in $pyenvs) { |
| 128 | + # Normalise any of: py311 / py3.11 / cp311 / 3.11 -> py311 |
| 129 | + $pySquashed = $pyenv -replace 'py|cp|\.', '' |
| 130 | + $pyenv = "py$pySquashed" |
| 131 | + $platformEnv = "windows-$pyenv" |
| 132 | + |
| 133 | + echo "" |
| 134 | + echo "========================================================" |
| 135 | + echo "Building cache for platform env: $platformEnv" |
| 136 | + echo "========================================================" |
| 137 | + |
| 138 | + pixi run -e $platformEnv python $BuildScript ` |
| 139 | + --platform-env $platformEnv ` |
| 140 | + --build-itk-tarball-cache ` |
| 141 | + --build-dir-root $BuildDirRoot ` |
| 142 | + --itk-source-dir $ItkSourceDir ` |
| 143 | + --itk-git-tag $ITK_GIT_TAG ` |
| 144 | + --no-use-sudo ` |
| 145 | + --no-use-ccache |
| 146 | + |
| 147 | + if ($LASTEXITCODE -ne 0) { |
| 148 | + throw "build_wheels.py failed for $platformEnv (exit code $LASTEXITCODE)" |
| 149 | + } |
| 150 | + } |
| 151 | +} |
| 152 | +finally { |
| 153 | + Pop-Location |
| 154 | +} |
| 155 | + |
| 156 | +echo "" |
| 157 | +echo "All tarball builds completed successfully." |
0 commit comments