Skip to content

Commit

Permalink
Python wheels for AD Map library (#60)
Browse files Browse the repository at this point in the history
* Added python wheels build
* Publishing to pypi on Release
* Removed static linking on general python build and remove the additional not required module shared library

Co-authored-by: Bernd Gassmann <bernd.gassmann@intel.com>
  • Loading branch information
joel-mb and berndgassmann authored Jul 28, 2021
1 parent 2f7d2f2 commit 78a4c01
Show file tree
Hide file tree
Showing 29 changed files with 566 additions and 432 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

env:
GTEST_OUTPUT: "xml:test_results"
BUILDCMD: "colcon build --event-handlers console_direct+ --executor sequential --cmake-args -DBUILD_HARDENING=ON -DBUILD_TESTING=ON -DBUILD_PYTHON_BINDING=ON && colcon test --event-handlers console_direct+ --packages-select ad_map_access ad_physics && colcon test-result"
BUILDCMD: "colcon build --event-handlers console_direct+ --executor sequential --cmake-args -DBUILD_HARDENING=ON -DBUILD_TESTING=ON -DBUILD_PYTHON_BINDING=ON -DPYTHON_BINDING_VERSION=${PYTHON_BINDING_VERSION} && colcon test --event-handlers console_direct+ --packages-select ad_map_access ad_physics && colcon test-result"

jobs:
ubuntu16job:
Expand All @@ -22,18 +22,22 @@ jobs:
EXTRA_PACKAGES: ""
CC: ""
CXX: ""
PYTHON_BINDING_VERSION: "2.7"
- compiler: gcc6
EXTRA_PACKAGES: g++-6
CC: /usr/bin/gcc-6
CXX: /usr/bin/g++-6
PYTHON_BINDING_VERSION: "2.7"
- compiler: clang5
EXTRA_PACKAGES: clang-5.0
CC: /usr/bin/clang-5.0
CXX: /usr/bin/clang++-5.0
PYTHON_BINDING_VERSION: "2.7"
- compiler: clang6
EXTRA_PACKAGES: clang-6.0
CC: /usr/bin/clang-6.0
CXX: /usr/bin/clang++-6.0
PYTHON_BINDING_VERSION: "2.7"

steps:
- uses: actions/checkout@v2
Expand All @@ -48,6 +52,7 @@ jobs:
CC: ${{ matrix.CC }}
CXX: ${{ matrix.CXX }}
EXTRA_PACKAGES: ${{ matrix.EXTRA_PACKAGES }}
PYTHON_BINDING_VERSION: ${{ matrix.PYTHON_BINDING_VERSION }}
run: |
sudo apt-get install ${EXTRA_PACKAGES}
rm -rf log build install
Expand All @@ -64,22 +69,27 @@ jobs:
EXTRA_PACKAGES: ""
CC: ""
CXX: ""
PYTHON_BINDING_VERSION: "2.7"
- compiler: gcc8
EXTRA_PACKAGES: g++-8
CC: /usr/bin/gcc-8
CXX: /usr/bin/g++-8
PYTHON_BINDING_VERSION: "3.6"
- compiler: gcc9
EXTRA_PACKAGES: g++-9
CC: /usr/bin/gcc-9
CXX: /usr/bin/g++-9
PYTHON_BINDING_VERSION: "3.6"
- compiler: clang7
EXTRA_PACKAGES: clang-7
CC: /usr/bin/clang-7
CXX: /usr/bin/clang++-7
PYTHON_BINDING_VERSION: "3.6"
- compiler: clang8
EXTRA_PACKAGES: clang-8
CC: /usr/bin/clang-8
CXX: /usr/bin/clang++-8
PYTHON_BINDING_VERSION: "3.6"

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -110,6 +120,7 @@ jobs:
EXTRA_PACKAGES: ""
CC: ""
CXX: ""
PYTHON_BINDING_VERSION: "3.8"

steps:
- uses: actions/checkout@v2
Expand Down
11 changes: 3 additions & 8 deletions .github/workflows/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install -y --no-install-recommends build-essential castxml cmake libboost-all-dev libgtest-dev liblapacke-dev libopenblas-dev libproj-dev libpugixml-dev libpython3-dev python python-setuptools python3 python3-pip python3-setuptools python3-wheel

if [ `lsb_release -a | grep Release | grep 20.04 | wc -l` == 1 ]; then
if [ `lsb_release -a | grep Release | grep 20.04 | wc -l` == 1 ]; then
sudo apt-get install -y --no-install-recommends python-is-python3
else
sudo apt-get install -y --no-install-recommends python-pip python-wheel
fi
sudo pip3 install --upgrade setuptools==51.1.2
sudo pip3 install colcon-common-extensions xmlrunner
sudo pip3 install colcon-common-extensions xmlrunner pygccxml pyplusplus

if [ `lsb_release -a | grep Release | grep 20.04 | wc -l` == 1 ]; then
sudo pip3 install pygccxml pyplusplus
else
if [ `lsb_release -a | grep Release | grep 20.04 | wc -l` != 1 ]; then
sudo pip2 install --upgrade setuptools==41.1.0
sudo pip2 install pygccxml pyplusplus xmlrunner
fi



8 changes: 6 additions & 2 deletions .github/workflows/release_qgis_plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ jobs:
include:
- os: ubuntu-18.04
artifact_name: ad_map_access_qgis_ubuntu1804.zip
PYTHON_BINDING_VERSION: "3.6"
- os: ubuntu-20.04
artifact_name: ad_map_access_qgis_ubuntu2004.zip
PYTHON_BINDING_VERSION: "3.8"

steps:
- uses: actions/checkout@v2
Expand All @@ -30,13 +32,15 @@ jobs:
run: bash .github/workflows/install_dependencies.sh

- name: Build Libraries
env:
PYTHON_BINDING_VERSION: ${{ matrix.PYTHON_BINDING_VERSION }}
run: |
colcon build --event-handlers console_direct+ --executor sequential --metas colcon_python.meta --build-base build-static --install-base install-static
colcon build --event-handlers console_direct+ --executor sequential --metas colcon_python.meta --build-base build-static --install-base install-static --cmake-args -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DPYTHON_BINDING_VERSION=${PYTHON_BINDING_VERSION}
- name: Build Package
run: |
cd install-static
cp -r ad_map_access/lib/python3.*/ad_map_access ad_map_access_qgis/share/qgis/python/plugins/ad_map_access_qgis/.
cp -r ad_map_access/lib/python3.*/site-packages/ad_map_access ad_map_access_qgis/share/qgis/python/plugins/ad_map_access_qgis/.
cd ad_map_access_qgis/share/qgis/python/plugins/
zip -r ${{ matrix.artifact_name }} ad_map_access_qgis/
mv ${{ matrix.artifact_name }} ../../../../../../
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build and Publish wheels for AD-Map Library

on:
release:
types: [published]
push:
branches: master
pull_request:
branches: master

jobs:
wheels:
runs-on: ubuntu-latest
strategy:
matrix:
python_binding_version: [2.7, 3.6, 3.7, 3.8]
container:
image: joelmb/map:${{ matrix.python_binding_version }}
env:
WHEEL_PLATFORM: manylinux_2_27_x86_64
PYTHON_BINDING_VERSION: ${{ matrix.python_binding_version }}
steps:
# We currently cannot use checkout@v2 because git version on the docker images is below 2.18
- uses: actions/checkout@v1
with:
fetch-depth: 1
submodules: true
- name: Build wheels
run: |
colcon build --packages-up-to ad_map_access --meta colcon_python.meta --event-handlers console_direct+ --cmake-args -DPYTHON_BINDING_VERSION=${PYTHON_BINDING_VERSION}
- name: Repair wheels
shell: bash
run: |
source install/setup.bash
for whl in install/ad_physics/dist/*.whl; do
auditwheel repair $whl --plat ${WHEEL_PLATFORM} --wheel-dir wheelhouse
done
for whl in install/ad_map_access/dist/*.whl; do
auditwheel repair $whl --plat ${WHEEL_PLATFORM} --wheel-dir wheelhouse
done
- name: Publish wheels to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: ${{ github.event_name == 'release'}}
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: wheelhouse/
54 changes: 54 additions & 0 deletions .github/workflows/wheels/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
ARG PYTHON_BINDING_VERSION

FROM ubuntu:18.04 AS ubuntu

ARG PYTHON_BINDING_VERSION

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
cmake \
git \
unzip \
wget \
autoconf \
automake \
castxml \
libpugixml-dev && \
rm -rf /var/lib/apt/lists/*

RUN \
if [ ${PYTHON_BINDING_VERSION} = "2.7" ]; then \
PYTHON3_VERSION=3.6 ; \
else \
PYTHON3_VERSION=${PYTHON_BINDING_VERSION} ; \
fi ; \
# Install python libraries
apt-get update && apt-get install -y --no-install-recommends \
python$PYTHON3_VERSION-dev \
python3-pip \
python-dev \
python-pip \
&& rm -rf /var/lib/apt/lists/* ; \
# Install python packages
python$PYTHON3_VERSION -m pip install --upgrade pip ; \
python$PYTHON3_VERSION -m pip install setuptools ; \
python$PYTHON3_VERSION -m pip install wheel auditwheel twine pygccxml pyplusplus colcon-common-extensions ; \
if [ "$PYTHON_BINDING_VERSION" = "2.7" ]; then \
python2.7 -m pip install --upgrade pip; \
python2.7 -m pip install setuptools; \
python2.7 -m pip install install wheel pygccxml pyplusplus; \
fi

WORKDIR /workspace

COPY ./utils .

RUN bash install_patchelf.sh
RUN bash install_boost.sh --python-version $PYTHON_BINDING_VERSION

ENV LD_LIBRARY_PATH "$LD_LIBRARY_PATH:/usr/local/lib"

CMD ["/bin/bash"]
41 changes: 41 additions & 0 deletions .github/workflows/wheels/docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

DOC_STRING="Build Docker image for building manylinux wheels."

USAGE_STRING=$(cat <<- END
Usage: $0 [-h|--help] [-p|--python-version PYTHON_VERSION]
The following python versions are supported:
* 2.7
* 3.6
* 3.7
* 3.8
END
)

usage() { echo "${DOC_STRING}"; echo "${USAGE_STRING}"; exit 1; }

# Defaults
PYTHON_VERSION="3.6"

while [[ $# -gt 0 ]]; do
case "$1" in
-p |--python-version )
PYTHON_VERSION=$2
if [ "${PYTHON_VERSION}" != "2.7" ] && [ "${PYTHON_VERSION}" != "3.6" ] && [ "${PYTHON_VERSION}" != "3.7" ] && [ "${PYTHON_VERSION}" != "3.8" ]; then
usage
fi
shift 2 ;;
-h | --help )
usage
;;
* )
shift ;;
esac
done

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
docker build \
-t map:${PYTHON_VERSION} \
-f Dockerfile ${SCRIPT_DIR} \
--build-arg PYTHON_BINDING_VERSION=${PYTHON_VERSION}
42 changes: 42 additions & 0 deletions .github/workflows/wheels/docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

DOC_STRING="Run Docker image for building manylinux wheels."

USAGE_STRING=$(cat <<- END
Usage: $0 [-h|--help] [-p|--python-version PYTHON_VERSION]
The following python versions are supported:
* 2.7
* 3.6
* 3.7
* 3.8
END
)

usage() { echo "${DOC_STRING}"; echo "${USAGE_STRING}"; exit 1; }

# Defaults
PYTHON_VERSION="3.6"

while [[ $# -gt 0 ]]; do
case "$1" in
-p |--python-version )
PYTHON_VERSION=$2
if [ "${PYTHON_VERSION}" != "2.7" ] && [ "${PYTHON_VERSION}" != "3.6" ] && [ "${PYTHON_VERSION}" != "3.7" ] && [ "${PYTHON_VERSION}" != "3.8" ]; then
usage
fi
shift 2 ;;
-h | --help )
usage
;;
* )
shift ;;
esac
done

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
docker run \
-it \
--rm \
-v ${SCRIPT_DIR}/../../../..:/workspace/map \
map:${PYTHON_VERSION} /bin/bash
63 changes: 63 additions & 0 deletions .github/workflows/wheels/docker/utils/install_boost.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

BOOST_VERSION=1.72.0
BOOST_BASENAME="boost-${BOOST_VERSION}"
BOOST_PACKAGE_BASENAME=boost_${BOOST_VERSION//./_}

DOC_STRING="Build boost."

USAGE_STRING=$(cat <<- END
Usage: $0 [-h|--help] [-p|--python-version PYTHON_VERSION]
The following python versions are supported:
* 2.7
* 3.6
* 3.7
* 3.8
END
)

usage() { echo "${DOC_STRING}"; echo "${USAGE_STRING}"; exit 1; }

# Defaults
PYTHON_VERSION="3.6"

while [[ $# -gt 0 ]]; do
case "$1" in
-p |--python-version )
PYTHON_VERSION=$2
if [ "${PYTHON_VERSION}" != "2.7" ] && [ "${PYTHON_VERSION}" != "3.6" ] && [ "${PYTHON_VERSION}" != "3.7" ] && [ "${PYTHON_VERSION}" != "3.8" ]; then
usage
fi
shift 2 ;;
-h | --help )
usage
;;
* )
shift ;;
esac
done

wget "https://boostorg.jfrog.io/artifactory/main/release/${BOOST_VERSION}/source/${BOOST_PACKAGE_BASENAME}.tar.gz" || true

tar -xzf ${BOOST_PACKAGE_BASENAME}.tar.gz

pushd ${BOOST_PACKAGE_BASENAME} >/dev/null

BOOST_CFLAGS="-fPIC -std=c++14 -DBOOST_ERROR_CODE_HEADER_ONLY"

py="/usr/bin/env python${PYTHON_VERSION}"
py_root=`${py} -c "import sys; print(sys.prefix)"`
pyv=`$py -c "import sys;x='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(x)";`
./bootstrap.sh \
--with-libraries=python,filesystem,system,program_options \
--with-python=${py} --with-python-root=${py_root}

echo "using python : ${pyv} : ${py_root}/bin/python${PYTHON_VERSION} ;" > project-config.jam

./b2 install

popd >/dev/null

rm -rf ${BOOST_PACKAGE_BASENAME}
rm -rf ${BOOST_PACKAGE_BASENAME}.tar.gz
Loading

0 comments on commit 78a4c01

Please sign in to comment.