Repository navigation
Add scripts to build Linux module wheels #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Pull dockcross manylinux images | ||
| docker pull dockcross/manylinux-x64 | ||
| #docker pull dockcross/manylinux-x86 | ||
|
|
||
| # Generate dockcross scripts | ||
| docker run dockcross/manylinux-x64 > /tmp/dockcross-manylinux-x64 | ||
| chmod u+x /tmp/dockcross-manylinux-x64 | ||
| #docker run dockcross/manylinux-x86 > /tmp/dockcross-manylinux-x86 | ||
| #chmod u+x /tmp/dockcross-manylinux-x86 | ||
|
|
||
| script_dir="`cd $(dirname $0); pwd`" | ||
|
|
||
| # Build wheels | ||
| mkdir -p dist | ||
| DOCKER_ARGS="-v $(pwd)/dist:/work/dist/ -v "$script_dir/..":/ITKPythonPackage" | ||
| /tmp/dockcross-manylinux-x64 \ | ||
| -a "$DOCKER_ARGS" \ | ||
| "/ITKPythonPackage/scripts/internal/manylinux-build-module-wheels.sh" "$@" | ||
| #/tmp/dockcross-manylinux-x86 \ | ||
| # -a "$DOCKER_ARGS" \ | ||
| # "$script_dir/scripts/internal/manylinux-build-module-wheels.sh" "$@" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| #!/usr/bin/env bash | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if code with this script should be shared ? See https://github.com/InsightSoftwareConsortium/ITKPythonPackage/blob/master/scripts/internal/manylinux-build-wheels.sh |
||
| set -e -x | ||
|
|
||
| # Versions can be restricted by passing them in as arguments to the script | ||
| # For example, | ||
| # manylinux-build-wheels.sh cp27mu cp35 | ||
| if [[ $# -eq 0 ]]; then | ||
| PYBINARIES=(/opt/python/*/bin) | ||
| else | ||
| PYBINARIES=() | ||
| for version in "$@"; do | ||
| PYBINARIES+=(/opt/python/*${version}*/bin) | ||
| done | ||
| fi | ||
|
|
||
| # i686 or x86_64 ? | ||
| case $(uname -p) in | ||
| i686) | ||
| arch=x86 | ||
| ;; | ||
| x86_64) | ||
| arch=x64 | ||
| ;; | ||
| *) | ||
| die "Unknown architecture $(uname -p)" | ||
| ;; | ||
| esac | ||
|
|
||
| echo "Building wheels for $arch" | ||
|
|
||
| # Since the python interpreter exports its symbol (see [1]), python | ||
| # modules should not link against any python libraries. | ||
| # To ensure it is not the case, we configure the project using an empty | ||
| # file as python library. | ||
| # | ||
| # [1] "Note that libpythonX.Y.so.1 is not on the list of libraries that | ||
| # a manylinux1 extension is allowed to link to. Explicitly linking to | ||
| # libpythonX.Y.so.1 is unnecessary in almost all cases: the way ELF linking | ||
| # works, extension modules that are loaded into the interpreter automatically | ||
| # get access to all of the interpreter's symbols, regardless of whether or | ||
| # not the extension itself is explicitly linked against libpython. [...]" | ||
| # | ||
| # Source: https://www.python.org/dev/peps/pep-0513/#libpythonx-y-so-1 | ||
| PYTHON_LIBRARY=/ITKPythonPackage/scripts/internal/manylinux-libpython-not-needed-symbols-exported-by-interpreter | ||
| touch ${PYTHON_LIBRARY} | ||
|
|
||
| # Compile wheels re-using standalone project and archive cache | ||
| for PYBIN in "${PYBINARIES[@]}"; do | ||
| if [[ ${PYBIN} == *"cp26"* || ${PYBIN} == *"cp33"* ]]; then | ||
| echo "Skipping ${PYBIN}" | ||
| continue | ||
| fi | ||
|
|
||
| PYTHON_EXECUTABLE=${PYBIN}/python | ||
| PYTHON_INCLUDE_DIR=$( find -L ${PYBIN}/../include/ -name Python.h -exec dirname {} \; ) | ||
|
|
||
| echo "" | ||
| echo "PYTHON_EXECUTABLE:${PYTHON_EXECUTABLE}" | ||
| echo "PYTHON_INCLUDE_DIR:${PYTHON_INCLUDE_DIR}" | ||
| echo "PYTHON_LIBRARY:${PYTHON_LIBRARY}" | ||
|
|
||
| if [[ -e /work/requirements-dev.txt ]]; then | ||
| ${PYBIN}/pip install -r /work/requirements-dev.txt | ||
| fi | ||
| itk_build_dir=/work/ITK-$(basename $(dirname ${PYBIN}))-manylinux1_${arch} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That section seems to be the specific one |
||
| ln -fs /ITKPythonPackage/ITK-$(basename $(dirname ${PYBIN}))-manylinux1_${arch} $itk_build_dir | ||
| if [[ ! -d $itk_build_dir ]]; then | ||
| echo 'ITK build tree not available!' 1>&2 | ||
| exit 1 | ||
| fi | ||
| itk_source_dir=/work/standalone-${arch}-build/ITK-source | ||
| ln -fs /ITKPythonPackage/standalone-${arch}-build/ /work/standalone-${arch}-build | ||
| if [[ ! -d $itk_source_dir ]]; then | ||
| echo 'ITK source tree not available!' 1>&2 | ||
| exit 1 | ||
| fi | ||
| ${PYBIN}/python setup.py bdist_wheel --build-type MinSizeRel -G Ninja -- \ | ||
| -DITK_DIR:PATH=${itk_build_dir} \ | ||
| -DITK_USE_SYSTEM_SWIG:BOOL=ON \ | ||
| -DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel \ | ||
| -DSWIG_EXECUTABLE:FILEPATH=${itk_build_dir}/Wrapping/Generators/SwigInterface/swig/bin/swig \ | ||
| -DCMAKE_CXX_COMPILER_TARGET:STRING=$(uname -p)-linux-gnu \ | ||
| -DBUILD_TESTING:BOOL=OFF \ | ||
| -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE} \ | ||
| -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} \ | ||
| -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY} | ||
| ${PYBIN}/python setup.py clean | ||
| done | ||
|
|
||
| # Since there are no external shared libraries to bundle into the wheels | ||
| # this step will fixup the wheel switching from 'linux' to 'manylinux1' tag | ||
| for whl in dist/*linux_$(uname -p).whl; do | ||
| auditwheel repair $whl -w /work/dist/ | ||
| rm $whl | ||
| done | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be usage of the script could be documented here ?