• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# Install CMake 3.16
24apt-get update && apt-get install -y wget
25wget -q -O cmake-linux.sh https://github.com/Kitware/CMake/releases/download/v3.16.1/cmake-3.16.1-Linux-x86_64.sh
26sh cmake-linux.sh -- --skip-license --prefix=/usr
27rm cmake-linux.sh
28
29# Build and install gRPC for the host architecture.
30# We do this because we need to be able to run protoc and grpc_cpp_plugin
31# while cross-compiling.
32mkdir -p "cmake/build"
33pushd "cmake/build"
34cmake \
35  -DCMAKE_BUILD_TYPE=Release \
36  -DgRPC_INSTALL=ON \
37  -DgRPC_BUILD_TESTS=OFF \
38  -DgRPC_SSL_PROVIDER=package \
39  ../..
40make -j4 install
41popd
42
43# Download raspberry pi toolchain.
44mkdir -p "/tmp/raspberrypi_root"
45pushd "/tmp/raspberrypi_root"
46git clone https://github.com/raspberrypi/tools raspberrypi-tools
47cd raspberrypi-tools && git checkout 4a335520900ce55e251ac4f420f52bf0b2ab6b1f && cd ..
48
49# Write a toolchain file to use for cross-compiling.
50cat > toolchain.cmake <<'EOT'
51SET(CMAKE_SYSTEM_NAME Linux)
52SET(CMAKE_SYSTEM_PROCESSOR arm)
53set(devel_root /tmp/raspberrypi_root)
54set(CMAKE_STAGING_PREFIX ${devel_root}/stage)
55set(tool_root ${devel_root}/raspberrypi-tools/arm-bcm2708)
56set(CMAKE_SYSROOT ${tool_root}/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/sysroot)
57set(CMAKE_C_COMPILER ${tool_root}/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc)
58set(CMAKE_CXX_COMPILER ${tool_root}/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++)
59set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
60set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
61set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
62set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
63EOT
64popd
65
66# Build and install gRPC for raspberry pi.
67# This build will use the host architecture copies of protoc and
68# grpc_cpp_plugin that we built earlier because we installed them
69# to a location in our PATH (/usr/local/bin).
70mkdir -p "cmake/raspberrypi_build"
71pushd "cmake/raspberrypi_build"
72cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/raspberrypi_root/toolchain.cmake \
73      -DCMAKE_BUILD_TYPE=Release \
74      -DCMAKE_INSTALL_PREFIX=/tmp/raspberrypi_root/grpc_install \
75      ../..
76make -j4 install
77popd
78
79# Build helloworld example for raspberry pi.
80# As above, it will find and use protoc and grpc_cpp_plugin
81# for the host architecture.
82mkdir -p "examples/cpp/helloworld/cmake/raspberrypi_build"
83pushd "examples/cpp/helloworld/cmake/raspberrypi_build"
84cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/raspberrypi_root/toolchain.cmake \
85      -DCMAKE_BUILD_TYPE=Release \
86      -DProtobuf_DIR=/tmp/raspberrypi_root/stage/lib/cmake/protobuf \
87      -DgRPC_DIR=/tmp/raspberrypi_root/stage/lib/cmake/grpc \
88      ../..
89make
90popd
91