|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# |
| 4 | +# Builds autonomous Python packages including all available dependencies |
| 5 | +# using docker. |
| 6 | +# |
| 7 | +# This is a tiny linux alternative to cibuildwheel as a workaround |
| 8 | +# to provide --volumes-from=.. on docker-in-docker builds. |
| 9 | +# |
| 10 | + |
| 11 | +if [[ $# -lt 3 ]]; then |
| 12 | + echo "Usage: $0 <librdkafka_tag> <repo-dir-full-path> <relative-out-dir>" |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | + |
| 16 | +set -ex |
| 17 | + |
| 18 | +if [[ $1 != "--in-docker" ]]; then |
| 19 | + # Outside our docker |
| 20 | + workdir=$2 |
| 21 | + if [[ -f /.dockerenv ]]; then |
| 22 | + echo "$0: $HOSTNAME: Currently running from inside docker: exposing host mounts" |
| 23 | + docker run -i --volumes-from=$HOSTNAME quay.io/pypa/manylinux1_x86_64 $workdir/tools/build-linux-selfcontained.sh --in-docker $1 $2 $3 |
| 24 | + else |
| 25 | + echo "$0: $HOSTNAME: Not currently running from inside docker: exposing $2 as volume" |
| 26 | + docker run -i -v $workdir:$workdir quay.io/pypa/manylinux1_x86_64 $workdir/tools/build-linux-selfcontained.sh --in-docker $1 $2 $3 |
| 27 | + fi |
| 28 | + exit 0 |
| 29 | +fi |
| 30 | + |
| 31 | +# |
| 32 | +# Inside our docker |
| 33 | +# |
| 34 | + |
| 35 | +echo "$0: $HOSTNAME: Run" |
| 36 | + |
| 37 | +shift # remove --in-docker |
| 38 | + |
| 39 | +LIBRDKAFKA_VERSION=$1 |
| 40 | +WORKDIR=$2 |
| 41 | +OUTDIR=$3 |
| 42 | + |
| 43 | + |
| 44 | +function install_deps { |
| 45 | + echo "# Installing basic system dependencies" |
| 46 | + if which apt-get >/dev/null 2>&1; then |
| 47 | + sudo apt-get -y install gcc g++ zlib1g-dev libssl-dev |
| 48 | + else |
| 49 | + yum install -y zlib-devel gcc gcc-c++ libstdc++-devel |
| 50 | + |
| 51 | + # Build OpenSSL |
| 52 | + $(dirname $0)/build-openssl.sh /usr |
| 53 | + |
| 54 | + fi |
| 55 | +} |
| 56 | + |
| 57 | +function build_librdkafka { |
| 58 | + local dest=$1 |
| 59 | + echo "# Building librdkafka ${LIBRDKAFKA_VERSION}" |
| 60 | + $(dirname $0)/bootstrap-librdkafka.sh --require-ssl ${LIBRDKAFKA_VERSION} $dest |
| 61 | + |
| 62 | +} |
| 63 | + |
| 64 | + |
| 65 | +function build { |
| 66 | + local workdir=$1 |
| 67 | + local outdir=$2 |
| 68 | + |
| 69 | + pushd $workdir |
| 70 | + |
| 71 | + install_deps |
| 72 | + |
| 73 | + build_librdkafka /usr |
| 74 | + |
| 75 | + mkdir -p $outdir |
| 76 | + |
| 77 | + for PYBIN in /opt/python/cp27-*/bin; do |
| 78 | + # Setup |
| 79 | + rm -rf /tmp/built_wheel |
| 80 | + rm -rf /tmp/delocated_wheel |
| 81 | + mkdir /tmp/built_wheel |
| 82 | + mkdir /tmp/delocated_wheel |
| 83 | + |
| 84 | + # Build that wheel |
| 85 | + PATH="$PYBIN:$PATH" "$PYBIN/pip" wheel . -w /tmp/built_wheel --no-deps |
| 86 | + built_wheel=(/tmp/built_wheel/*.whl) |
| 87 | + |
| 88 | + # Delocate the wheel |
| 89 | + # NOTE: 'built_wheel' here is a bash array of glob matches; "$built_wheel" returns |
| 90 | + # the first element |
| 91 | + if [[ "$built_wheel" == *none-any.whl ]]; then |
| 92 | + # pure python wheel - just copy |
| 93 | + mv "$built_wheel" /tmp/delocated_wheel |
| 94 | + else |
| 95 | + auditwheel repair "$built_wheel" -w /tmp/delocated_wheel |
| 96 | + fi |
| 97 | + delocated_wheel=(/tmp/delocated_wheel/*.whl) |
| 98 | + |
| 99 | + # Install the wheel we just built |
| 100 | + "$PYBIN/pip" install "$delocated_wheel" |
| 101 | + |
| 102 | + # we're all done here; move it to output |
| 103 | + mv "$delocated_wheel" $outdir/ |
| 104 | + done |
| 105 | + |
| 106 | + popd # workdir |
| 107 | +} |
| 108 | + |
| 109 | +build $WORKDIR $OUTDIR |
| 110 | + |
0 commit comments