Skip to content

Commit 3096353

Browse files
tstellarkwk
andauthored
test-release.sh: Add a CMake cache file for 3-stage release builds (#75903)
You can now pass the -use-cmake-cache option to test-release.sh and it will use a predefined cache file for building the release. This will make it easier to reproduce the builds and add other enhancements like PGO or bolt optimizations. --------- Co-authored-by: Konrad Kleine <[email protected]>
1 parent 9a2df55 commit 3096353

File tree

3 files changed

+104
-9
lines changed

3 files changed

+104
-9
lines changed

.github/workflows/release-binaries.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ jobs:
9393

9494
- name: Build Clang
9595
run: |
96-
cmake -G Ninja -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_BUILD_TYPE=Release -DCMAKE_ENABLE_ASSERTIONS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DLLVM_ENABLE_PROJECTS=clang -S llvm -B build
97-
ninja -v -C build
96+
cmake -G Ninja -C clang/cmake/caches/Release.cmake -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_POSITION_INDEPENDENT_CODE=ON -S llvm -B build
97+
ninja -v -C build clang
9898
9999
100100
build-binaries:
@@ -152,6 +152,7 @@ jobs:
152152
-triple ${{ matrix.target.triple }} \
153153
-use-ninja \
154154
-no-checkout \
155+
-use-cmake-cache \
155156
-no-test-suite \
156157
-configure-flags "-DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache"
157158

clang/cmake/caches/Release.cmake

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Plain options configure the first build.
2+
# BOOTSTRAP_* options configure the second build.
3+
# BOOTSTRAP_BOOTSTRAP_* options configure the third build.
4+
5+
set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
6+
7+
# Stage 1 Bootstrap Setup
8+
set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
9+
set(CLANG_BOOTSTRAP_TARGETS
10+
clang
11+
check-all
12+
check-llvm
13+
check-clang
14+
test-suite
15+
stage3
16+
stage3-clang
17+
stage3-check-all
18+
stage3-check-llvm
19+
stage3-check-clang
20+
stage3-install
21+
stage3-test-suite CACHE STRING "")
22+
23+
# Stage 1 Options
24+
set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "")
25+
set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
26+
27+
# Stage 2 Bootstrap Setup
28+
set(BOOTSTRAP_CLANG_ENABLE_BOOTSTRAP ON CACHE STRING "")
29+
set(BOOTSTRAP_CLANG_BOOTSTRAP_TARGETS
30+
clang
31+
check-all
32+
check-llvm
33+
check-clang CACHE STRING "")
34+
35+
# Stage 2 Options
36+
set(BOOTSTRAP_LLVM_ENABLE_PROJECTS "clang" CACHE STRING "")
37+
set(BOOTSTRAP_LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
38+
39+
# Stage 3 Options
40+
set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
41+
set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_PROJECTS "clang;lld;lldb;clang-tools-extra;bolt;polly;mlir;flang" CACHE STRING "")

llvm/utils/release/test-release.sh

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ BuildDir="`pwd`"
4646
ExtraConfigureFlags=""
4747
ExportBranch=""
4848
git_ref=""
49-
49+
do_cmake_cache="no"
5050
do_bolt="no"
5151
if [ "$System" = "Linux" ]; then
5252
case $Machine in
@@ -87,6 +87,7 @@ function usage() {
8787
echo " -no-mlir Disable check-out & build MLIR"
8888
echo " -no-flang Disable check-out & build Flang"
8989
echo " -silent-log Don't output build logs to stdout"
90+
echo " -use-cmake-cache Build using a CMake cache file"
9091
}
9192

9293
while [ $# -gt 0 ]; do
@@ -200,6 +201,9 @@ while [ $# -gt 0 ]; do
200201
-silent-log )
201202
do_silent_log="yes"
202203
;;
204+
-use-cmake-cache | --use-cmake-cache )
205+
do_cmake_cache="yes"
206+
;;
203207
-help | --help | -h | --h | -\? )
204208
usage
205209
exit 0
@@ -328,6 +332,55 @@ Package=$Package-$Triple
328332
# Errors to be highlighted at the end are written to this file.
329333
echo -n > $LogDir/deferred_errors.log
330334

335+
redir="/dev/stdout"
336+
if [ $do_silent_log == "yes" ]; then
337+
echo "# Silencing build logs because of -silent-log flag..."
338+
redir="/dev/null"
339+
fi
340+
341+
342+
function build_with_cmake_cache() {
343+
(
344+
CMakeBuildDir=$BuildDir/build
345+
SrcDir=$BuildDir/llvm-project/
346+
InstallDir=$BuildDir/install
347+
348+
rm -rf $CMakeBuildDir
349+
350+
# FIXME: Would be nice if the commands were echoed to the log file too.
351+
set -x
352+
353+
env CC="$c_compiler" CXX="$cxx_compiler" \
354+
cmake -G "$generator" -B $CMakeBuildDir -S $SrcDir/llvm \
355+
-C $SrcDir/clang/cmake/caches/Release.cmake \
356+
-DCLANG_BOOTSTRAP_PASSTHROUGH="CMAKE_POSITION_INDEPENDENT_CODE;LLVM_LIT_ARGS" \
357+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
358+
-DLLVM_LIT_ARGS="-j $NumJobs $LitVerbose" \
359+
$ExtraConfigureFlags
360+
2>&1 | tee $LogDir/llvm.configure-$Flavor.log
361+
362+
${MAKE} $J_ARG $Verbose -C $CMakeBuildDir stage3-check-all \
363+
2>&1 | tee $LogDir/llvm.make-$Flavor.log > $redir
364+
365+
DESTDIR="${InstallDir}" \
366+
${MAKE} -C $CMakeBuildDir stage3-install \
367+
2>&1 | tee $LogDir/llvm.install-$Flavor.log > $redir
368+
369+
mkdir -p $BuildDir/Release
370+
pushd $BuildDir/Release
371+
mv $InstallDir/usr/local $Package
372+
if [ "$use_gzip" = "yes" ]; then
373+
tar cf - $Package | gzip -9c > $BuildDir/$Package.tar.gz
374+
else
375+
tar cf - $Package | xz -9ce -T $NumJobs > $BuildDir/$Package.tar.xz
376+
fi
377+
mv $Package $InstallDir/usr/local
378+
popd
379+
) 2>&1 | tee $LogDir/testing.$Release-$RC.log
380+
381+
exit 0
382+
}
383+
331384
function deferred_error() {
332385
Phase="$1"
333386
Flavor="$2"
@@ -485,12 +538,6 @@ function build_llvmCore() {
485538
fi
486539
fi
487540

488-
redir="/dev/stdout"
489-
if [ $do_silent_log == "yes" ]; then
490-
echo "# Silencing build logs because of -silent-log flag..."
491-
redir="/dev/null"
492-
fi
493-
494541
cd $ObjDir
495542
echo "# Compiling llvm $Release-$RC $Flavor"
496543
echo "# ${MAKE} $J_ARG $Verbose"
@@ -600,7 +647,13 @@ if [ $do_test_suite = "yes" ]; then
600647
mkdir -p $TestSuiteBuildDir
601648
fi
602649

650+
if [ "$do_cmake_cache" = "yes" ]; then
651+
build_with_cmake_cache
652+
exit 0
653+
fi
654+
603655
(
656+
604657
Flavors="Release"
605658
if [ "$do_debug" = "yes" ]; then
606659
Flavors="Debug $Flavors"

0 commit comments

Comments
 (0)