1#!/bin/bash 2# Copyright 2017 gRPC authors. 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 16set -ex 17 18cd "$(dirname "$0")/../../.." 19 20# Install openssl (to use instead of boringssl) 21apt-get update && apt-get install -y libssl-dev 22 23# Use externally provided env to determine build parallelism, otherwise use default. 24GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS=${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS:-4} 25 26# Build and install gRPC for the host architecture. 27# We do this because we need to be able to run protoc and grpc_cpp_plugin 28# while cross-compiling. 29mkdir -p "cmake/build" 30pushd "cmake/build" 31cmake \ 32 -DCMAKE_BUILD_TYPE=Release \ 33 -DCMAKE_CXX_STANDARD=17 \ 34 -DgRPC_INSTALL=ON \ 35 -DgRPC_BUILD_TESTS=OFF \ 36 -DgRPC_SSL_PROVIDER=package \ 37 ../.. 38make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}" install 39popd 40 41# Write a toolchain file to use for cross-compiling. 42cat > /tmp/toolchain.cmake <<'EOT' 43SET(CMAKE_SYSTEM_NAME Linux) 44SET(CMAKE_SYSTEM_PROCESSOR aarch64) 45set(CMAKE_STAGING_PREFIX /tmp/stage) 46set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc-10) 47set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++-10) 48set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 49set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 50set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 51set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 52EOT 53 54# Build and install gRPC for ARM. 55# This build will use the host architecture copies of protoc and 56# grpc_cpp_plugin that we built earlier because we installed them 57# to a location in our PATH (/usr/local/bin). 58mkdir -p "cmake/build_arm" 59pushd "cmake/build_arm" 60cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake \ 61 -DCMAKE_BUILD_TYPE=Release \ 62 -DCMAKE_CXX_STANDARD=17 \ 63 -DCMAKE_INSTALL_PREFIX=/tmp/install \ 64 ../.. 65make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}" install 66popd 67 68# Build helloworld example for ARM. 69# As above, it will find and use protoc and grpc_cpp_plugin 70# for the host architecture. 71mkdir -p "examples/cpp/helloworld/cmake/build_arm" 72pushd "examples/cpp/helloworld/cmake/build_arm" 73cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake \ 74 -DCMAKE_BUILD_TYPE=Release \ 75 -DCMAKE_CXX_STANDARD=17 \ 76 -Dabsl_DIR=/tmp/stage/lib/cmake/absl \ 77 -DProtobuf_DIR=/tmp/stage/lib/cmake/protobuf \ 78 -Dutf8_range_DIR=/tmp/stage/lib/cmake/utf8_range \ 79 -DgRPC_DIR=/tmp/stage/lib/cmake/grpc \ 80 ../.. 81make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}" 82popd 83