build.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
  20. ROOT_DIR="$( cd "${SCRIPT_DIR}/../../.." >/dev/null 2>&1 && pwd )"
  21. CONFIG=$1 # DEBUG RELEASE
  22. COMPILER=$2 # clang gcc
  23. TOOL=$3 # cmake bazel
  24. BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}
  25. # chown the given directory to the current user, if it exists.
  26. # Docker creates files with the root user - this can upset the Kokoro artifact copier.
  27. function chown_dir() {
  28. dir=$1
  29. if [[ -d "$dir" ]]; then
  30. sudo chown -R "$(id -u):$(id -g)" "$dir"
  31. fi
  32. }
  33. set +e
  34. # Allow build failures
  35. # "--privileged" is required to run ptrace in the asan builds.
  36. docker run --rm -i \
  37. --privileged \
  38. --volume "${ROOT_DIR}:${ROOT_DIR}" \
  39. --volume "${KOKORO_ARTIFACTS_DIR}:${KOKORO_ARTIFACTS_DIR}" \
  40. --workdir "${ROOT_DIR}" \
  41. --env SCRIPT_DIR=${SCRIPT_DIR} \
  42. --env ROOT_DIR=${ROOT_DIR} \
  43. --env CONFIG=${CONFIG} \
  44. --env COMPILER=${COMPILER} \
  45. --env TOOL=${TOOL} \
  46. --env KOKORO_ARTIFACTS_DIR="${KOKORO_ARTIFACTS_DIR}" \
  47. --env BUILD_SHA="${BUILD_SHA}" \
  48. --entrypoint "${SCRIPT_DIR}/build-docker.sh" \
  49. us-east4-docker.pkg.dev/shaderc-build/radial-docker/ubuntu-24.04-amd64/cpp-builder
  50. RESULT=$?
  51. # This is important. If the permissions are not fixed, kokoro will fail
  52. # to pull build artifacts, and put the build in tool-failure state, which
  53. # blocks the logs.
  54. chown_dir "${ROOT_DIR}/build"
  55. chown_dir "${ROOT_DIR}/third_party"
  56. exit $RESULT