xref: /aosp_15_r20/external/abseil-cpp/ci/linux_clang-latest_libstdcxx_bazel.sh (revision 9356374a3709195abf420251b3e825997ff56c0f)
1*9356374aSAndroid Build Coastguard Worker#!/bin/bash
2*9356374aSAndroid Build Coastguard Worker#
3*9356374aSAndroid Build Coastguard Worker# Copyright 2019 The Abseil Authors.
4*9356374aSAndroid Build Coastguard Worker#
5*9356374aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*9356374aSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*9356374aSAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*9356374aSAndroid Build Coastguard Worker#
9*9356374aSAndroid Build Coastguard Worker#    https://www.apache.org/licenses/LICENSE-2.0
10*9356374aSAndroid Build Coastguard Worker#
11*9356374aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*9356374aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*9356374aSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*9356374aSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*9356374aSAndroid Build Coastguard Worker# limitations under the License.
16*9356374aSAndroid Build Coastguard Worker
17*9356374aSAndroid Build Coastguard Worker# This script that can be invoked to test abseil-cpp in a hermetic environment
18*9356374aSAndroid Build Coastguard Worker# using a Docker image on Linux. You must have Docker installed to use this
19*9356374aSAndroid Build Coastguard Worker# script.
20*9356374aSAndroid Build Coastguard Worker
21*9356374aSAndroid Build Coastguard Workerset -euox pipefail
22*9356374aSAndroid Build Coastguard Worker
23*9356374aSAndroid Build Coastguard Workerif [[ -z ${ABSEIL_ROOT:-} ]]; then
24*9356374aSAndroid Build Coastguard Worker  ABSEIL_ROOT="$(realpath $(dirname ${0})/..)"
25*9356374aSAndroid Build Coastguard Workerfi
26*9356374aSAndroid Build Coastguard Worker
27*9356374aSAndroid Build Coastguard Workerif [[ -z ${STD:-} ]]; then
28*9356374aSAndroid Build Coastguard Worker  STD="c++14 c++17"
29*9356374aSAndroid Build Coastguard Workerfi
30*9356374aSAndroid Build Coastguard Worker
31*9356374aSAndroid Build Coastguard Workerif [[ -z ${COMPILATION_MODE:-} ]]; then
32*9356374aSAndroid Build Coastguard Worker  COMPILATION_MODE="fastbuild opt"
33*9356374aSAndroid Build Coastguard Workerfi
34*9356374aSAndroid Build Coastguard Worker
35*9356374aSAndroid Build Coastguard Workerif [[ -z ${EXCEPTIONS_MODE:-} ]]; then
36*9356374aSAndroid Build Coastguard Worker  EXCEPTIONS_MODE="-fno-exceptions -fexceptions"
37*9356374aSAndroid Build Coastguard Workerfi
38*9356374aSAndroid Build Coastguard Worker
39*9356374aSAndroid Build Coastguard Workersource "${ABSEIL_ROOT}/ci/linux_docker_containers.sh"
40*9356374aSAndroid Build Coastguard Workerreadonly DOCKER_CONTAINER=${LINUX_CLANG_LATEST_CONTAINER}
41*9356374aSAndroid Build Coastguard Worker
42*9356374aSAndroid Build Coastguard Worker# USE_BAZEL_CACHE=1 only works on Kokoro.
43*9356374aSAndroid Build Coastguard Worker# Without access to the credentials this won't work.
44*9356374aSAndroid Build Coastguard Workerif [[ ${USE_BAZEL_CACHE:-0} -ne 0 ]]; then
45*9356374aSAndroid Build Coastguard Worker  DOCKER_EXTRA_ARGS="--mount type=bind,source=${KOKORO_KEYSTORE_DIR},target=/keystore,readonly ${DOCKER_EXTRA_ARGS:-}"
46*9356374aSAndroid Build Coastguard Worker  # Bazel doesn't track changes to tools outside of the workspace
47*9356374aSAndroid Build Coastguard Worker  # (e.g. /usr/bin/gcc), so by appending the docker container to the
48*9356374aSAndroid Build Coastguard Worker  # remote_http_cache url, we make changes to the container part of
49*9356374aSAndroid Build Coastguard Worker  # the cache key. Hashing the key is to make it shorter and url-safe.
50*9356374aSAndroid Build Coastguard Worker  container_key=$(echo ${DOCKER_CONTAINER} | sha256sum | head -c 16)
51*9356374aSAndroid Build Coastguard Worker  BAZEL_EXTRA_ARGS="--remote_cache=https://storage.googleapis.com/absl-bazel-remote-cache/${container_key} --google_credentials=/keystore/73103_absl-bazel-remote-cache ${BAZEL_EXTRA_ARGS:-}"
52*9356374aSAndroid Build Coastguard Workerfi
53*9356374aSAndroid Build Coastguard Worker
54*9356374aSAndroid Build Coastguard Worker# Avoid depending on external sites like GitHub by checking --distdir for
55*9356374aSAndroid Build Coastguard Worker# external dependencies first.
56*9356374aSAndroid Build Coastguard Worker# https://docs.bazel.build/versions/master/guide.html#distdir
57*9356374aSAndroid Build Coastguard Workerif [[ ${KOKORO_GFILE_DIR:-} ]] && [[ -d "${KOKORO_GFILE_DIR}/distdir" ]]; then
58*9356374aSAndroid Build Coastguard Worker  DOCKER_EXTRA_ARGS="--mount type=bind,source=${KOKORO_GFILE_DIR}/distdir,target=/distdir,readonly ${DOCKER_EXTRA_ARGS:-}"
59*9356374aSAndroid Build Coastguard Worker  BAZEL_EXTRA_ARGS="--distdir=/distdir ${BAZEL_EXTRA_ARGS:-}"
60*9356374aSAndroid Build Coastguard Workerfi
61*9356374aSAndroid Build Coastguard Worker
62*9356374aSAndroid Build Coastguard Workerfor std in ${STD}; do
63*9356374aSAndroid Build Coastguard Worker  for compilation_mode in ${COMPILATION_MODE}; do
64*9356374aSAndroid Build Coastguard Worker    for exceptions_mode in ${EXCEPTIONS_MODE}; do
65*9356374aSAndroid Build Coastguard Worker      echo "--------------------------------------------------------------------"
66*9356374aSAndroid Build Coastguard Worker      time docker run \
67*9356374aSAndroid Build Coastguard Worker        --mount type=bind,source="${ABSEIL_ROOT}",target=/abseil-cpp,readonly \
68*9356374aSAndroid Build Coastguard Worker        --workdir=/abseil-cpp \
69*9356374aSAndroid Build Coastguard Worker        --cap-add=SYS_PTRACE \
70*9356374aSAndroid Build Coastguard Worker        --rm \
71*9356374aSAndroid Build Coastguard Worker        -e CC="/opt/llvm/clang/bin/clang" \
72*9356374aSAndroid Build Coastguard Worker        -e BAZEL_CXXOPTS="-std=${std}" \
73*9356374aSAndroid Build Coastguard Worker        ${DOCKER_EXTRA_ARGS:-} \
74*9356374aSAndroid Build Coastguard Worker        ${DOCKER_CONTAINER} \
75*9356374aSAndroid Build Coastguard Worker        /usr/local/bin/bazel test ... \
76*9356374aSAndroid Build Coastguard Worker          --compilation_mode="${compilation_mode}" \
77*9356374aSAndroid Build Coastguard Worker          --copt="--gcc-toolchain=/usr/local" \
78*9356374aSAndroid Build Coastguard Worker          --copt="-DGTEST_REMOVE_LEGACY_TEST_CASEAPI_=1" \
79*9356374aSAndroid Build Coastguard Worker          --copt="${exceptions_mode}" \
80*9356374aSAndroid Build Coastguard Worker          --copt="-march=haswell" \
81*9356374aSAndroid Build Coastguard Worker          --copt=-Werror \
82*9356374aSAndroid Build Coastguard Worker          --define="absl=1" \
83*9356374aSAndroid Build Coastguard Worker          --enable_bzlmod=true \
84*9356374aSAndroid Build Coastguard Worker          --features=external_include_paths \
85*9356374aSAndroid Build Coastguard Worker          --keep_going \
86*9356374aSAndroid Build Coastguard Worker          --linkopt="--gcc-toolchain=/usr/local" \
87*9356374aSAndroid Build Coastguard Worker          --show_timestamps \
88*9356374aSAndroid Build Coastguard Worker          --test_env="GTEST_INSTALL_FAILURE_SIGNAL_HANDLER=1" \
89*9356374aSAndroid Build Coastguard Worker          --test_env="TZDIR=/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo" \
90*9356374aSAndroid Build Coastguard Worker          --test_output=errors \
91*9356374aSAndroid Build Coastguard Worker          --test_tag_filters=-benchmark \
92*9356374aSAndroid Build Coastguard Worker          ${BAZEL_EXTRA_ARGS:-}
93*9356374aSAndroid Build Coastguard Worker    done
94*9356374aSAndroid Build Coastguard Worker  done
95*9356374aSAndroid Build Coastguard Workerdone
96