build-docker.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. # Copyright (c) 2023 Google LLC.
  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. # Linux Build Script.
  17. # Fail on any error.
  18. set -e
  19. # Display commands being run.
  20. set -x
  21. function die {
  22. echo "$@"
  23. exit 1
  24. }
  25. # This is required to run any git command in the docker since owner will
  26. # have changed between the clone environment, and the docker container.
  27. # Marking the root of the repo as safe for ownership changes.
  28. git config --global --add safe.directory $ROOT_DIR
  29. . /bin/using.sh # Declare the bash `using` function for configuring toolchains.
  30. using python-3.12
  31. case $CONFIG in
  32. DEBUG|RELEASE)
  33. ;;
  34. *)
  35. die expected CONFIG to be DEBUG or RELEASE
  36. ;;
  37. esac
  38. case $COMPILER in
  39. clang)
  40. using clang-13.0.1
  41. ;;
  42. gcc)
  43. using gcc-13
  44. ;;
  45. *)
  46. die expected COMPILER to be clang or gcc
  47. ;;
  48. esac
  49. case $TOOL in
  50. cmake|bazel)
  51. ;;
  52. *)
  53. die expected TOOL to be cmake or bazel
  54. ;;
  55. esac
  56. cd $ROOT_DIR
  57. function clean_dir() {
  58. dir=$1
  59. if [[ -d "$dir" ]]; then
  60. rm -fr "$dir"
  61. fi
  62. mkdir "$dir"
  63. }
  64. # Get source for dependencies, as specified in the DEPS file
  65. /usr/bin/python3 utils/git-sync-deps
  66. if [ $TOOL = "cmake" ]; then
  67. using cmake-3.31.2
  68. using ninja-1.10.0
  69. BUILD_TYPE="Debug"
  70. if [ $CONFIG = "RELEASE" ]; then
  71. BUILD_TYPE="RelWithDebInfo"
  72. fi
  73. clean_dir "$ROOT_DIR/build"
  74. cd "$ROOT_DIR/build"
  75. # Invoke the build.
  76. BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}
  77. echo $(date): Starting build...
  78. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python3 -GNinja -DCMAKE_INSTALL_PREFIX=$KOKORO_ARTIFACTS_DIR/install -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DRE2_BUILD_TESTING=OFF ..
  79. echo $(date): Build everything...
  80. ninja
  81. echo $(date): Build completed.
  82. echo $(date): Starting ctest...
  83. ctest --output-on-failure --timeout 300
  84. echo $(date): ctest completed.
  85. elif [ $TOOL = "bazel" ]; then
  86. using bazel-7.0.2
  87. echo $(date): Build everything...
  88. bazel build --cxxopt=-std=c++17 :all
  89. echo $(date): Build completed.
  90. echo $(date): Starting bazel test...
  91. bazel test --cxxopt=-std=c++17 :all
  92. echo $(date): Bazel test completed.
  93. fi