run_distrib_test_cmake_aarch64_cross.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. # Use externally provided env to determine build parallelism, otherwise use default.
  25. GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS=${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS:-4}
  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.
  29. mkdir -p "cmake/build"
  30. pushd "cmake/build"
  31. cmake \
  32. -DCMAKE_BUILD_TYPE=Release \
  33. -DgRPC_INSTALL=ON \
  34. -DgRPC_BUILD_TESTS=OFF \
  35. -DgRPC_SSL_PROVIDER=package \
  36. ../..
  37. make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}" install
  38. popd
  39. # Write a toolchain file to use for cross-compiling.
  40. cat > /tmp/toolchain.cmake <<'EOT'
  41. SET(CMAKE_SYSTEM_NAME Linux)
  42. SET(CMAKE_SYSTEM_PROCESSOR aarch64)
  43. set(CMAKE_STAGING_PREFIX /tmp/stage)
  44. set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc-6)
  45. set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++-6)
  46. set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  47. set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  48. set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  49. set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
  50. EOT
  51. # Build and install gRPC for ARM.
  52. # This build will use the host architecture copies of protoc and
  53. # grpc_cpp_plugin that we built earlier because we installed them
  54. # to a location in our PATH (/usr/local/bin).
  55. mkdir -p "cmake/build_arm"
  56. pushd "cmake/build_arm"
  57. cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake \
  58. -DCMAKE_BUILD_TYPE=Release \
  59. -DCMAKE_INSTALL_PREFIX=/tmp/install \
  60. ../..
  61. make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}" install
  62. popd
  63. # Build helloworld example for ARM.
  64. # As above, it will find and use protoc and grpc_cpp_plugin
  65. # for the host architecture.
  66. mkdir -p "examples/cpp/helloworld/cmake/build_arm"
  67. pushd "examples/cpp/helloworld/cmake/build_arm"
  68. cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake \
  69. -DCMAKE_BUILD_TYPE=Release \
  70. -Dabsl_DIR=/tmp/stage/lib/cmake/absl \
  71. -DProtobuf_DIR=/tmp/stage/lib/cmake/protobuf \
  72. -DgRPC_DIR=/tmp/stage/lib/cmake/grpc \
  73. ../..
  74. make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}"
  75. popd