Last active
May 2, 2019 11:56
-
-
Save arnobaer/935ce329749058f293483aa98593d5cf to your computer and use it in GitHub Desktop.
Build utm python wheels with included c++ libraries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Requires manylinux1 docker image | |
# | |
# Run 'init' on local host machine, then 'build', 'install' and 'wheel' from docher image. | |
# Note: wget will not work from manylinux1 docker image due to dreadful outdated OpenSSL! | |
# | |
# Docker instructions | |
# | |
# $ docker pull quay.io/pypa/manylinux1_x86_64 | |
# $ docker run -i -t -v `pwd`:/io quay.io/pypa/manylinux1_x86_64 /bin/bash | |
# | |
set -eE | |
set -o errtrace | |
utm_tag=0.7.3 | |
boost_version=1.70.0 | |
boost_area=boost_1_70_0 | |
boost_tarball=${boost_area}.tar.gz | |
boost_url=https://dl.bintray.com/boostorg/release/${boost_version}/source/${boost_tarball} | |
boost_configure="./bootstrap.sh" | |
boost_make="./b2 --with-filesystem --with-system" | |
boost_install="./b2 install" | |
xerces_version=3.2.2 | |
xerces_area=xerces-c-${xerces_version} | |
xerces_tarball=${xerces_area}.tar.gz | |
xerces_url=http://mirror.klaus-uwe.me/apache//xerces/c/3/sources/${xerces_tarball} | |
xerces_configure="./configure --disable-static" | |
xerces_make="make" | |
xerces_install="make install" | |
swig_version=4.0.0 | |
swig_area=swig-rel-${swig_version} | |
swig_tarball=rel-${swig_version}.tar.gz | |
swig_url=https://github.com/swig/swig/archive/${swig_tarball} | |
swig_configure="./autogen.sh && ./configure" | |
swig_make="make" | |
swig_install="make install" | |
python27_version=2.7.10 | |
python27_area=Python-${python27_version} | |
python27_tarball=${python27_area}.tgz | |
python27_url=https://www.python.org/ftp/python/${python27_version}/${python27_tarball} | |
python27_bin=python${python27_version%.*} | |
python27_configure="./configure" | |
python27_make="make" | |
python27_install="make install" | |
python34_version=3.4.10 | |
python34_area=Python-${python34_version} | |
python34_tarball=${python34_area}.tgz | |
python34_url=https://www.python.org/ftp/python/${python34_version}/${python34_tarball} | |
python34_bin=python${python34_version%.*} | |
python27_configure="./configure" | |
python27_make="make" | |
python27_install="make install" | |
python35_version=3.5.7 | |
python35_area=Python-${python35_version} | |
python35_tarball=${python35_area}.tgz | |
python35_url=https://www.python.org/ftp/python/${python35_version}/${python35_tarball} | |
python35_bin=python${python35_version%.*} | |
python27_configure="./configure" | |
python27_make="make" | |
python27_install="make install" | |
python36_version=3.6.8 | |
python36_area=Python-${python36_version} | |
python36_tarball=${python36_area}.tgz | |
python35_url=https://www.python.org/ftp/python/${python36_version}/${python36_tarball} | |
python36_bin=python${python36_version%.*} | |
python27_configure="./configure" | |
python27_make="make" | |
python27_install="make install" | |
python37_version=3.7.3 | |
python37_area=Python-${python37_version} | |
python37_tarball=${python37_area}.tgz | |
python37_url=https://www.python.org/ftp/python/${python37_version}/${python37_tarball} | |
python37_bin=python${python37_version%.*} | |
python27_configure="./configure" | |
python27_make="make" | |
python27_install="make install" | |
tools=(boost xerces swig python27 python34) | |
system_dependecies="zlib-devel openssl-devel pcre-devel" | |
build_area=$(pwd -P) | |
script_name=$(basename ${0}) | |
# Access variable by string representation | |
# project=foo; get "${project}_version" # returns value of $foo_version | |
function get { | |
local var=${1:?missing variable name} | |
echo ${!var} | |
} | |
# Colorful logging base function | |
function log { | |
local level="${1}" | |
local color="${2}" | |
local message="${@:3}" | |
if [ -t 1 ]; then | |
echo -e "\033[${color};1m${level}\033[0m \033[${color}m${message}\033[0m" | |
else | |
echo "${level} ${message}" | |
fi | |
} | |
# Logging info message | |
function info { | |
log ${FUNCNAME[0]^^} 32 ${@} | |
} | |
# Logging warning message | |
function warning { | |
log ${FUNCNAME[0]^^} 33 ${@} | |
} | |
# Logging error message | |
function error { | |
log ${FUNCNAME[0]^^} 31 ${@} | |
} | |
# Clone project source from tarball | |
function _clone { | |
set -euo pipefail | |
project=${1:?missing project name} | |
version=$(get ${project}_version) | |
area=$(get ${project}_area) | |
tarball=$(get ${project}_tarball) | |
url=$(get ${project}_url) | |
info "cloning ${project} version ${version} ..." | |
cd ${build_area} | |
if [ ! -d ${area} ]; then | |
if [ ! -f ${tarball} ]; then | |
wget ${url} -O ${tarball} | |
fi | |
case "${tarball##*.}" in | |
"tar") | |
tar xf ${tarball} | |
;; | |
"gz" | "tgz") | |
tar xzf ${tarball} | |
;; | |
"zip" | "tgz") | |
unzip ${tarball} | |
;; | |
esac | |
fi | |
info "done." | |
} | |
function cmd_clone { | |
set -euo pipefail | |
for tool in ${tools[@]}; do | |
_clone ${tool} | |
done | |
} | |
function _build { | |
set -euo pipefail | |
project=${1:?missing project name} | |
version=$(get ${project}_version) | |
area=$(get ${project}_area) | |
info "building ${project} version ${version} ..." | |
cd ${build_area} | |
cd ${area} | |
if [ ! -f .lock ]; then | |
info "configure..." | |
$(get ${project}_configure) | |
info "build..." | |
$(get ${project}_make) | |
info "lock..." | |
touch .lock | |
fi | |
info "done." | |
} | |
function cmd_build { | |
set -euo pipefail | |
info "install system build dependencies..." | |
#yum install -y ${system_dependecies} | |
info "done." | |
for tool in ${tools[@]}; do | |
_build ${tool} | |
done | |
} | |
function cmd_install { | |
set -euo pipefail | |
echo "install boost version ${boost_version}..." | |
cd ${build_area} | |
cd ${boost_area} | |
./b2 install | |
echo "done." | |
echo "install xerces-c version ${xerces_version}..." | |
cd ${build_area} | |
cd ${xerces_area} | |
make install | |
echo "done." | |
echo "install python version ${python27_version}..." | |
cd ${build_area} | |
cd ${python27_area} | |
make install | |
echo "done." | |
echo "install python version ${python37_version}..." | |
cd ${build_area} | |
cd ${python37_area} | |
make install | |
echo "done." | |
} | |
function cmd_wheel { | |
info "create python wheels..." | |
cd ${build_area} | |
# TODO | |
echo ":: ${@}" | |
info "done." | |
} | |
function show_help { | |
echo "usage: ${script_name} <command>" | |
echo "commands:" | |
echo " clone clone dependencies (host)" | |
echo " build build dependencies (docker)" | |
echo " install install dependencies (docker)" | |
echo " wheel create python wheels (docker)" | |
echo " help show this information" | |
} | |
function main { | |
case "${1}" in | |
"clone") | |
cmd_clone ${@:2} | |
;; | |
"build") | |
cmd_build ${@:2} | |
;; | |
"install") | |
cmd_install ${@:2} | |
;; | |
"wheel") | |
cmd_wheel ${@:2} | |
;; | |
*) | |
show_help | |
;; | |
esac | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment