Skip to content

test-release.sh: Add a CMake cache file for 3-stage release builds #75903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 5, 2024

Conversation

tstellar
Copy link
Collaborator

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.

You can now pass the -use-cmake-cache option 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.
@tstellar tstellar requested review from tru and petrhosek December 19, 2023 08:04
@llvmbot llvmbot added clang Clang issues not falling into any other category github:workflow labels Dec 19, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 19, 2023

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-github-workflow

Author: Tom Stellard (tstellar)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/75903.diff

3 Files Affected:

  • (modified) .github/workflows/release-binaries.yml (+3-2)
  • (added) clang/cmake/caches/Release.cmake (+41)
  • (modified) llvm/utils/release/test-release.sh (+60-7)
diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml
index 4e3eaff97a8783..4a4ba9dcc5ca34 100644
--- a/.github/workflows/release-binaries.yml
+++ b/.github/workflows/release-binaries.yml
@@ -93,8 +93,8 @@ jobs:
 
     - name: Build Clang
       run: |
-        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
-        ninja -v -C build
+        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
+        ninja -v -C build clang
 
 
   build-binaries:
@@ -152,6 +152,7 @@ jobs:
         -triple ${{ matrix.target.triple }} \
         -use-ninja \
         -no-checkout \
+        -use-cmake-cache \
         -no-test-suite \
         -configure-flags "-DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache"
 
diff --git a/clang/cmake/caches/Release.cmake b/clang/cmake/caches/Release.cmake
new file mode 100644
index 00000000000000..42c88655c58cee
--- /dev/null
+++ b/clang/cmake/caches/Release.cmake
@@ -0,0 +1,41 @@
+# Plain options configure the first build.
+# BOOTSTRAP_* options configure the second build.
+# BOOTSTRAP_BOOTSTRAP_* options configure the third build.
+
+set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
+
+# Stage 1 Bootstrap Setup
+set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
+set(CLANG_BOOTSTRAP_TARGETS
+  clang
+  check-all
+  check-llvm
+  check-clang
+  test-suite
+  stage3
+  stage3-clang
+  stage3-check-all
+  stage3-check-llvm
+  stage3-check-clang
+  stage3-install
+  stage3-test-suite CACHE STRING "")
+
+# Stage 1 Options
+set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "")
+set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
+
+# Stage 2 Bootstrap Setup
+set(BOOTSTRAP_CLANG_ENABLE_BOOTSTRAP=ON CACHE STRING "")
+set(BOOTSTRAP_CLANG_BOOTSTRAP_TARGETS
+  clang
+  check-all
+  check-llvm
+  check-clang CACHE STRING "")
+
+# Stage 2 Options
+set(BOOTSTRAP_LLVM_ENABLE_PROJECTS "clang" CACHE STRING "")
+set(BOOTSTRAP_LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
+
+# Stage 3 Options
+set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
+set(BOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_PROJECTS "clang;lld;lldb;clang-tools-extra;bolt;polly;mlir;flang" CACHE STRING "")
diff --git a/llvm/utils/release/test-release.sh b/llvm/utils/release/test-release.sh
index f38134e3d22d8f..544d4bfdd799ce 100755
--- a/llvm/utils/release/test-release.sh
+++ b/llvm/utils/release/test-release.sh
@@ -46,7 +46,7 @@ BuildDir="`pwd`"
 ExtraConfigureFlags=""
 ExportBranch=""
 git_ref=""
-
+do_cmake_cache="no"
 do_bolt="no"
 if [ "$System" = "Linux" ]; then
     case $Machine in
@@ -87,6 +87,7 @@ function usage() {
     echo " -no-mlir             Disable check-out & build MLIR"
     echo " -no-flang            Disable check-out & build Flang"
     echo " -silent-log          Don't output build logs to stdout"
+    echo " -use-cmake-cache     Build using a CMake cache file"
 }
 
 while [ $# -gt 0 ]; do
@@ -200,6 +201,9 @@ while [ $# -gt 0 ]; do
         -silent-log )
             do_silent_log="yes"
             ;;
+        -use-cmake-cache | --use-cmake-cache )
+            do_cmake_cache="yes"
+            ;;
         -help | --help | -h | --h | -\? )
             usage
             exit 0
@@ -328,6 +332,55 @@ Package=$Package-$Triple
 # Errors to be highlighted at the end are written to this file.
 echo -n > $LogDir/deferred_errors.log
 
+redir="/dev/stdout"
+if [ $do_silent_log == "yes" ]; then
+  echo "# Silencing build logs because of -silent-log flag..."
+  redir="/dev/null"
+fi
+
+
+function build_with_cmake_cache() {
+(
+  CMakeBuildDir=$BuildDir/build
+  SrcDir=$BuildDir/llvm-project/
+  InstallDir=$BuildDir/install
+
+  rm -rf $CMakeBuildDir
+
+  # FIXME: Would be nice if the commands were echoed to the log file too.
+  set -x
+
+  env CC="$c_compiler" CXX="$cxx_compiler" \
+  cmake -G "$generator" -B $CMakeBuildDir -S $SrcDir/llvm \
+        -C $SrcDir/clang/cmake/caches/Release.cmake \
+	-DCLANG_BOOTSTRAP_PASSTHROUGH="CMAKE_POSITION_INDEPENDENT_CODE;LLVM_LIT_ARGS" \
+        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
+        -DLLVM_LIT_ARGS="-j $NumJobs $LitVerbose" \
+        $ExtraConfigureFlags
+        2>&1 | tee $LogDir/llvm.configure-$Flavor.log
+
+  ${MAKE} $J_ARG $Verbose -C $CMakeBuildDir stage3-check-all \
+          2>&1 | tee $LogDir/llvm.make-$Flavor.log > $redir
+
+  DESTDIR="${InstallDir}" \
+  ${MAKE} -C $CMakeBuildDir stage3-install \
+          2>&1 | tee $LogDir/llvm.install-$Flavor.log > $redir
+
+ mkdir -p $BuildDir/Release
+ pushd $BuildDir/Release
+ mv $InstallDir/usr/local $Package
+ if [ "$use_gzip" = "yes" ]; then
+    tar cf - $Package | gzip -9c > $BuildDir/$Package.tar.gz
+  else
+    tar cf - $Package | xz -9ce -T $NumJobs > $BuildDir/$Package.tar.xz
+  fi
+  mv $Package $InstallDir/usr/local
+  popd
+) 2>&1 | tee $LogDir/testing.$Release-$RC.log
+
+  exit 0
+}
+
 function deferred_error() {
   Phase="$1"
   Flavor="$2"
@@ -485,12 +538,6 @@ function build_llvmCore() {
       fi
     fi
 
-    redir="/dev/stdout"
-    if [ $do_silent_log == "yes" ]; then
-      echo "# Silencing build logs because of -silent-log flag..."
-      redir="/dev/null"
-    fi
-
     cd $ObjDir
     echo "# Compiling llvm $Release-$RC $Flavor"
     echo "# ${MAKE} $J_ARG $Verbose"
@@ -600,7 +647,13 @@ if [ $do_test_suite = "yes" ]; then
   mkdir -p $TestSuiteBuildDir
 fi
 
+if [ "$do_cmake_cache" = "yes" ]; then
+  build_with_cmake_cache
+  exit 0
+fi
+
 (
+
 Flavors="Release"
 if [ "$do_debug" = "yes" ]; then
     Flavors="Debug $Flavors"

Copy link
Member

@petrhosek petrhosek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, what's the reason for using 3-stage (rather than 2-stage) build?

@tstellar
Copy link
Collaborator Author

Out of curiosity, what's the reason for using 3-stage (rather than 2-stage) build?

I'm trying to replicate what the script currently does which is a 3-stage build. I also want to add in PGO in the future, which would require 3 stages.

@tstellar tstellar merged commit 3096353 into llvm:main Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category github:workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants