From 583e7a68d478d21519b579300800d7b4d62102c5 Mon Sep 17 00:00:00 2001 From: Tom Birdsong Date: Wed, 30 Nov 2022 12:15:39 -0500 Subject: [PATCH] ENH: Expose MANYLINUX_VERSION and IMAGE_TAG for Linux builds Replaces `TARBALL_SPECIALIZATION` parameter with distinct `MANYLINUX_VERSION` and `IMAGE_TAG` parameters to be set by the user prior to build. The resulting script fetches the correct dockcross image for building specialized wheels and artifacts. Resolves an issue where `manylinux2014` wheels were attempted to build on `-manylinux_2_28` images. --- .../dockcross-manylinux-build-module-wheels.sh | 15 +++++++++++++-- scripts/dockcross-manylinux-build-wheels.sh | 16 ++++++++++++++-- ...ux-download-cache-and-build-module-wheels.sh | 17 ++++++++++++++--- scripts/internal/manylinux-build-common.sh | 2 +- .../internal/manylinux-build-module-wheels.sh | 10 ++++++++++ scripts/internal/manylinux-build-wheels.sh | 10 ++++++++++ ...anylinux_2_28_aarch64-build-module-wheels.sh | 14 +++++++++++--- 7 files changed, 73 insertions(+), 11 deletions(-) diff --git a/scripts/dockcross-manylinux-build-module-wheels.sh b/scripts/dockcross-manylinux-build-module-wheels.sh index 9807879c..854224a4 100755 --- a/scripts/dockcross-manylinux-build-module-wheels.sh +++ b/scripts/dockcross-manylinux-build-module-wheels.sh @@ -16,9 +16,19 @@ # export LD_LIBRARY_PATH="/path/to/OpenCL.so:/path/to/OpenCL.so.1.2" # scripts/dockcross-manylinux-build-module-wheels.sh cp39 # +# A specialized manylinux image and tag can be used by exporting +# MANYLINUX_VERSION and IMAGE_TAG before running this script. +# See https://github.com/dockcross/dockcross for available versions and tags. +# +# For example, +# +# export MANYLINUX_VERSION=2014 +# export IMAGE_TAG=20221108-102ebcc +# scripts/dockcross-manylinux-build-module-wheels.sh cp39 +# -MANYLINUX_VERSION=_2_28 -IMAGE_TAG=20221128-2024e4b +MANYLINUX_VERSION=${MANYLINUX_VERSION:=_2_28} +IMAGE_TAG=${IMAGE_TAG:=20221128-2024e4b} # Generate dockcross scripts docker run --rm dockcross/manylinux${MANYLINUX_VERSION}-x64:${IMAGE_TAG} > /tmp/dockcross-manylinux-x64 @@ -31,6 +41,7 @@ chmod 777 $(pwd)/tools # Build wheels mkdir -p dist DOCKER_ARGS="-v $(pwd)/dist:/work/dist/ -v $script_dir/..:/ITKPythonPackage -v $(pwd)/tools:/tools" +DOCKER_ARGS+=" -e MANYLINUX_VERSION" # Mount any shared libraries if [[ -n ${LD_LIBRARY_PATH} ]]; then for libpath in ${LD_LIBRARY_PATH//:/ }; do diff --git a/scripts/dockcross-manylinux-build-wheels.sh b/scripts/dockcross-manylinux-build-wheels.sh index 4e70d7d7..ece0e10a 100755 --- a/scripts/dockcross-manylinux-build-wheels.sh +++ b/scripts/dockcross-manylinux-build-wheels.sh @@ -6,9 +6,20 @@ # For example, # # scripts/dockcross-manylinux-build-wheels.sh cp39 +# +# A specialized manylinux image and tag can be used by exporting to +# MANYLINUX_VERSION and IMAGE_TAG before running this script. +# See https://github.com/dockcross/dockcross for available versions and tags. +# +# For example, +# +# export MANYLINUX_VERSION=2014 +# export IMAGE_TAG=20221108-102ebcc +# scripts/dockcross-manylinux-build-module-wheels.sh cp39 +# -MANYLINUX_VERSION=_2_28 -IMAGE_TAG=20221128-2024e4b +MANYLINUX_VERSION=${MANYLINUX_VERSION:=_2_28} +IMAGE_TAG=${IMAGE_TAG:=20221128-2024e4b} # Generate dockcross scripts docker run --rm dockcross/manylinux${MANYLINUX_VERSION}-x64:${IMAGE_TAG} > /tmp/dockcross-manylinux-x64 @@ -20,6 +31,7 @@ script_dir=$(cd $(dirname $0) || exit 1; pwd) pushd $script_dir/.. mkdir -p dist DOCKER_ARGS="-v $(pwd)/dist:/work/dist/" +DOCKER_ARGS+=" -e MANYLINUX_VERSION" /tmp/dockcross-manylinux-x64 \ -a "$DOCKER_ARGS" \ ./scripts/internal/manylinux-build-wheels.sh "$@" diff --git a/scripts/dockcross-manylinux-download-cache-and-build-module-wheels.sh b/scripts/dockcross-manylinux-download-cache-and-build-module-wheels.sh index 37ad2ca2..6bd4add5 100755 --- a/scripts/dockcross-manylinux-download-cache-and-build-module-wheels.sh +++ b/scripts/dockcross-manylinux-download-cache-and-build-module-wheels.sh @@ -5,14 +5,18 @@ # # Exported variables used in this script: # - ITK_PACKAGE_VERSION: Tag for ITKPythonBuilds build archive to use -# - TARBALL_SPECIALIZATION: manylinux specialization to use -# Examples: "-manylinux_2_28", "-manylinux2014", "-manylinux_2_28_aarch64" +# Examples: "v5.3.0", "v5.2.1.post1" +# See available tags at https://github.com/InsightSoftwareConsortium/ITKPythonBuilds/tags +# - MANYLINUX_VERSION: manylinux specialization to use +# Examples: "_2_28", "2014", "_2_28_aarch64" +# See https://github.com/dockcross/dockcross # - ITKPYTHONPACKAGE_TAG: Tag for ITKPythonPackage build scripts to use. # If ITKPYTHONPACKAGE_TAG is empty then the default scripts distributed # with the ITKPythonBuilds archive will be used. # - ITKPYTHONPACKAGE_ORG: Github organization or user to use for ITKPythonPackage # build script source. Default is InsightSoftwareConsortium. # Ignored if ITKPYTHONPACKAGE_TAG is empty. +# # ----------------------------------------------------------------------- # Script argument parsing @@ -57,9 +61,14 @@ fi # Expect unzstd > v1.3.2, see discussion in `dockcross-manylinux-build-tarball.sh` ${unzstd_exe} --version +# ----------------------------------------------------------------------- +# Fetch build archive + +TARBALL_SPECIALIZATION="-manylinux${MANYLINUX_VERSION:=_2_28}" TARBALL_NAME="ITKPythonBuilds-linux${TARBALL_SPECIALIZATION}.tar" if [[ ! -f ${TARBALL_NAME}.zst ]]; then + echo "Fetching https://github.com/InsightSoftwareConsortium/ITKPythonBuilds/releases/download/${ITK_PACKAGE_VERSION:=v5.3.0}/${TARBALL_NAME}.zst" curl -L https://github.com/InsightSoftwareConsortium/ITKPythonBuilds/releases/download/${ITK_PACKAGE_VERSION:=v5.3.0}/${TARBALL_NAME}.zst -O fi if [[ ! -f ./${TARBALL_NAME}.zst ]]; then @@ -99,8 +108,10 @@ if [[ ! -f ./ITKPythonPackage/scripts/dockcross-manylinux-build-module-wheels.sh fi cp -a ITKPythonPackage/oneTBB-prefix ./ +# ----------------------------------------------------------------------- + set -- "${FORWARD_ARGS[@]}"; # Restore initial argument list -if [[ "${TARBALL_SPECIALIZATION}" = "-manylinux_2_28_aarch64" ]]; then +if [[ "${MANYLINUX_VERSION}" = "_2_28_aarch64" ]]; then ./ITKPythonPackage/scripts/manylinux_2_28_aarch64-build-module-wheels.sh "$@" else ./ITKPythonPackage/scripts/dockcross-manylinux-build-module-wheels.sh "$@" diff --git a/scripts/internal/manylinux-build-common.sh b/scripts/internal/manylinux-build-common.sh index bd133882..f87ca18d 100644 --- a/scripts/internal/manylinux-build-common.sh +++ b/scripts/internal/manylinux-build-common.sh @@ -80,6 +80,6 @@ if ! type ninja > /dev/null 2>&1; then popd fi -MANYLINUX_VERSION=_2_28 +MANYLINUX_VERSION=${MANYLINUX_VERSION:=_2_28} echo "Building wheels for $ARCH using manylinux${MANYLINUX_VERSION}" diff --git a/scripts/internal/manylinux-build-module-wheels.sh b/scripts/internal/manylinux-build-module-wheels.sh index da004646..0a089752 100755 --- a/scripts/internal/manylinux-build-module-wheels.sh +++ b/scripts/internal/manylinux-build-module-wheels.sh @@ -15,6 +15,16 @@ # DOCKER_ARGS="-v /path/to/lib.so:/usr/local/lib64/lib.so" # /tmp/dockcross-manylinux-x64 -a "$DOCKER_ARGS" manylinux-build-module-wheels.sh # +# The specialized manylinux container version should be set prior to running this script. +# See https://github.com/dockcross/dockcross for available versions and tags. +# +# For example, `docker run -e ` can be used to set an environment variable when launching a container: +# +# export MANYLINUX_VERSION=2014 +# docker run --rm dockcross/manylinux${MANYLINUX_VERSION}-x64:${IMAGE_TAG} > /tmp/dockcross-manylinux-x64 +# chmod u+x /tmp/dockcross-manylinux-x64 +# /tmp/dockcross-manylinux-x64 -e MANYLINUX_VERSION manylinux-build-module-wheels.sh cp39 +# # ----------------------------------------------------------------------- # Script argument parsing diff --git a/scripts/internal/manylinux-build-wheels.sh b/scripts/internal/manylinux-build-wheels.sh index 2a8054b5..76ed3ee2 100755 --- a/scripts/internal/manylinux-build-wheels.sh +++ b/scripts/internal/manylinux-build-wheels.sh @@ -15,6 +15,16 @@ # DOCKER_ARGS="-v /path/to/lib.so:/usr/local/lib64/lib.so" # /tmp/dockcross-manylinux-x64 -a "$DOCKER_ARGS" manylinux-build-wheels.sh # +# The specialized manylinux container version should be set prior to running this script. +# See https://github.com/dockcross/dockcross for available versions and tags. +# +# For example, `docker run -e ` can be used to set an environment variable when launching a container: +# +# export MANYLINUX_VERSION=2014 +# docker run --rm dockcross/manylinux${MANYLINUX_VERSION}-x64:${IMAGE_TAG} > /tmp/dockcross-manylinux-x64 +# chmod u+x /tmp/dockcross-manylinux-x64 +# /tmp/dockcross-manylinux-x64 -e MANYLINUX_VERSION manylinux-build-module-wheels.sh cp39 +# # ----------------------------------------------------------------------- # These variables are set in common script: diff --git a/scripts/manylinux_2_28_aarch64-build-module-wheels.sh b/scripts/manylinux_2_28_aarch64-build-module-wheels.sh index 6f15c537..9cf470ad 100755 --- a/scripts/manylinux_2_28_aarch64-build-module-wheels.sh +++ b/scripts/manylinux_2_28_aarch64-build-module-wheels.sh @@ -16,9 +16,17 @@ # export LD_LIBRARY_PATH="/path/to/OpenCL.so:/path/to/OpenCL.so.1.2" # scripts/dockcross-manylinux-build-module-wheels.sh cp39 # +# A specialized manylinux image and tag can be used by exporting to MANYLINUX_VERSION before +# running this script. Default is _2_28_aarch64. +# +# For example, +# +# export MANYLINUX_VERSION=2014 +# export IMAGE_TAG=20221108-102ebcc +# scripts/dockcross-manylinux-build-module-wheels.sh cp39 -MANYLINUX_VERSION=_2_28 -IMAGE_TAG=latest +MANYLINUX_VERSION=${MANYLINUX_VERSION:=_2_28_aarch64} +IMAGE_TAG=${IMAGE_TAG:=latest} script_dir=$(cd $(dirname $0) || exit 1; pwd) @@ -35,4 +43,4 @@ if [[ -n ${LD_LIBRARY_PATH} ]]; then fi docker run --privileged --rm tonistiigi/binfmt --install all -docker run --rm -it $DOCKER_ARGS -v $(pwd):/work/ quay.io/pypa/manylinux${MANYLINUX_VERSION}_aarch64:${IMAGE_TAG} "/ITKPythonPackage/scripts/internal/manylinux-aarch64-build-module-wheels.sh" "$@" +docker run --rm -it $DOCKER_ARGS -v $(pwd):/work/ quay.io/pypa/manylinux${MANYLINUX_VERSION}:${IMAGE_TAG} "/ITKPythonPackage/scripts/internal/manylinux-aarch64-build-module-wheels.sh" "$@"