1#!/bin/bash 2# Copyright 2020 Google LLC 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15################################################################################ 16 17# This script builds binary wheels of Tink for Linux based on PEP 599. It 18# should be run inside a manylinux2014 Docker container to have the correct 19# environment setup. 20 21set -euo pipefail 22 23# The following assoicative array contains: 24# ["<Python version>"]="<python tag>-<abi tag>" 25# where: 26# <Python version> = language version, e.g "3.7" 27# <python tag>, <abi tag> = as defined at 28# https://packaging.python.org/en/latest/specifications/, e.g. "cp37-37m" 29declare -A PYTHON_VERSIONS 30PYTHON_VERSIONS["3.7"]="cp37-cp37m" 31PYTHON_VERSIONS["3.8"]="cp38-cp38" 32PYTHON_VERSIONS["3.9"]="cp39-cp39" 33PYTHON_VERSIONS["3.10"]="cp310-cp310" 34readonly -A PYTHON_VERSIONS 35 36export TINK_PYTHON_ROOT_PATH="${PWD}" 37export ARCH="$(uname -m)" 38 39# Install Bazelisk 1.17.0. 40readonly BAZELISK_VERSION="1.17.0" 41BAZELISK_URL="https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK_VERSION}/bazelisk-linux-amd64" 42BAZELISK_SHA256="61699e22abb2a26304edfa1376f65ad24191f94a4ffed68a58d42b6fee01e124" 43if [[ "${ARCH}" == "aarch64" || "${ARCH}" == "arm64" ]]; then 44 BAZELISK_URL="https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK_VERSION}/bazelisk-linux-arm64" 45 BAZELISK_SHA256="a836972b8a7c34970fb9ecc44768ece172f184c5f7e2972c80033fcdcf8c1870" 46fi 47readonly BAZELISK_URL 48readonly BAZELISK_SHA256 49curl -LsS "${BAZELISK_URL}" -o /usr/local/bin/bazelisk 50echo "${BAZELISK_SHA256} /usr/local/bin/bazelisk" | sha256sum -c 51chmod +x /usr/local/bin/bazelisk 52 53# Install protoc 21.12 (python version 4.21.12). Needed for protocol buffer 54# compilation. 55readonly PROTOC_RELEASE_TAG="21.12" 56PROTOC_URL="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_RELEASE_TAG}/protoc-${PROTOC_RELEASE_TAG}-linux-x86_64.zip" 57PROTOC_SHA256="3a4c1e5f2516c639d3079b1586e703fc7bcfa2136d58bda24d1d54f949c315e8" 58if [[ "${ARCH}" == "aarch64" || "${ARCH}" == "arm64" ]]; then 59 PROTOC_URL="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_RELEASE_TAG}/protoc-${PROTOC_RELEASE_TAG}-linux-aarch_64.zip" 60 PROTOC_SHA256="2dd17f75d66a682640b136e31848da9fb2eefe68d55303baf8b32617374f6711" 61fi 62readonly PROTOC_URL 63readonly PROTOC_SHA256 64curl -LsS "${PROTOC_URL}" -o protoc.zip 65echo "${PROTOC_SHA256} protoc.zip" | sha256sum -c 66unzip -o protoc.zip -d /usr/local bin/protoc 67 68# Required to fix https://github.com/pypa/manylinux/issues/357. 69export LD_LIBRARY_PATH="/usr/local/lib" 70 71for v in "${!PYTHON_VERSIONS[@]}"; do 72 ( 73 # Executing in a subshell to make the PATH modification temporary. 74 # This makes shure that `which python3 == 75 # /opt/python/${PYTHON_VERSIONS[$v]}/bin/python3`, which is a symlink of 76 # `/opt/python/${PYTHON_VERSIONS[$v]}/bin/python${v}`. This should allow 77 # pybind11_bazel to pick up the correct Python binary [1]. 78 # 79 # [1] https://github.com/pybind/pybind11_bazel/blob/fc56ce8a8b51e3dd941139d329b63ccfea1d304b/python_configure.bzl#L434 80 export PATH="${PATH}:/opt/python/${PYTHON_VERSIONS[$v]}/bin" 81 python3 -m pip wheel . 82 ) 83done 84 85# Repair wheels to convert them from linux to manylinux. 86for wheel in ./tink*.whl; do 87 auditwheel repair "${wheel}" -w release 88done 89