Python Build grpcio From Source (with OpenSSL)

November 21, 2020

By default (at least since v1.33.2), grpc is build with boringssl.

Perform the following to compile grpc with OpenSSL instead.

export REPO_ROOT=grp
git clone -b v1.33.2 https://github.com/grpc/grpc $REPO_ROOT
cd $REPO_ROOT
git submodule update --init
pip install -rrequirements.txt

GRPC_PYTHON_BUILD_WITH_CYTHON=1 GRPC_BUILD_WITH_BORING_SSL_ASM=0 pip install .

The following doesn’t work

GRPC_PYTHON_BUILD_WITH_CYTHON=1 GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 GRPC_BUILD_WITH_BORING_SSL_ASM=0 pip install .
GRPC_PYTHON_BUILD_WITH_CYTHON=1 GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 pip install .

due to

/usr/bin/ld: python_build/temp.linux-x86_64-3.8/third_party/boringssl-with-bazel/linux-x86_64/crypto/chacha/chacha-x86_64.o: in function `ChaCha20_ctr32':
  /tmp/pip-req-build-i1hyvo8u/third_party/boringssl-with-bazel/linux-x86_64/crypto/chacha/chacha-x86_64.S:56: undefined reference to `OPENSSL_ia32cap_P'
  /usr/bin/ld: python_build/temp.linux-x86_64-3.8/third_party/boringssl-with-bazel/linux-x86_64/crypto/chacha/chacha-x86_64.o: relocation R_X86_64_PC32 against undefined hidden symbol `OPENSSL_ia32cap_P' can not be used when making a shared object
  /usr/bin/ld: final link failed: bad value

If you bump into gcc: fatal error: Killed signal terminated program cc1plus, it is probably due to out of memory.

References:

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.