Skip to content

Commit de79339

Browse files
committed
Add scripts to build Linux module wheels
1 parent a32a061 commit de79339

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Pull dockcross manylinux images
4+
docker pull dockcross/manylinux-x64
5+
#docker pull dockcross/manylinux-x86
6+
7+
# Generate dockcross scripts
8+
docker run dockcross/manylinux-x64 > /tmp/dockcross-manylinux-x64
9+
chmod u+x /tmp/dockcross-manylinux-x64
10+
#docker run dockcross/manylinux-x86 > /tmp/dockcross-manylinux-x86
11+
#chmod u+x /tmp/dockcross-manylinux-x86
12+
13+
script_dir="`cd $(dirname $0); pwd`"
14+
15+
# Build wheels
16+
mkdir -p dist
17+
DOCKER_ARGS="-v $(pwd)/dist:/work/dist/ -v "$script_dir/..":/ITKPythonPackage"
18+
/tmp/dockcross-manylinux-x64 \
19+
-a "$DOCKER_ARGS" \
20+
"/ITKPythonPackage/scripts/internal/manylinux-build-module-wheels.sh" "$@"
21+
#/tmp/dockcross-manylinux-x86 \
22+
# -a "$DOCKER_ARGS" \
23+
# "$script_dir/scripts/internal/manylinux-build-module-wheels.sh" "$@"
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env bash
2+
set -e -x
3+
4+
# Versions can be restricted by passing them in as arguments to the script
5+
# For example,
6+
# manylinux-build-wheels.sh cp27mu cp35
7+
if [[ $# -eq 0 ]]; then
8+
PYBINARIES=(/opt/python/*/bin)
9+
else
10+
PYBINARIES=()
11+
for version in "$@"; do
12+
PYBINARIES+=(/opt/python/*${version}*/bin)
13+
done
14+
fi
15+
16+
# i686 or x86_64 ?
17+
case $(uname -p) in
18+
i686)
19+
arch=x86
20+
;;
21+
x86_64)
22+
arch=x64
23+
;;
24+
*)
25+
die "Unknown architecture $(uname -p)"
26+
;;
27+
esac
28+
29+
echo "Building wheels for $arch"
30+
31+
# Since the python interpreter exports its symbol (see [1]), python
32+
# modules should not link against any python libraries.
33+
# To ensure it is not the case, we configure the project using an empty
34+
# file as python library.
35+
#
36+
# [1] "Note that libpythonX.Y.so.1 is not on the list of libraries that
37+
# a manylinux1 extension is allowed to link to. Explicitly linking to
38+
# libpythonX.Y.so.1 is unnecessary in almost all cases: the way ELF linking
39+
# works, extension modules that are loaded into the interpreter automatically
40+
# get access to all of the interpreter's symbols, regardless of whether or
41+
# not the extension itself is explicitly linked against libpython. [...]"
42+
#
43+
# Source: https://www.python.org/dev/peps/pep-0513/#libpythonx-y-so-1
44+
PYTHON_LIBRARY=/ITKPythonPackage/scripts/internal/manylinux-libpython-not-needed-symbols-exported-by-interpreter
45+
touch ${PYTHON_LIBRARY}
46+
47+
# Compile wheels re-using standalone project and archive cache
48+
for PYBIN in "${PYBINARIES[@]}"; do
49+
if [[ ${PYBIN} == *"cp26"* || ${PYBIN} == *"cp33"* ]]; then
50+
echo "Skipping ${PYBIN}"
51+
continue
52+
fi
53+
54+
PYTHON_EXECUTABLE=${PYBIN}/python
55+
PYTHON_INCLUDE_DIR=$( find -L ${PYBIN}/../include/ -name Python.h -exec dirname {} \; )
56+
57+
echo ""
58+
echo "PYTHON_EXECUTABLE:${PYTHON_EXECUTABLE}"
59+
echo "PYTHON_INCLUDE_DIR:${PYTHON_INCLUDE_DIR}"
60+
echo "PYTHON_LIBRARY:${PYTHON_LIBRARY}"
61+
62+
if [[ -e /work/requirements-dev.txt ]]; then
63+
${PYBIN}/pip install -r /work/requirements-dev.txt
64+
fi
65+
itk_build_dir=/work/ITK-$(basename $(dirname ${PYBIN}))-manylinux1_${arch}
66+
ln -fs /ITKPythonPackage/ITK-$(basename $(dirname ${PYBIN}))-manylinux1_${arch} $itk_build_dir
67+
if [[ ! -d $itk_build_dir ]]; then
68+
echo 'ITK build tree not available!' 1>&2
69+
exit 1
70+
fi
71+
itk_source_dir=/work/standalone-${arch}-build/ITK-source
72+
ln -fs /ITKPythonPackage/standalone-${arch}-build/ /work/standalone-${arch}-build
73+
if [[ ! -d $itk_source_dir ]]; then
74+
echo 'ITK source tree not available!' 1>&2
75+
exit 1
76+
fi
77+
${PYBIN}/python setup.py bdist_wheel --build-type MinSizeRel -G Ninja -- \
78+
-DITK_DIR:PATH=${itk_build_dir} \
79+
-DITK_USE_SYSTEM_SWIG:BOOL=ON \
80+
-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel \
81+
-DSWIG_EXECUTABLE:FILEPATH=${itk_build_dir}/Wrapping/Generators/SwigInterface/swig/bin/swig \
82+
-DCMAKE_CXX_COMPILER_TARGET:STRING=$(uname -p)-linux-gnu \
83+
-DBUILD_TESTING:BOOL=OFF \
84+
-DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE} \
85+
-DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} \
86+
-DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY}
87+
${PYBIN}/python setup.py clean
88+
done
89+
90+
# Since there are no external shared libraries to bundle into the wheels
91+
# this step will fixup the wheel switching from 'linux' to 'manylinux1' tag
92+
for whl in dist/*linux_$(uname -p).whl; do
93+
auditwheel repair $whl -w /work/dist/
94+
rm $whl
95+
done

0 commit comments

Comments
 (0)