Skip to content

Commit cd5ed7c

Browse files
authored
[libc++] Make CC and CXX environment variables mandatory in run-buildbot (#166875)
Previously, the bootstrapping-build job defined in run-buildbot required the CC and CXX environment variables to be defined even though run-buildbot documents these environment variables as being optional. It also relied on ccache being available. Refactor run-buildbot to make CC and CXX mandatory, and refactor various places in the CI where we called run-buildbot without setting CC and CXX. After this patch, all places that use run-buildbot are setting CC and CXX before calling the script, which makes it easier to track what compiler is used where. This also allows simplifying run-buildbot itself. Finally, this patch makes ccache optional for running the bootstrapping build.
1 parent 63f48fd commit cd5ed7c

File tree

5 files changed

+102
-63
lines changed

5 files changed

+102
-63
lines changed

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ jobs:
223223
source .venv/bin/activate
224224
python -m pip install psutil
225225
xcrun bash libcxx/utils/ci/run-buildbot ${{ matrix.config }}
226+
env:
227+
CC: clang
228+
CXX: clang++
226229
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
227230
if: always() # Upload artifacts even if the build or test suite fails
228231
with:
@@ -241,16 +244,16 @@ jobs:
241244
fail-fast: false
242245
matrix:
243246
include:
244-
- { config: clang-cl-dll, mingw: false }
245-
- { config: clang-cl-static, mingw: false }
246-
- { config: clang-cl-no-vcruntime, mingw: false }
247-
- { config: clang-cl-debug, mingw: false }
248-
- { config: clang-cl-static-crt, mingw: false }
249-
- { config: mingw-dll, mingw: true }
250-
- { config: mingw-static, mingw: true }
251-
- { config: mingw-dll-i686, mingw: true }
252-
- { config: mingw-incomplete-sysroot, mingw: true }
253-
- { config: mingw-static, mingw: true, runner: windows-11-arm }
247+
- { config: clang-cl-dll, mingw: false, cc: clang-cl, cxx: clang-cl }
248+
- { config: clang-cl-static, mingw: false, cc: clang-cl, cxx: clang-cl }
249+
- { config: clang-cl-no-vcruntime, mingw: false, cc: clang-cl, cxx: clang-cl }
250+
- { config: clang-cl-debug, mingw: false, cc: clang-cl, cxx: clang-cl }
251+
- { config: clang-cl-static-crt, mingw: false, cc: clang-cl, cxx: clang-cl }
252+
- { config: mingw-dll, mingw: true, cc: cc, cxx: c++ }
253+
- { config: mingw-dll, mingw: true, cc: i686-w64-mingw32-clang, cxx: i686-w64-mingw32-clang++ }
254+
- { config: mingw-static, mingw: true, cc: cc, cxx: c++ }
255+
- { config: mingw-incomplete-sysroot, mingw: true, cc: cc, cxx: c++ }
256+
- { config: mingw-static, mingw: true, cc: cc, cxx: c++, runner: windows-11-arm }
254257
runs-on: ${{ matrix.runner != '' && matrix.runner || 'windows-2022' }}
255258
steps:
256259
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
@@ -286,5 +289,7 @@ jobs:
286289
run: |
287290
echo "c:\Program Files\LLVM\bin" | Out-File -FilePath $Env:GITHUB_PATH -Encoding utf8 -Append
288291
- name: Build and test
289-
run: |
290-
bash libcxx/utils/ci/run-buildbot ${{ matrix.config }}
292+
run: bash libcxx/utils/ci/run-buildbot ${{ matrix.config }}
293+
env:
294+
CC: ${{ matrix.cc }}
295+
CXX: ${{ matrix.cxx }}

.github/workflows/libcxx-check-generated-files.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ jobs:
2222

2323
- name: Check generated files
2424
run: libcxx/utils/ci/run-buildbot check-generated-output
25+
env:
26+
CC: cc
27+
CXX: c++

libcxx/docs/AddingNewCIJobs.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ An example of a job definition is:
2828
2929
- label: "C++11"
3030
command: "libcxx/utils/ci/run-buildbot generic-cxx11"
31+
env:
32+
CC: clang
33+
CXX: clang++
3134
artifact_paths:
3235
- "**/test-results.xml"
3336
agents:

libcxx/utils/ci/buildkite-pipeline.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,55 +37,79 @@ steps:
3737
steps:
3838
- label: AArch64
3939
command: libcxx/utils/ci/run-buildbot aarch64
40+
env:
41+
CC: cc
42+
CXX: c++
4043
agents:
4144
queue: libcxx-builders-linaro-arm
4245
arch: aarch64
4346
<<: *common
4447

4548
- label: AArch64 -fno-exceptions
4649
command: libcxx/utils/ci/run-buildbot aarch64-no-exceptions
50+
env:
51+
CC: cc
52+
CXX: c++
4753
agents:
4854
queue: libcxx-builders-linaro-arm
4955
arch: aarch64
5056
<<: *common
5157

5258
- label: Armv8
5359
command: libcxx/utils/ci/run-buildbot armv8
60+
env:
61+
CC: cc
62+
CXX: c++
5463
agents:
5564
queue: libcxx-builders-linaro-arm
5665
arch: armv8l
5766
<<: *common
5867

5968
- label: Armv8 -fno-exceptions
6069
command: libcxx/utils/ci/run-buildbot armv8-no-exceptions
70+
env:
71+
CC: cc
72+
CXX: c++
6173
agents:
6274
queue: libcxx-builders-linaro-arm
6375
arch: armv8l
6476
<<: *common
6577

6678
- label: Armv7
6779
command: libcxx/utils/ci/run-buildbot armv7
80+
env:
81+
CC: cc
82+
CXX: c++
6883
agents:
6984
queue: libcxx-builders-linaro-arm
7085
arch: armv8l
7186
<<: *common
7287

7388
- label: Armv7 -fno-exceptions
7489
command: libcxx/utils/ci/run-buildbot armv7-no-exceptions
90+
env:
91+
CC: cc
92+
CXX: c++
7593
agents:
7694
queue: libcxx-builders-linaro-arm
7795
arch: armv8l
7896
<<: *common
7997

8098
- label: Armv7-M picolibc
8199
command: libcxx/utils/ci/run-buildbot armv7m-picolibc
100+
env:
101+
CC: cc
102+
CXX: c++
82103
agents:
83104
queue: libcxx-builders-linaro-arm
84105
arch: aarch64
85106
<<: *common
86107

87108
- label: Armv7-M picolibc -fno-exceptions
88109
command: libcxx/utils/ci/run-buildbot armv7m-picolibc-no-exceptions
110+
env:
111+
CC: cc
112+
CXX: c++
89113
agents:
90114
queue: libcxx-builders-linaro-arm
91115
arch: aarch64
@@ -131,13 +155,19 @@ steps:
131155
steps:
132156
- label: Android 5.0, x86 NDK
133157
command: libcxx/utils/ci/run-buildbot android-ndk-21-def-x86
158+
env:
159+
CC: /opt/android/clang/clang-current/bin/clang
160+
CXX: /opt/android/clang/clang-current/bin/clang++
134161
agents:
135162
queue: libcxx-builders
136163
os: android
137164
<<: *common
138165

139166
- label: Android 13, x86_64 NDK
140167
command: libcxx/utils/ci/run-buildbot android-ndk-33-goog-x86_64
168+
env:
169+
CC: /opt/android/clang/clang-current/bin/clang
170+
CXX: /opt/android/clang/clang-current/bin/clang++
141171
agents:
142172
queue: libcxx-builders
143173
os: android

libcxx/utils/ci/run-buildbot

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,41 @@ ${PROGNAME} [options] <BUILDER>
3030
3131
Environment variables
3232
CC The C compiler to use, this value is used by CMake. This
33-
variable is optional.
33+
variable is mandatory.
3434
3535
CXX The C++ compiler to use, this value is used by CMake. This
36-
variable is optional.
37-
38-
CLANG_FORMAT The clang-format binary to use when generating the format
39-
ignore list.
36+
variable is mandatory.
4037
38+
CCACHE The ccache binary to use. This variable is optional and is only
39+
used by the bootstrapping build.
4140
EOF
4241
}
4342

