run_distrib_test_cmake_aarch64_cross.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. set -ex
  16. cd "$(dirname "$0")/../../.."
  17. # Install openssl (to use instead of boringssl)
  18. apt-get update && apt-get install -y libssl-dev
  19. # Install CMake 3.16
  20. apt-get update && apt-get install -y wget
  21. wget -q -O cmake-linux.sh https://github.com/Kitware/CMake/releases/download/v3.16.1/cmake-3.16.1-Linux-x86_64.sh
  22. sh cmake-linux.sh -- --skip-license --prefix=/usr
  23. rm cmake-linux.sh
  24. # Build and install gRPC for the host architecture.
  25. # We do this because we need to be able to run protoc and grpc_cpp_plugin
  26. # while cross-compiling.
  27. mkdir -p "cmake/build"
  28. pushd "cmake/build"
  29. cmake \
  30. -DCMAKE_BUILD_TYPE=Release \
  31. -DgRPC_INSTALL=ON \
  32. -DgRPC_BUILD_TESTS=OFF \
  33. -DgRPC_SSL_PROVIDER=package \
  34. ../..
  35. make -j4 install
  36. popd
  37. # Write a toolchain file to use for cross-compiling.
  38. cat > /tmp/toolchain.cmake <<'EOT'
  39. SET(CMAKE_SYSTEM_NAME Linux)
  40. SET(CMAKE_SYSTEM_PROCESSOR aarch64)
  41. set(CMAKE_STAGING_PREFIX /tmp/stage)
  42. set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc-6)
  43. set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++-6)
  44. set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  45. set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  46. set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  47. set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
  48. EOT
  49. # Build and install absl (absl won't be installed down below)
  50. mkdir -p "third_party/abseil-cpp/cmake/build_arm"
  51. pushd "third_party/abseil-cpp/cmake/build_arm"
  52. cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake \
  53. -DCMAKE_BUILD_TYPE=Release \
  54. -DCMAKE_INSTALL_PREFIX=/tmp/install \
  55. -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \
  56. ../..
  57. make -j4 install
  58. popd
  59. # Build and install gRPC for ARM.
  60. # This build will use the host architecture copies of protoc and
  61. # grpc_cpp_plugin that we built earlier because we installed them
  62. # to a location in our PATH (/usr/local/bin).
  63. mkdir -p "cmake/build_arm"
  64. pushd "cmake/build_arm"
  65. cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake \
  66. -DCMAKE_BUILD_TYPE=Release \
  67. -DCMAKE_INSTALL_PREFIX=/tmp/install \
  68. ../..
  69. make -j4 install
  70. popd
  71. # Build helloworld example for ARM.
  72. # As above, it will find and use protoc and grpc_cpp_plugin
  73. # for the host architecture.
  74. mkdir -p "examples/cpp/helloworld/cmake/build_arm"
  75. pushd "examples/cpp/helloworld/cmake/build_arm"
  76. cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake \
  77. -DCMAKE_BUILD_TYPE=Release \
  78. -DProtobuf_DIR=/tmp/stage/lib/cmake/protobuf \
  79. -DgRPC_DIR=/tmp/stage/lib/cmake/grpc \
  80. ../..
  81. make
  82. popd