|
| 1 | +#!/bin/bash |
| 2 | +# build wheel for python version specified in $PYTHON |
| 3 | + |
| 4 | +set -e -x |
| 5 | + |
| 6 | +export PYTHON_MINOR_VERSION="${PYTHON_MINOR_VERSION}" |
| 7 | +PYTHON="python3${PYTHON_MINOR_VERSION:+.$PYTHON_MINOR_VERSION}" |
| 8 | + |
| 9 | +function write_to_bazelrc() { |
| 10 | + echo "$1" >> .bazelrc |
| 11 | +} |
| 12 | + |
| 13 | +function main() { |
| 14 | + # Remove .bazelrc if it already exists |
| 15 | + [ -e .bazelrc ] && rm .bazelrc |
| 16 | + |
| 17 | + write_to_bazelrc "build -c opt" |
| 18 | + write_to_bazelrc "build --cxxopt=-std=c++17" |
| 19 | + write_to_bazelrc "build --host_cxxopt=-std=c++17" |
| 20 | + write_to_bazelrc "build --linkopt=\"-lrt -lm\"" |
| 21 | + write_to_bazelrc "build --experimental_repo_remote_exec" |
| 22 | + write_to_bazelrc "build --action_env=PYTHON_BIN_PATH=\"/usr/bin/$PYTHON\"" |
| 23 | + write_to_bazelrc "build --action_env=PYTHON_LIB_PATH=\"/usr/lib/$PYTHON\"" |
| 24 | + write_to_bazelrc "build --python_path=\"/usr/bin/$PYTHON\"" |
| 25 | + |
| 26 | + bazel clean |
| 27 | + bazel build $@ ... |
| 28 | + bazel test $@ ... |
| 29 | + |
| 30 | + DEST="/tmp/array_record_pip_pkg" |
| 31 | + # Create the directory, then do dirname on a non-existent file inside it to |
| 32 | + # give us an absolute paths with tilde characters resolved to the destination |
| 33 | + # directory. |
| 34 | + mkdir -p "${DEST}" |
| 35 | + echo "=== destination directory: ${DEST}" |
| 36 | + |
| 37 | + TMPDIR=$(mktemp -d -t tmp.XXXXXXXXXX) |
| 38 | + |
| 39 | + echo $(date) : "=== Using tmpdir: ${TMPDIR}" |
| 40 | + mkdir "${TMPDIR}/array_record" |
| 41 | + |
| 42 | + echo "=== Copy array_record files" |
| 43 | + |
| 44 | + cp setup.py "${TMPDIR}" |
| 45 | + cp LICENSE "${TMPDIR}" |
| 46 | + rsync -avm -L --exclude="bazel-*/" . "${TMPDIR}/array_record" |
| 47 | + rsync -avm -L --include="*.so" --include="*_pb2.py" \ |
| 48 | + --exclude="*.runfiles" --exclude="*_obj" --include="*/" --exclude="*" \ |
| 49 | + bazel-bin/cpp "${TMPDIR}/array_record" |
| 50 | + rsync -avm -L --include="*.so" --include="*_pb2.py" \ |
| 51 | + --exclude="*.runfiles" --exclude="*_obj" --include="*/" --exclude="*" \ |
| 52 | + bazel-bin/python "${TMPDIR}/array_record" |
| 53 | + |
| 54 | + pushd ${TMPDIR} |
| 55 | + echo $(date) : "=== Building wheel" |
| 56 | + ${PYTHON} setup.py bdist_wheel --python-tag py3${PYTHON_MINOR_VERSION} |
| 57 | + |
| 58 | + echo $(date) : "=== Auditing wheel" |
| 59 | + auditwheel repair --plat manylinux2014_x86_64 -w dist dist/*.whl |
| 60 | + cp dist/*.whl "${DEST}" |
| 61 | + popd |
| 62 | + |
| 63 | + echo $(date) : "=== Output wheel file is in: ${DEST}" |
| 64 | +} |
| 65 | + |
| 66 | +main "$@" |
0 commit comments