43+
function step() {
44+
endstep
45+
set +x
46+
if [[ ! -z ${GITHUB_ACTIONS+x} ]]; then
47+
echo "::group::$1"
48+
export IN_GROUP=1
49+
else
50+
echo "--- $1"
51+
fi
52+
set -x
53+
}
54+
55+
function endstep() {
56+
set +x
57+
if [[ ! -z ${GITHUB_ACTIONS+x} ]] && [[ ! -z ${IN_GROUP+x} ]]; then
58+
echo "::endgroup::"
59+
unset IN_GROUP
60+
fi
61+
set -x
62+
}
63+
64+
function error() {
65+
echo "::error::$1"
66+
}
67+
4468
if [[ $# == 0 ]]; then
4569
usage
4670
exit 0
@@ -71,30 +95,22 @@ MONOREPO_ROOT="${MONOREPO_ROOT:="$(git rev-parse --show-toplevel)"}"
7195
BUILD_DIR="${BUILD_DIR:=${MONOREPO_ROOT}/build/${BUILDER}}"
7296
INSTALL_DIR="${BUILD_DIR}/install"
7397

74-
function step() {
75-
endstep
76-
set +x
77-
if [[ ! -z ${GITHUB_ACTIONS+x} ]]; then
78-
echo "::group::$1"
79-
export IN_GROUP=1
80-
else
81-
echo "--- $1"
82-
fi
83-
set -x
84-
}
98+
if [ -z ${CC+x} ]; then
99+
error "Environment variable CC must be defined"
100+
exit 1
101+
fi
85102

86-
function endstep() {
87-
set +x
88-
if [[ ! -z ${GITHUB_ACTIONS+x} ]] && [[ ! -z ${IN_GROUP+x} ]]; then
89-
echo "::endgroup::"
90-
unset IN_GROUP
91-
fi
92-
set -x
93-
}
103+
if [ -z ${CXX+x} ]; then
104+
error "Environment variable CXX must be defined"
105+
exit 1
106+
fi
94107

95-
function error() {
96-
echo "::error::$1"
97-
}
108+
# Print the version of a few tools to aid diagnostics in some cases
109+
step "Diagnose tools in use"
110+
cmake --version
111+
ninja --version
112+
${CC} --version
113+
${CXX} --version
98114

99115
function clean() {
100116
rm -rf "${BUILD_DIR}"
@@ -127,11 +143,7 @@ function generate-cmake() {
127143
}
128144

129145
function generate-cmake-libcxx-win() {
130-
generate-cmake-base \
131-
-DLLVM_ENABLE_RUNTIMES="libcxx" \
132-
-DCMAKE_C_COMPILER=clang-cl \
133-
-DCMAKE_CXX_COMPILER=clang-cl \
134-
"${@}"
146+
generate-cmake-base -DLLVM_ENABLE_RUNTIMES="libcxx" "${@}"
135147
}
136148

137149
function generate-cmake-android() {
@@ -216,12 +228,6 @@ function test-armv7m-picolibc() {
216228
check-runtimes
217229
}
218230

219-
# Print the version of a few tools to aid diagnostics in some cases
220-
step "Diagnose tools in use"
221-
cmake --version
222-
ninja --version
223-
if [ ! -z "${CXX}" ]; then ${CXX} --version; fi
224-
225231
case "${BUILDER}" in
226232
check-generated-output)
227233
# `! foo` doesn't work properly with `set -e`, use `! foo || false` instead.
@@ -358,12 +364,16 @@ generic-ubsan)
358364
bootstrapping-build)
359365
clean
360366

367+
if [ ! -z ${CCACHE+x} ]; then
368+
COMPILER_LAUNCHER="-DCMAKE_CXX_COMPILER_LAUNCHER=${CCACHE}"
369+
fi
370+
361371
step "Generating CMake"
362372
cmake \
363373
-S "${MONOREPO_ROOT}/llvm" \
364374
-B "${BUILD_DIR}" \
365375
-GNinja \
366-
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
376+
${COMPILER_LAUNCHER} \
367377
-DCMAKE_BUILD_TYPE=Release \
368378
-DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
369379
-DLLVM_ENABLE_PROJECTS="clang;lldb" \
@@ -691,14 +701,6 @@ mingw-static)
691701
-DLIBUNWIND_ENABLE_SHARED=OFF
692702
check-runtimes
693703
;;
694-
mingw-dll-i686)
695-
clean
696-
generate-cmake \
697-
-DCMAKE_C_COMPILER=i686-w64-mingw32-clang \
698-
-DCMAKE_CXX_COMPILER=i686-w64-mingw32-clang++ \
699-
-C "${MONOREPO_ROOT}/libcxx/cmake/caches/MinGW.cmake"
700-
check-runtimes
701-
;;
702704
mingw-incomplete-sysroot)
703705
# When bringing up a new cross compiler from scratch, we build
704706
# libunwind/libcxx in a setup where the toolchain is incomplete and
@@ -743,10 +745,6 @@ android-ndk-*)
743745
fi
744746
ARCH=$(arch_of_emu_img ${ANDROID_EMU_IMG})
745747

746-
# Use the Android compiler by default.
747-
export CC=${CC:-/opt/android/clang/clang-current/bin/clang}
748-
export CXX=${CXX:-/opt/android/clang/clang-current/bin/clang++}
749-
750748
# The NDK libc++_shared.so is always built against the oldest supported API
751749
# level. When tests are run against a device with a newer API level, test
752750
# programs can be built for any supported API level, but building for the

0 commit comments

Comments
 (0)