Skip to content

Commit 583af7b

Browse files
committed
ENH: macOS remote module scikit-build-core support
In ITK 5.4 RC3, we provide macOS swig binaries. The path in the distribution has changed and is more complex -- just fetch the binaries at build time. Continue to support setup.py from scikit-build classic, but use scikit-build-core with the Stable ABI when setup.py has been migrated to pyproject.toml.
1 parent 1dc4ecb commit 583af7b

File tree

2 files changed

+53
-16
lines changed

2 files changed

+53
-16
lines changed

scripts/macpython-build-common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ usage()
1515
echo "Usage:
1616
macpython-build-common
1717
[ -h | --help ] show usage
18-
[ -c | --cmake_options ] space-separated string of CMake options to forward to the module (e.g. \"-DBUILD_TESTING=OFF\")
18+
[ -c | --cmake_options ] space-separated string of CMake options to forward to the module (e.g. \"--config-setting=cmake.define.BUILD_TESTING=OFF\")
1919
[ -- python_versions ] build wheel for a specific python version(s). (e.g. -- 3.9 3.10)"
2020
exit 2
2121
}

scripts/macpython-build-module-wheels.sh

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ VENVS=()
6262
source "${script_dir}/macpython-build-common.sh"
6363
# -----------------------------------------------------------------------
6464

65+
if test -e setup.py; then
66+
use_skbuild_classic=true
67+
else
68+
use_skbuild_classic=false
69+
fi
70+
71+
6572
VENV="${VENVS[0]}"
6673
Python3_EXECUTABLE=${VENV}/bin/python3
6774
${Python3_EXECUTABLE} -m pip install --no-cache delocate
@@ -81,6 +88,11 @@ for VENV in "${VENVS[@]}"; do
8188
echo "Python3_EXECUTABLE:${Python3_EXECUTABLE}"
8289
echo "Python3_INCLUDE_DIR:${Python3_INCLUDE_DIR}"
8390

91+
if $use_skbuild_classic; then
92+
# So older remote modules with setup.py continue to work
93+
${Python3_EXECUTABLE} -m pip install --upgrade scikit-build
94+
fi
95+
8496
if [[ $(arch) == "arm64" ]]; then
8597
plat_name="macosx-11.0-arm64"
8698
osx_target="11.0"
@@ -95,26 +107,51 @@ for VENV in "${VENVS[@]}"; do
95107
if [[ ! -z "${MACOSX_DEPLOYMENT_TARGET}" ]]; then
96108
osx_target="${MACOSX_DEPLOYMENT_TARGET}"
97109
fi
110+
export MACOSX_DEPLOYMENT_TARGET=${osx_target}
98111

99112
if [[ -e $PWD/requirements-dev.txt ]]; then
100113
${Python3_EXECUTABLE} -m pip install --upgrade -r $PWD/requirements-dev.txt
101114
fi
102115
itk_build_path="${build_path}"
103-
${Python3_EXECUTABLE} setup.py bdist_wheel --build-type Release --plat-name ${plat_name} -G Ninja -- \
104-
-DCMAKE_MAKE_PROGRAM:FILEPATH=${NINJA_EXECUTABLE} \
105-
-DITK_DIR:PATH=${itk_build_path} \
106-
-DCMAKE_INSTALL_LIBDIR:STRING=lib \
107-
-DITK_USE_SYSTEM_SWIG:BOOL=ON \
108-
-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel \
109-
-DSWIG_EXECUTABLE:FILEPATH=${itk_build_path}/Wrapping/Generators/SwigInterface/swig/bin/swig \
110-
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${osx_target} \
111-
-DCMAKE_OSX_ARCHITECTURES:STRING=${osx_arch} \
112-
-DBUILD_TESTING:BOOL=OFF \
113-
-DPython3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE} \
114-
-DPython3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR} \
115-
${CMAKE_OPTIONS} \
116-
|| exit 1
117-
# rm -r ${SKBUILD_DIR} # Permission denied
116+
if $use_skbuild_classic; then
117+
${Python3_EXECUTABLE} setup.py bdist_wheel --build-type Release --plat-name ${plat_name} -G Ninja -- \
118+
-DCMAKE_MAKE_PROGRAM:FILEPATH=${NINJA_EXECUTABLE} \
119+
-DITK_DIR:PATH=${itk_build_path} \
120+
-DCMAKE_INSTALL_LIBDIR:STRING=lib \
121+
-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel \
122+
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${osx_target} \
123+
-DCMAKE_OSX_ARCHITECTURES:STRING=${osx_arch} \
124+
-DBUILD_TESTING:BOOL=OFF \
125+
-DPython3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE} \
126+
-DPython3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR} \
127+
${CMAKE_OPTIONS} \
128+
|| exit 1
129+
else
130+
py_minor=$(echo $py_mm | cut -d '.' -f 2)
131+
wheel_py_api=""
132+
if test $py_minor -ge 11; then
133+
wheel_py_api=cp3$py_minor
134+
fi
135+
${Python3_EXECUTABLE} -m build \
136+
--verbose \
137+
--wheel \
138+
--outdir dist \
139+
--no-isolation \
140+
--skip-dependency-check \
141+
--config-setting=cmake.define.CMAKE_MAKE_PROGRAM:FILEPATH=${NINJA_EXECUTABLE} \
142+
--config-setting=cmake.define.ITK_DIR:PATH=${itk_build_path} \
143+
--config-setting=cmake.define.CMAKE_INSTALL_LIBDIR:STRING=lib \
144+
--config-setting=cmake.define.WRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel \
145+
--config-setting=cmake.define.CMAKE_OSX_DEPLOYMENT_TARGET:STRING=${osx_target} \
146+
--config-setting=cmake.define.CMAKE_OSX_ARCHITECTURES:STRING=${osx_arch} \
147+
--config-setting=cmake.define.PY_SITE_PACKAGES_PATH:PATH="." \
148+
--config-setting=wheel.py-api=$wheel_py_api \
149+
--config-setting=cmake.define.BUILD_TESTING:BOOL=OFF \
150+
--config-setting=cmake.define.Python3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE} \
151+
--config-setting=cmake.define.Python3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR} \
152+
${CMAKE_OPTIONS} \
153+
|| exit 1
154+
fi
118155
done
119156

120157
for wheel in $PWD/dist/*.whl; do

0 commit comments

Comments
 (0)