protobuf_optimized_pip.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env bash
  2. # DO NOT use this script manually! Called by docker.
  3. set -ex
  4. # Print usage and fail.
  5. function usage() {
  6. echo "Usage: protobuf_optimized_pip.sh PROTOBUF_VERSION" >&2
  7. exit 1 # Causes caller to exit because we use -e.
  8. }
  9. # Build wheel
  10. function build_wheel() {
  11. PYTHON_VERSION=$1
  12. PYTHON_BIN=/opt/python/${PYTHON_VERSION}/bin/python
  13. $PYTHON_BIN setup.py bdist_wheel --cpp_implementation --compile_static_extension
  14. auditwheel repair dist/protobuf-${PROTOBUF_VERSION}-${PYTHON_VERSION}-linux_x86_64.whl
  15. }
  16. # Validate arguments.
  17. if [ $0 != ./protobuf_optimized_pip.sh ]; then
  18. echo "Please run this script from the directory in which it is located." >&2
  19. exit 1
  20. fi
  21. if [ $# -lt 1 ]; then
  22. usage
  23. exit 1
  24. fi
  25. PROTOBUF_VERSION=$1
  26. PYPI_USERNAME=$2
  27. PYPI_PASSWORD=$3
  28. DIR=${PWD}/'protobuf-python-build'
  29. PYTHON_VERSIONS=('cp27-cp27mu' 'cp33-cp33m' 'cp34-cp34m' 'cp35-cp35m' 'cp36-cp36m')
  30. mkdir -p ${DIR}
  31. cd ${DIR}
  32. curl -SsL -O https://github.com/google/protobuf/archive/v${PROTOBUF_VERSION}.tar.gz
  33. tar xzf v${PROTOBUF_VERSION}.tar.gz
  34. cd $DIR/protobuf-${PROTOBUF_VERSION}
  35. # Autoconf on centos 5.11 cannot recognize AC_PROG_OBJC.
  36. sed -i '/AC_PROG_OBJC/d' configure.ac
  37. sed -i 's/conformance\/Makefile//g' configure.ac
  38. # Use the /usr/bin/autoconf and related tools to pick the correct aclocal macros
  39. export PATH="/usr/bin:$PATH"
  40. # Build protoc
  41. ./autogen.sh
  42. CXXFLAGS="-fPIC -g -O2" ./configure
  43. make -j8
  44. export PROTOC=$DIR/src/protoc
  45. cd python
  46. for PYTHON_VERSION in "${PYTHON_VERSIONS[@]}"
  47. do
  48. build_wheel $PYTHON_VERSION
  49. done
  50. /opt/python/cp27-cp27mu/bin/twine upload wheelhouse/*