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