From 160cb1b2153b91f094ef74d0eb505086c0e94aca Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Tue, 2 Mar 2021 08:46:03 -0800 Subject: [PATCH] Changed RPI build test to general ARM build test (#25580) * Change rpi build test to arm test * Having a separate docker and targetting aarch64 --- BUILDING.md | 2 +- ...> run_distrib_test_cmake_aarch64_cross.sh} | 51 ++++++++++--------- .../cpp_stretch_aarch64_cross_x64/Dockerfile | 29 +++++++++++ .../artifacts/distribtest_targets.py | 3 +- 4 files changed, 58 insertions(+), 27 deletions(-) rename test/distrib/cpp/{run_distrib_test_raspberry_pi.sh => run_distrib_test_cmake_aarch64_cross.sh} (60%) create mode 100644 tools/dockerfile/distribtest/cpp_stretch_aarch64_cross_x64/Dockerfile diff --git a/BUILDING.md b/BUILDING.md index 01ffd2a38f4..674d5ed0e8c 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -243,7 +243,7 @@ $ cmake ../.. -DCMAKE_TOOLCHAIN_FILE=path/to/file $ make ``` -[Cross-compile example](test/distrib/cpp/run_distrib_test_raspberry_pi.sh) +[Cross-compile example](test/distrib/cpp/run_distrib_test_cmake_aarch64_cross.sh) ## Building with make on UNIX systems (deprecated) diff --git a/test/distrib/cpp/run_distrib_test_raspberry_pi.sh b/test/distrib/cpp/run_distrib_test_cmake_aarch64_cross.sh similarity index 60% rename from test/distrib/cpp/run_distrib_test_raspberry_pi.sh rename to test/distrib/cpp/run_distrib_test_cmake_aarch64_cross.sh index b1a0ba5ea32..4b8b5221843 100755 --- a/test/distrib/cpp/run_distrib_test_raspberry_pi.sh +++ b/test/distrib/cpp/run_distrib_test_cmake_aarch64_cross.sh @@ -40,51 +40,52 @@ cmake \ make -j4 install popd -# Download raspberry pi toolchain. -mkdir -p "/tmp/raspberrypi_root" -pushd "/tmp/raspberrypi_root" -git clone https://github.com/raspberrypi/tools raspberrypi-tools -cd raspberrypi-tools && git checkout 4a335520900ce55e251ac4f420f52bf0b2ab6b1f && cd .. - # Write a toolchain file to use for cross-compiling. -cat > toolchain.cmake <<'EOT' +cat > /tmp/toolchain.cmake <<'EOT' SET(CMAKE_SYSTEM_NAME Linux) -SET(CMAKE_SYSTEM_PROCESSOR arm) -set(devel_root /tmp/raspberrypi_root) -set(CMAKE_STAGING_PREFIX ${devel_root}/stage) -set(tool_root ${devel_root}/raspberrypi-tools/arm-bcm2708) -set(CMAKE_SYSROOT ${tool_root}/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/sysroot) -set(CMAKE_C_COMPILER ${tool_root}/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc) -set(CMAKE_CXX_COMPILER ${tool_root}/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++) +SET(CMAKE_SYSTEM_PROCESSOR aarch64) +set(CMAKE_STAGING_PREFIX /tmp/stage) +set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc-6) +set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++-6) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) EOT + +# Build and install absl (absl won't be installed down below) +mkdir -p "third_party/abseil-cpp/cmake/build_arm" +pushd "third_party/abseil-cpp/cmake/build_arm" +cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/tmp/install \ + -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \ + ../.. +make -j4 install popd -# Build and install gRPC for raspberry pi. +# Build and install gRPC for ARM. # This build will use the host architecture copies of protoc and # grpc_cpp_plugin that we built earlier because we installed them # to a location in our PATH (/usr/local/bin). -mkdir -p "cmake/raspberrypi_build" -pushd "cmake/raspberrypi_build" -cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/raspberrypi_root/toolchain.cmake \ +mkdir -p "cmake/build_arm" +pushd "cmake/build_arm" +cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake \ -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=/tmp/raspberrypi_root/grpc_install \ + -DCMAKE_INSTALL_PREFIX=/tmp/install \ ../.. make -j4 install popd -# Build helloworld example for raspberry pi. +# Build helloworld example for ARM. # As above, it will find and use protoc and grpc_cpp_plugin # for the host architecture. -mkdir -p "examples/cpp/helloworld/cmake/raspberrypi_build" -pushd "examples/cpp/helloworld/cmake/raspberrypi_build" -cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/raspberrypi_root/toolchain.cmake \ +mkdir -p "examples/cpp/helloworld/cmake/build_arm" +pushd "examples/cpp/helloworld/cmake/build_arm" +cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake \ -DCMAKE_BUILD_TYPE=Release \ - -DProtobuf_DIR=/tmp/raspberrypi_root/stage/lib/cmake/protobuf \ - -DgRPC_DIR=/tmp/raspberrypi_root/stage/lib/cmake/grpc \ + -DProtobuf_DIR=/tmp/stage/lib/cmake/protobuf \ + -DgRPC_DIR=/tmp/stage/lib/cmake/grpc \ ../.. make popd diff --git a/tools/dockerfile/distribtest/cpp_stretch_aarch64_cross_x64/Dockerfile b/tools/dockerfile/distribtest/cpp_stretch_aarch64_cross_x64/Dockerfile new file mode 100644 index 00000000000..e20df959d84 --- /dev/null +++ b/tools/dockerfile/distribtest/cpp_stretch_aarch64_cross_x64/Dockerfile @@ -0,0 +1,29 @@ +# Copyright 2021 The gRPC Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM debian:stretch + +# gRPC C++ dependencies based on https://github.com/grpc/grpc/blob/master/BUILDING.md +RUN apt-get update && apt-get install -y build-essential autoconf libtool pkg-config && apt-get clean + +# debian stretch has cmake 3.7: https://packages.debian.org/stretch/cmake +RUN apt-get update && apt-get install -y cmake && apt-get clean + +# C++ distribtests are setup in a way that requires git +RUN apt-get update && apt-get install -y git && apt-get clean + +# aarch cross-compiler +RUN apt-get update && apt-get install -y g++-6-aarch64-linux-gnu + +CMD ["bash"] diff --git a/tools/run_tests/artifacts/distribtest_targets.py b/tools/run_tests/artifacts/distribtest_targets.py index 484835ba630..cfbd2905a8e 100644 --- a/tools/run_tests/artifacts/distribtest_targets.py +++ b/tools/run_tests/artifacts/distribtest_targets.py @@ -326,7 +326,8 @@ def targets(): CppDistribTest('linux', 'x64', 'stretch', 'cmake_module_install_pkgconfig'), CppDistribTest('linux', 'x64', 'stretch', 'cmake_pkgconfig'), - CppDistribTest('linux', 'x64', 'stretch', 'raspberry_pi'), + CppDistribTest('linux', 'x64', 'stretch_aarch64_cross', + 'cmake_aarch64_cross'), CppDistribTest('windows', 'x86', testcase='cmake'), CppDistribTest('windows', 'x86', testcase='cmake_as_externalproject'), # C#