xref: /aosp_15_r20/external/cronet/third_party/libc++/src/utils/ci/run-buildbot (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1#!/usr/bin/env bash
2#===----------------------------------------------------------------------===##
3#
4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5# See https://llvm.org/LICENSE.txt for license information.
6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7#
8#===----------------------------------------------------------------------===##
9
10set -ex
11set -o pipefail
12unset LANG
13unset LC_ALL
14unset LC_COLLATE
15
16PROGNAME="$(basename "${0}")"
17
18function usage() {
19cat <<EOF
20Usage:
21${PROGNAME} [options] <BUILDER>
22
23[-h|--help]         Display this help and exit.
24
25--llvm-root <DIR>   Path to the root of the LLVM monorepo. By default, we try
26                    to figure it out based on the current working directory.
27
28--build-dir <DIR>   The directory to use for building the library. By default,
29                    this is '<llvm-root>/build/<builder>'.
30
31--osx-roots <DIR>   Path to pre-downloaded macOS dylibs. By default, we download
32                    them from Green Dragon. This is only relevant at all when
33                    running back-deployment testing if one wants to override
34                    the old dylibs we use to run the tests with different ones.
35Environment variables
36CC                  The C compiler to use, this value is used by CMake. This
37                    variable is optional.
38
39CXX                 The C++ compiler to use, this value is used by CMake. This
40                    variable is optional.
41
42CMAKE               The CMake binary to use. This variable is optional.
43
44CLANG_FORMAT        The clang-format binary to use when generating the format
45                    ignore list.
46
47ENABLE_CLANG_TIDY   Whether to compile and run clang-tidy checks. This variable
48                    is optional.
49
50EOF
51}
52
53if [[ $# == 0 ]]; then
54   usage
55   exit 0
56fi
57
58while [[ $# -gt 0 ]]; do
59    case ${1} in
60        -h|--help)
61            usage
62            exit 0
63            ;;
64        --llvm-root)
65            MONOREPO_ROOT="${2}"
66            shift; shift
67            ;;
68        --build-dir)
69            BUILD_DIR="${2}"
70            shift; shift
71            ;;
72        --osx-roots)
73            OSX_ROOTS="${2}"
74            shift; shift
75            ;;
76        *)
77            BUILDER="${1}"
78            shift
79            ;;
80    esac
81done
82
83MONOREPO_ROOT="${MONOREPO_ROOT:="$(git rev-parse --show-toplevel)"}"
84BUILD_DIR="${BUILD_DIR:=${MONOREPO_ROOT}/build/${BUILDER}}"
85INSTALL_DIR="${BUILD_DIR}/install"
86
87# If we can find Ninja/CMake provided by Xcode, use those since we know their
88# version will generally work with the Clang shipped in Xcode (e.g. if Clang
89# knows about -std=c++20, the CMake bundled in Xcode will probably know about
90# that flag too).
91if xcrun --find ninja &>/dev/null; then
92    NINJA="$(xcrun --find ninja)"
93elif which ninja &>/dev/null; then
94    # The current implementation of modules needs the absolute path to the ninja
95    # binary.
96    # TODO MODULES Is this still needed when CMake has libc++ module support?
97    NINJA="$(which ninja)"
98else
99    NINJA="ninja"
100fi
101
102if [ -z "${CMAKE}" ]; then
103    if xcrun --find cmake &>/dev/null; then
104        CMAKE="$(xcrun --find cmake)"
105    else
106        CMAKE="cmake"
107    fi
108fi
109
110function clean() {
111    rm -rf "${BUILD_DIR}"
112}
113
114if [ -z "${ENABLE_CLANG_TIDY}" ]; then
115    ENABLE_CLANG_TIDY=Off
116fi
117
118function generate-cmake-base() {
119    echo "--- Generating CMake"
120    ${CMAKE} \
121          -S "${MONOREPO_ROOT}/runtimes" \
122          -B "${BUILD_DIR}" \
123          -GNinja -DCMAKE_MAKE_PROGRAM="${NINJA}" \
124          -DCMAKE_BUILD_TYPE=RelWithDebInfo \
125          -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
126          -DLIBCXX_ENABLE_WERROR=YES \
127          -DLIBCXXABI_ENABLE_WERROR=YES \
128          -DLIBUNWIND_ENABLE_WERROR=YES \
129          -DLIBCXX_ENABLE_CLANG_TIDY=${ENABLE_CLANG_TIDY} \
130          -DLLVM_LIT_ARGS="-sv --xunit-xml-output test-results.xml --timeout=1500 --time-tests" \
131          "${@}"
132}
133
134function generate-cmake() {
135    generate-cmake-base \
136          -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
137          -DLIBCXX_CXX_ABI=libcxxabi \
138          "${@}"
139}
140
141function generate-cmake-libcxx-win() {
142    generate-cmake-base \
143          -DLLVM_ENABLE_RUNTIMES="libcxx" \
144          -DCMAKE_C_COMPILER=clang-cl \
145          -DCMAKE_CXX_COMPILER=clang-cl \
146          "${@}"
147}
148
149function generate-cmake-android() {
150    generate-cmake-base \
151          -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
152          -DLIBCXX_CXX_ABI=libcxxabi \
153          "${@}"
154}
155
156function check-runtimes() {
157    echo "+++ Running the libc++ tests"
158    ${NINJA} -vC "${BUILD_DIR}" check-cxx
159
160    echo "+++ Running the libc++abi tests"
161    ${NINJA} -vC "${BUILD_DIR}" check-cxxabi
162
163    echo "+++ Running the libunwind tests"
164    ${NINJA} -vC "${BUILD_DIR}" check-unwind
165
166    # TODO: On macOS 13.5, the linker seems to have an issue where it will pick up
167    #       a library if it exists inside a -L search path, even if we don't link
168    #       against that library. This happens with libunwind.dylib if it is built
169    #       at the point when we run the libc++ tests, which causes issues cause we
170    #       are also linking against the system unwinder.
171    #
172    #       I believe this is a linker regression and I reported it as rdar://115842730.
173    #       It should be possible to move this installation step back to the top once
174    #       that issue has been resolved, but in the meantime it doesn't really hurt to
175    #       have it here.
176    echo "--- Installing libc++, libc++abi and libunwind to a fake location"
177    ${NINJA} -vC "${BUILD_DIR}" install-cxx install-cxxabi install-unwind
178}
179
180# TODO: The goal is to test this against all configurations. We should also move
181#       this to the Lit test suite instead of being a separate CMake target.
182function check-abi-list() {
183    echo "+++ Running the libc++ ABI list test"
184    ${NINJA} -vC "${BUILD_DIR}" check-cxx-abilist || (
185        echo "+++ Generating the libc++ ABI list after failed check"
186        ${NINJA} -vC "${BUILD_DIR}" generate-cxx-abilist
187        false
188    )
189}
190
191function check-cxx-benchmarks() {
192    echo "--- Running the benchmarks"
193    ${NINJA} -vC "${BUILD_DIR}" check-cxx-benchmarks
194}
195
196function test-armv7m-picolibc() {
197    clean
198
199    # To make it easier to get this builder up and running, build picolibc
200    # from scratch. Anecdotally, the build-picolibc script takes about 16 seconds.
201    # This could be optimised by building picolibc into the Docker container.
202    ${MONOREPO_ROOT}/libcxx/utils/ci/build-picolibc.sh \
203        --build-dir "${BUILD_DIR}" \
204        --install-dir "${INSTALL_DIR}" \
205        --target armv7m-none-eabi
206
207    echo "--- Generating CMake"
208    flags="--sysroot=${INSTALL_DIR}"
209    ${CMAKE} \
210        -S "${MONOREPO_ROOT}/compiler-rt" \
211        -B "${BUILD_DIR}/compiler-rt" \
212        -GNinja -DCMAKE_MAKE_PROGRAM="${NINJA}" \
213        -DCMAKE_BUILD_TYPE=RelWithDebInfo \
214        -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
215        -DCMAKE_C_FLAGS="${flags}" \
216        -DCMAKE_CXX_FLAGS="${flags}" \
217        -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON \
218        "${@}"
219    generate-cmake \
220        -DLIBCXX_TEST_CONFIG="armv7m-picolibc-libc++.cfg.in" \
221        -DLIBCXXABI_TEST_CONFIG="armv7m-picolibc-libc++abi.cfg.in" \
222        -DLIBUNWIND_TEST_CONFIG="armv7m-picolibc-libunwind.cfg.in" \
223        -DCMAKE_C_FLAGS="${flags}" \
224        -DCMAKE_CXX_FLAGS="${flags}" \
225        "${@}"
226
227    ${NINJA} -vC "${BUILD_DIR}/compiler-rt" install
228    mv "${BUILD_DIR}/install/lib/armv7m-none-eabi"/* "${BUILD_DIR}/install/lib"
229
230    check-runtimes
231}
232
233# Print the version of a few tools to aid diagnostics in some cases
234${CMAKE} --version
235${NINJA} --version
236
237if [ ! -z "${CXX}" ]; then ${CXX} --version; fi
238
239case "${BUILDER}" in
240check-generated-output)
241    # `! foo` doesn't work properly with `set -e`, use `! foo || false` instead.
242    # https://stackoverflow.com/questions/57681955/set-e-does-not-respect-logical-not
243    clean
244    generate-cmake
245
246    set +x # Printing all the commands below just creates extremely confusing output
247
248    # Reject patches that forgot to re-run the generator scripts.
249    echo "+++ Making sure the generator scripts were run"
250    ${NINJA} -vC "${BUILD_DIR}" libcxx-generate-files
251    git diff | tee ${BUILD_DIR}/generated_output.patch
252    git ls-files -o --exclude-standard | tee ${BUILD_DIR}/generated_output.status
253    ! grep -q '^--- a' ${BUILD_DIR}/generated_output.patch || false
254    if [ -s ${BUILD_DIR}/generated_output.status ]; then
255        echo "It looks like not all the generator scripts were run,"
256        echo "did you forget to build the libcxx-generate-files target?"
257        echo "Did you add all new files it generated?"
258        false
259    fi
260
261    # Reject patches that introduce non-ASCII characters or hard tabs.
262    # Depends on LC_COLLATE set at the top of this script.
263    set -x
264    ! grep -rn '[^ -~]' libcxx/include libcxx/src libcxx/test libcxx/benchmarks \
265           --exclude '*.dat' \
266           --exclude '*unicode*.cpp' \
267           --exclude '*print*.sh.cpp' \
268           --exclude 'escaped_output.*.pass.cpp' \
269           --exclude 'format_tests.h' \
270           --exclude 'format.functions.tests.h' \
271           --exclude 'formatter.*.pass.cpp' \
272           --exclude 'grep.pass.cpp' \
273           --exclude 'locale-specific_form.pass.cpp' \
274           --exclude 'ostream.pass.cpp' \
275           --exclude 'transcoding.pass.cpp' \
276           --exclude 'underflow.pass.cpp' \
277           || false
278;;
279#
280# Various Standard modes
281#
282generic-cxx03)
283    clean
284    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-cxx03.cmake"
285    check-runtimes
286    check-abi-list
287;;
288generic-cxx11)
289    clean
290    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-cxx11.cmake"
291    check-runtimes
292    check-abi-list
293;;
294generic-cxx14)
295    clean
296    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-cxx14.cmake"
297    check-runtimes
298    check-abi-list
299;;
300generic-cxx17)
301    clean
302    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-cxx17.cmake"
303    check-runtimes
304    check-abi-list
305;;
306generic-cxx20)
307    clean
308    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-cxx20.cmake"
309    check-runtimes
310    check-abi-list
311;;
312generic-cxx23)
313    clean
314    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-cxx23.cmake"
315    check-runtimes
316    check-abi-list
317;;
318generic-cxx26)
319    clean
320    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-cxx26.cmake"
321    check-runtimes
322    check-abi-list
323;;
324#
325# Other compiler support
326#
327generic-gcc)
328    clean
329    generate-cmake -DLIBCXX_ENABLE_WERROR=NO \
330                   -DLIBCXXABI_ENABLE_WERROR=NO \
331                   -DLIBUNWIND_ENABLE_WERROR=NO
332    check-runtimes
333;;
334generic-gcc-cxx11)
335    clean
336    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-cxx11.cmake" \
337                   -DLIBCXX_ENABLE_WERROR=NO \
338                   -DLIBCXXABI_ENABLE_WERROR=NO \
339                   -DLIBUNWIND_ENABLE_WERROR=NO
340    check-runtimes
341;;
342#
343# Sanitizers
344#
345generic-asan)
346    clean
347    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-asan.cmake"
348    check-runtimes
349;;
350generic-msan)
351    clean
352    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-msan.cmake"
353    check-runtimes
354;;
355generic-tsan)
356    clean
357    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-tsan.cmake"
358    check-runtimes
359;;
360generic-ubsan)
361    clean
362    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-ubsan.cmake"
363    check-runtimes
364;;
365#
366# Various build configurations
367#
368bootstrapping-build)
369    clean
370
371    echo "--- Generating CMake"
372    ${CMAKE} \
373          -S "${MONOREPO_ROOT}/llvm" \
374          -B "${BUILD_DIR}" \
375          -GNinja -DCMAKE_MAKE_PROGRAM="${NINJA}" \
376          -DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
377          -DCMAKE_BUILD_TYPE=RelWithDebInfo \
378          -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
379          -DLLVM_ENABLE_PROJECTS="clang" \
380          -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
381          -DLLVM_RUNTIME_TARGETS="$(${CXX} --print-target-triple)" \
382          -DLLVM_TARGETS_TO_BUILD="host" \
383          -DRUNTIMES_BUILD_ALLOW_DARWIN=ON \
384          -DLLVM_ENABLE_ASSERTIONS=ON \
385          -DLLVM_LIT_ARGS="-sv --xunit-xml-output test-results.xml --timeout=1500 --time-tests"
386
387    echo "+++ Running the libc++ and libc++abi tests"
388    ${NINJA} -vC "${BUILD_DIR}" check-runtimes
389
390    echo "--- Installing libc++ and libc++abi to a fake location"
391    ${NINJA} -vC "${BUILD_DIR}" install-runtimes
392
393    ccache -s
394;;
395generic-static)
396    clean
397    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-static.cmake"
398    check-runtimes
399;;
400generic-merged)
401    clean
402    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-merged.cmake" \
403                   -DLIBCXX_TEST_CONFIG="llvm-libc++-shared.cfg.in" \
404                   -DLIBCXXABI_TEST_CONFIG="llvm-libc++abi-merged.cfg.in" \
405                   -DLIBUNWIND_TEST_CONFIG="llvm-libunwind-merged.cfg.in"
406    check-runtimes
407;;
408generic-hardening-mode-fast)
409    clean
410    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-hardening-mode-fast.cmake"
411    check-runtimes
412    check-abi-list
413;;
414generic-hardening-mode-fast-with-abi-breaks)
415    clean
416    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-hardening-mode-fast-with-abi-breaks.cmake"
417    check-runtimes
418    check-abi-list
419;;
420generic-hardening-mode-extensive)
421    clean
422    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-hardening-mode-extensive.cmake"
423    check-runtimes
424    check-abi-list
425;;
426generic-hardening-mode-debug)
427    clean
428    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-hardening-mode-debug.cmake"
429    check-runtimes
430    check-abi-list
431;;
432#
433# Module builds
434#
435generic-modules)
436    clean
437    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-modules.cmake"
438    check-runtimes
439    check-abi-list
440;;
441generic-modules-lsv)
442    clean
443    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-modules-lsv.cmake"
444    check-runtimes
445    check-abi-list
446;;
447#
448# Parts removed
449#
450generic-no-threads)
451    clean
452    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-no-threads.cmake"
453    check-runtimes
454;;
455generic-no-filesystem)
456    clean
457    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-no-filesystem.cmake"
458    check-runtimes
459;;
460generic-no-random_device)
461    clean
462    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-no-random_device.cmake"
463    check-runtimes
464;;
465generic-no-localization)
466    clean
467    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-no-localization.cmake"
468    check-runtimes
469;;
470generic-no-unicode)
471    clean
472    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-no-unicode.cmake"
473    check-runtimes
474;;
475generic-no-wide-characters)
476    clean
477    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-no-wide-characters.cmake"
478    check-runtimes
479;;
480generic-no-tzdb)
481    clean
482    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-no-tzdb.cmake"
483    check-runtimes
484;;
485generic-no-experimental)
486    clean
487    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-no-experimental.cmake"
488    check-runtimes
489    check-abi-list
490;;
491generic-no-exceptions)
492    clean
493    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-no-exceptions.cmake"
494    check-runtimes
495    check-abi-list
496;;
497generic-no-rtti)
498    clean
499    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-no-rtti.cmake"
500    check-runtimes
501;;
502#
503# Other miscellaneous jobs
504#
505generic-abi-unstable)
506    clean
507    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-abi-unstable.cmake"
508    check-runtimes
509;;
510generic-optimized-speed)
511    clean
512    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-optimized-speed.cmake"
513    check-runtimes
514;;
515apple-system)
516    clean
517
518    arch="$(uname -m)"
519    xcrun --sdk macosx                                              \
520        ${MONOREPO_ROOT}/libcxx/utils/ci/apple-install-libcxx.sh    \
521            --llvm-root ${MONOREPO_ROOT}                            \
522            --build-dir ${BUILD_DIR}                                \
523            --install-dir ${INSTALL_DIR}                            \
524            --symbols-dir "${BUILD_DIR}/symbols"                    \
525            --architectures "${arch}"                               \
526            --version "999.99"
527
528    # TODO: It would be better to run the tests against the fake-installed version of libc++ instead
529    xcrun --sdk macosx ninja -vC "${BUILD_DIR}/${arch}" check-cxx check-cxxabi check-cxx-abilist
530;;
531apple-system-backdeployment-hardened-*)
532    clean
533
534    if [[ "${OSX_ROOTS}" == "" ]]; then
535        echo "--- Downloading previous macOS dylibs"
536        PREVIOUS_DYLIBS_URL="https://dl.dropboxusercontent.com/s/gmcfxwgl9f9n6pu/libcxx-roots.tar.gz"
537        OSX_ROOTS="${BUILD_DIR}/macos-roots"
538        mkdir -p "${OSX_ROOTS}"
539        curl "${PREVIOUS_DYLIBS_URL}" | tar -xz --strip-components=1 -C "${OSX_ROOTS}"
540    fi
541
542    DEPLOYMENT_TARGET="${BUILDER#apple-system-backdeployment-hardened-}"
543
544    # TODO: On Apple platforms, we never produce libc++abi.1.dylib or libunwind.1.dylib,
545    #       only libc++abi.dylib and libunwind.dylib. Fix that in the build so that the
546    #       tests stop searching for @rpath/libc++abi.1.dylib and @rpath/libunwind.1.dylib.
547    cp "${OSX_ROOTS}/macOS/libc++abi/${DEPLOYMENT_TARGET}/libc++abi.dylib" \
548       "${OSX_ROOTS}/macOS/libc++abi/${DEPLOYMENT_TARGET}/libc++abi.1.dylib"
549    cp "${OSX_ROOTS}/macOS/libunwind/${DEPLOYMENT_TARGET}/libunwind.dylib" \
550       "${OSX_ROOTS}/macOS/libunwind/${DEPLOYMENT_TARGET}/libunwind.1.dylib"
551
552    arch="$(uname -m)"
553    PARAMS="target_triple=${arch}-apple-macosx${DEPLOYMENT_TARGET}"
554    PARAMS+=";cxx_runtime_root=${OSX_ROOTS}/macOS/libc++/${DEPLOYMENT_TARGET}"
555    PARAMS+=";abi_runtime_root=${OSX_ROOTS}/macOS/libc++abi/${DEPLOYMENT_TARGET}"
556    PARAMS+=";unwind_runtime_root=${OSX_ROOTS}/macOS/libunwind/${DEPLOYMENT_TARGET}"
557    PARAMS+=";hardening_mode=fast"
558
559    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Apple.cmake" \
560                   -DLIBCXX_TEST_CONFIG="apple-libc++-backdeployment.cfg.in" \
561                   -DLIBCXXABI_TEST_CONFIG="apple-libc++abi-backdeployment.cfg.in" \
562                   -DLIBUNWIND_TEST_CONFIG="apple-libunwind-backdeployment.cfg.in" \
563                   -DLIBCXX_TEST_PARAMS="${PARAMS}" \
564                   -DLIBCXXABI_TEST_PARAMS="${PARAMS}" \
565                   -DLIBUNWIND_TEST_PARAMS="${PARAMS}"
566
567    check-runtimes
568;;
569apple-system-backdeployment-*)
570    clean
571
572    if [[ "${OSX_ROOTS}" == "" ]]; then
573        echo "--- Downloading previous macOS dylibs"
574        PREVIOUS_DYLIBS_URL="https://dl.dropboxusercontent.com/s/gmcfxwgl9f9n6pu/libcxx-roots.tar.gz"
575        OSX_ROOTS="${BUILD_DIR}/macos-roots"
576        mkdir -p "${OSX_ROOTS}"
577        curl "${PREVIOUS_DYLIBS_URL}" | tar -xz --strip-components=1 -C "${OSX_ROOTS}"
578    fi
579
580    DEPLOYMENT_TARGET="${BUILDER#apple-system-backdeployment-}"
581
582    # TODO: On Apple platforms, we never produce libc++abi.1.dylib or libunwind.1.dylib,
583    #       only libc++abi.dylib and libunwind.dylib. Fix that in the build so that the
584    #       tests stop searching for @rpath/libc++abi.1.dylib and @rpath/libunwind.1.dylib.
585    cp "${OSX_ROOTS}/macOS/libc++abi/${DEPLOYMENT_TARGET}/libc++abi.dylib" \
586       "${OSX_ROOTS}/macOS/libc++abi/${DEPLOYMENT_TARGET}/libc++abi.1.dylib"
587    cp "${OSX_ROOTS}/macOS/libunwind/${DEPLOYMENT_TARGET}/libunwind.dylib" \
588       "${OSX_ROOTS}/macOS/libunwind/${DEPLOYMENT_TARGET}/libunwind.1.dylib"
589
590    arch="$(uname -m)"
591    PARAMS="target_triple=${arch}-apple-macosx${DEPLOYMENT_TARGET}"
592    PARAMS+=";cxx_runtime_root=${OSX_ROOTS}/macOS/libc++/${DEPLOYMENT_TARGET}"
593    PARAMS+=";abi_runtime_root=${OSX_ROOTS}/macOS/libc++abi/${DEPLOYMENT_TARGET}"
594    PARAMS+=";unwind_runtime_root=${OSX_ROOTS}/macOS/libunwind/${DEPLOYMENT_TARGET}"
595
596    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Apple.cmake" \
597                   -DLIBCXX_TEST_CONFIG="apple-libc++-backdeployment.cfg.in" \
598                   -DLIBCXXABI_TEST_CONFIG="apple-libc++abi-backdeployment.cfg.in" \
599                   -DLIBUNWIND_TEST_CONFIG="apple-libunwind-backdeployment.cfg.in" \
600                   -DLIBCXX_TEST_PARAMS="${PARAMS}" \
601                   -DLIBCXXABI_TEST_PARAMS="${PARAMS}" \
602                   -DLIBUNWIND_TEST_PARAMS="${PARAMS}"
603
604    check-runtimes
605;;
606benchmarks)
607    clean
608    generate-cmake
609    check-cxx-benchmarks
610;;
611aarch64)
612    clean
613    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/AArch64.cmake"
614    check-runtimes
615;;
616aarch64-no-exceptions)
617    clean
618    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/AArch64.cmake" \
619                   -DLIBCXX_ENABLE_EXCEPTIONS=OFF \
620                   -DLIBCXXABI_ENABLE_EXCEPTIONS=OFF
621    check-runtimes
622;;
623# Aka Armv8 32 bit
624armv8)
625    clean
626    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Armv8Arm.cmake"
627    check-runtimes
628;;
629armv8-no-exceptions)
630    clean
631    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake"
632    check-runtimes
633;;
634# Armv7 32 bit. One building Arm only one Thumb only code.
635armv7)
636    clean
637    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Armv7Arm.cmake"
638    check-runtimes
639;;
640armv7-no-exceptions)
641    clean
642    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake"
643    check-runtimes
644;;
645armv7m-picolibc)
646    test-armv7m-picolibc \
647        -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Armv7M-picolibc.cmake"
648;;
649armv7m-picolibc-no-exceptions)
650    test-armv7m-picolibc \
651        -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Armv7M-picolibc.cmake" \
652        -DLIBCXXABI_ENABLE_EXCEPTIONS=OFF \
653        -DLIBCXXABI_ENABLE_STATIC_UNWINDER=OFF \
654        -DLIBCXX_ENABLE_EXCEPTIONS=OFF \
655        -DLIBCXX_ENABLE_RTTI=OFF
656;;
657clang-cl-dll)
658    clean
659    # TODO: Currently, building with the experimental library breaks running
660    # tests (the test linking look for the c++experimental library with the
661    # wrong name, and the statically linked c++experimental can't be linked
662    # correctly when libc++ visibility attributes indicate dllimport linkage
663    # anyway), thus just disable the experimental library. Remove this
664    # setting when cmake and the test driver does the right thing automatically.
665    generate-cmake-libcxx-win -DLIBCXX_TEST_PARAMS="enable_experimental=False"
666    echo "+++ Running the libc++ tests"
667    ${NINJA} -vC "${BUILD_DIR}" check-cxx
668;;
669clang-cl-static)
670    clean
671    generate-cmake-libcxx-win -DLIBCXX_ENABLE_SHARED=OFF
672    echo "+++ Running the libc++ tests"
673    ${NINJA} -vC "${BUILD_DIR}" check-cxx
674;;
675clang-cl-no-vcruntime)
676    clean
677    # Building libc++ in the same way as in clang-cl-dll above, but running
678    # tests with -D_HAS_EXCEPTIONS=0, which users might set in certain
679    # translation units while using libc++, even if libc++ is built with
680    # exceptions enabled.
681    generate-cmake-libcxx-win -DLIBCXX_TEST_PARAMS="enable_experimental=False" \
682                              -DLIBCXX_TEST_CONFIG="llvm-libc++-shared-no-vcruntime-clangcl.cfg.in"
683    echo "+++ Running the libc++ tests"
684    ${NINJA} -vC "${BUILD_DIR}" check-cxx
685;;
686clang-cl-debug)
687    clean
688    generate-cmake-libcxx-win -DLIBCXX_TEST_PARAMS="enable_experimental=False" \
689                              -DCMAKE_BUILD_TYPE=Debug
690    echo "+++ Running the libc++ tests"
691    ${NINJA} -vC "${BUILD_DIR}" check-cxx
692;;
693clang-cl-static-crt)
694    clean
695    # Test linking a static libc++ with the static CRT ("MultiThreaded" denotes
696    # the static CRT, as opposed to "MultiThreadedDLL" which is the default).
697    generate-cmake-libcxx-win -DLIBCXX_ENABLE_SHARED=OFF \
698                              -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
699    echo "+++ Running the libc++ tests"
700    ${NINJA} -vC "${BUILD_DIR}" check-cxx
701;;
702mingw-dll)
703    clean
704    # Explicitly specify the compiler with a triple prefix. The CI
705    # environment has got two installations of Clang; the default one
706    # defaults to MSVC mode, while there's an installation of llvm-mingw
707    # further back in PATH. By calling the compiler with an explicit
708    # triple prefix, we use the one that is bundled with a mingw sysroot.
709    generate-cmake \
710          -DCMAKE_C_COMPILER=x86_64-w64-mingw32-clang \
711          -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-clang++ \
712          -C "${MONOREPO_ROOT}/libcxx/cmake/caches/MinGW.cmake"
713    check-runtimes
714;;
715mingw-static)
716    clean
717    generate-cmake \
718          -DCMAKE_C_COMPILER=x86_64-w64-mingw32-clang \
719          -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-clang++ \
720          -C "${MONOREPO_ROOT}/libcxx/cmake/caches/MinGW.cmake" \
721          -DLIBCXX_ENABLE_SHARED=OFF \
722          -DLIBUNWIND_ENABLE_SHARED=OFF
723    check-runtimes
724;;
725mingw-dll-i686)
726    clean
727    generate-cmake \
728          -DCMAKE_C_COMPILER=i686-w64-mingw32-clang \
729          -DCMAKE_CXX_COMPILER=i686-w64-mingw32-clang++ \
730          -C "${MONOREPO_ROOT}/libcxx/cmake/caches/MinGW.cmake"
731    check-runtimes
732;;
733aix)
734    clean
735    generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/AIX.cmake" \
736                   -DLIBCXX_TEST_CONFIG="ibm-libc++-shared.cfg.in" \
737                   -DLIBCXXABI_TEST_CONFIG="ibm-libc++abi-shared.cfg.in" \
738                   -DLIBUNWIND_TEST_CONFIG="ibm-libunwind-shared.cfg.in"
739    check-abi-list
740    check-runtimes
741;;
742android-ndk-*)
743    clean
744
745    ANDROID_EMU_IMG="${BUILDER#android-ndk-}"
746    . "${MONOREPO_ROOT}/libcxx/utils/ci/vendor/android/emulator-functions.sh"
747    if ! validate_emu_img "${ANDROID_EMU_IMG}"; then
748        echo "error: android-ndk suffix must be a valid emulator image (${ANDROID_EMU_IMG})" >&2
749        exit 1
750    fi
751    ARCH=$(arch_of_emu_img ${ANDROID_EMU_IMG})
752
753    # Use the Android compiler by default.
754    export CC=${CC:-/opt/android/clang/clang-current/bin/clang}
755    export CXX=${CXX:-/opt/android/clang/clang-current/bin/clang++}
756
757    # The NDK libc++_shared.so is always built against the oldest supported API
758    # level. When tests are run against a device with a newer API level, test
759    # programs can be built for any supported API level, but building for the
760    # newest API (i.e. the system image's API) is probably the most interesting.
761    PARAMS="executor=${MONOREPO_ROOT}/libcxx/utils/adb_run.py;target_triple=$(triple_of_arch ${ARCH})$(api_of_emu_img ${ANDROID_EMU_IMG})"
762    generate-cmake-android -C "${MONOREPO_ROOT}/runtimes/cmake/android/Arch-${ARCH}.cmake" \
763                           -C "${MONOREPO_ROOT}/libcxx/cmake/caches/AndroidNDK.cmake" \
764                           -DCMAKE_SYSROOT=/opt/android/ndk/sysroot \
765                           -DLIBCXX_TEST_PARAMS="${PARAMS}" \
766                           -DLIBCXXABI_TEST_PARAMS="${PARAMS}"
767    check-abi-list
768    ${NINJA} -vC "${BUILD_DIR}" install-cxx install-cxxabi
769
770    # Start the emulator and make sure we can connect to the adb server running
771    # inside of it.
772    "${MONOREPO_ROOT}/libcxx/utils/ci/vendor/android/start-emulator.sh" ${ANDROID_EMU_IMG}
773    trap "${MONOREPO_ROOT}/libcxx/utils/ci/vendor/android/stop-emulator.sh" EXIT
774    . "${MONOREPO_ROOT}/libcxx/utils/ci/vendor/android/setup-env-for-emulator.sh"
775
776    # Create adb_run early to avoid concurrent `mkdir -p` of common parent
777    # directories.
778    adb shell mkdir -p /data/local/tmp/adb_run
779    adb push "${BUILD_DIR}/lib/libc++_shared.so" /data/local/tmp/libc++/libc++_shared.so
780    echo "+++ Running the libc++ tests"
781    ${NINJA} -vC "${BUILD_DIR}" check-cxx
782    echo "+++ Running the libc++abi tests"
783    ${NINJA} -vC "${BUILD_DIR}" check-cxxabi
784;;
785#################################################################
786# Insert vendor-specific internal configurations below.
787#
788# This allows vendors to extend this file with their own internal
789# configurations without running into merge conflicts with upstream.
790#################################################################
791
792#################################################################
793*)
794    echo "${BUILDER} is not a known configuration"
795    exit 1
796;;
797esac
798