Skip to content

Commit bc80276

Browse files
committed
feat: add tarball creation and ITK build cache management
Adds make_tarballs.sh and integrates tarball generation logic into build_python_instance_base.py. Supports creating, downloading, and reusing ITK build caches across Linux, macOS, and Windows, including manylinux tarball support, arch-specific naming, and a --build-itk-tarball-cache CLI option. Adds make_windows_zip.ps1 for streamlined Windows wheel packaging and zip creation.
1 parent 36564fa commit bc80276

File tree

5 files changed

+277
-81
lines changed

5 files changed

+277
-81
lines changed

scripts/dockcross-manylinux-build-tarball.sh

Lines changed: 0 additions & 44 deletions
This file was deleted.

scripts/macpython-build-tarball.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

scripts/make_tarballs.sh

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env bash
2+
# NOTES: Building tarballs requires specific pathing for supporting github CI
3+
# workflows
4+
5+
script_dir=$(
6+
cd "$(dirname "$0")" || exit 1
7+
pwd
8+
)
9+
_ipp_dir=$(dirname "${script_dir}")
10+
11+
# If args are given, use them. Otherwise use default python environments
12+
pyenvs=("${@:-py310 py311}")
13+
14+
# Otherwise process mac and linux based on uname
15+
16+
# Need to explicitly request to --build-itk-tarball-cache
17+
BUILD_WHEELS_EXTRA_FLAGS=("--build-itk-tarball-cache")
18+
if [ -z "${ITK_GIT_TAG}" ]; then
19+
DEFAULT_ITK_GIT_TAG=v6.0b02
20+
echo "============================================================================="
21+
echo "============================================================================="
22+
for _ in x x x x x x x x x x x x x x x x x x x x x x x x x x x x x; do
23+
echo "===== WARNING: ITK_GIT_TAG not set, so defaulting to ${DEFAULT_ITK_GIT_TAG}"
24+
done
25+
echo "============================================================================="
26+
echo "============================================================================="
27+
fi
28+
ITK_GIT_TAG=${ITK_GIT_TAG:=${DEFAULT_ITK_GIT_TAG}}
29+
30+
## --
31+
# --
32+
# --
33+
# --
34+
# Short circuit builds to use dockcross if MANYLINUX_VERSION is requested
35+
if [ -n "${MANYLINUX_VERSION}" ]; then
36+
BUILD_WHEELS_EXTRA_FLAGS="${BUILD_WHEELS_EXTRA_FLAGS[*]}" \
37+
ITK_GIT_TAG=${ITK_GIT_TAG} \
38+
MANYLINUX_VERSION=${MANYLINUX_VERSION} \
39+
bash "${_ipp_dir}/scripts/dockcross-manylinux-build-wheels.sh" \
40+
"${pyenvs[@]}"
41+
exit $?
42+
fi
43+
44+
## --
45+
# --
46+
# --
47+
# --
48+
case "$(uname -s)" in
49+
Darwin)
50+
PLATFORM_PREFIX="macosx"
51+
DASHBOARD_BUILD_DIRECTORY=${DASHBOARD_BUILD_DIRECTORY:=/Users/svc-dashboard/D/P}
52+
;;
53+
Linux)
54+
PLATFORM_PREFIX="linux"
55+
DASHBOARD_BUILD_DIRECTORY=${DASHBOARD_BUILD_DIRECTORY:=/work}
56+
;;
57+
# POSIX build env NOT SUPPORTED for windows, Needs to be done in a .ps1 shell
58+
# MINGW*|MSYS*|CYGWIN*)
59+
# PLATFORM_PREFIX="windows"
60+
# DASHBOARD_BUILD_DIRECTORY="C:\P"
61+
# ;;
62+
*)
63+
echo "Unsupported platform: $(uname -s)"
64+
exit 1
65+
;;
66+
esac
67+
68+
# Required environment variables
69+
required_vars=(
70+
ITK_GIT_TAG
71+
PLATFORM_PREFIX
72+
DASHBOARD_BUILD_DIRECTORY
73+
74+
)
75+
76+
# Sanity Validation loop
77+
_missing_required=0
78+
for v in "${required_vars[@]}"; do
79+
if [ -z "${!v:-}" ]; then
80+
_missing_required=1
81+
echo "ERROR: Required environment variable '$v' is not set or empty."
82+
fi
83+
done
84+
if [ "${_missing_required}" -ne 0 ]; then
85+
exit 1
86+
fi
87+
unset _missing_required
88+
89+
if [ ! -d "${DASHBOARD_BUILD_DIRECTORY}" ]; then
90+
# This is the expected directory for the cache, It may require creation with administrator credentials
91+
mkdir -p "${DASHBOARD_BUILD_DIRECTORY}"
92+
fi
93+
if [ "${script_dir}" != "${DASHBOARD_BUILD_DIRECTORY}/ITKPythonPackage/scripts" ]; then
94+
echo "ERROR: Github CI requires rigid directory structure, you may substitute the ITKPythonPackage organization if testing"
95+
echo " RUN: cd ${DASHBOARD_BUILD_DIRECTORY}"
96+
echo " RUN: git clone git@github.com:${ITKPYTHONPACKAGE_ORG}/ITKPythonPackage.git ${DASHBOARD_BUILD_DIRECTORY}/ITKPythonPackage"
97+
echo " FOR DEVELOPMENT RUN: git checkout python_based_build_scripts"
98+
echo " RUN: ${DASHBOARD_BUILD_DIRECTORY}/ITKPythonPackage/scripts/make_tarballs.sh"
99+
exit 1
100+
fi
101+
102+
export PIXI_HOME=${DASHBOARD_BUILD_DIRECTORY}/.pixi
103+
if [ ! -f "${PIXI_HOME}/bin/pixi" ]; then
104+
#PIXI INSTALL
105+
if [ ! -f "${PIXI_HOME}/bin/pixi" ]; then
106+
curl -fsSL https://pixi.sh/install.sh | sh
107+
export PATH="${PIXI_HOME}/bin:$PATH"
108+
fi
109+
fi
110+
111+
for pyenv in "${pyenvs[@]}"; do
112+
cd "${DASHBOARD_BUILD_DIRECTORY}/ITKPythonPackage" || exit
113+
"${PIXI_HOME}/bin/pixi" run -e "${PLATFORM_PREFIX}-${pyenv}" \
114+
python3 "${DASHBOARD_BUILD_DIRECTORY}/ITKPythonPackage/scripts/build_wheels.py" \
115+
--platform-env "${PLATFORM_PREFIX}-${pyenv}" \
116+
--build-dir-root "${DASHBOARD_BUILD_DIRECTORY}/ITKPythonPackage-build" \
117+
--itk-source-dir "${DASHBOARD_BUILD_DIRECTORY}/ITKPythonPackage-build/ITK" \
118+
--itk-git-tag "${ITK_GIT_TAG}" \
119+
"${BUILD_WHEELS_EXTRA_FLAGS[@]}"
120+
done

scripts/make_windows_zip.ps1

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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."

scripts/windows-build-tarball.ps1

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)