From 7ff582b963bdfca74f942704fd0c1deb96c27e3e Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Wed, 29 Mar 2023 16:52:04 +0200 Subject: [PATCH] Deprecate ENABLE_CCACHE and replace it by COMPILER_CACHE --- CMakeLists.txt | 2 +- cmake/ccache.cmake | 29 +++++++++++++++++++---------- docker/packager/packager | 9 +++------ tests/ci/fast_test_check.py | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd7de46474b..ce615c11f2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -568,7 +568,7 @@ if (NATIVE_BUILD_TARGETS COMMAND ${CMAKE_COMMAND} "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" - "-DENABLE_CCACHE=${ENABLE_CCACHE}" + "-DCOMPILER_CACHE=${COMPILER_CACHE}" # Avoid overriding .cargo/config.toml with native toolchain. "-DENABLE_RUST=OFF" "-DENABLE_CLICKHOUSE_SELF_EXTRACTING=${ENABLE_CLICKHOUSE_SELF_EXTRACTING}" diff --git a/cmake/ccache.cmake b/cmake/ccache.cmake index 6103a5212e3..285c8efb9e1 100644 --- a/cmake/ccache.cmake +++ b/cmake/ccache.cmake @@ -1,5 +1,6 @@ # Setup integration with ccache to speed up builds, see https://ccache.dev/ +# Matches both ccache and sccache if (CMAKE_CXX_COMPILER_LAUNCHER MATCHES "ccache" OR CMAKE_C_COMPILER_LAUNCHER MATCHES "ccache") # custom compiler launcher already defined, most likely because cmake was invoked with like "-DCMAKE_CXX_COMPILER_LAUNCHER=ccache" or # via environment variable --> respect setting and trust that the launcher was specified correctly @@ -8,24 +9,32 @@ if (CMAKE_CXX_COMPILER_LAUNCHER MATCHES "ccache" OR CMAKE_C_COMPILER_LAUNCHER MA return() endif() -option(ENABLE_CCACHE "Speedup re-compilations using ccache (default) or sccache (external tools)" ON) -option(FORCE_SCCACHE "Use sccache by default" OFF) - -if (NOT ENABLE_CCACHE AND NOT FORCE_SCCACHE) - message(STATUS "Using *ccache: no (disabled via configuration)") - return() +set(ENABLE_CCACHE "default" CACHE STRING "Deprecated, use COMPILER_CACHE=(auto|ccache|sccache|disabled)") +if (NOT ENABLE_CCACHE STREQUAL "default") + message(WARNING "The -DENABLE_CCACHE is deprecated in favor of -DCOMPILER_CACHE") endif() -# We support ccache and sccache -if (FORCE_SCCACHE) +set(COMPILER_CACHE "auto" CACHE STRING "Speedup re-compilations using the caching tools; valid options are 'auto' (ccache, then sccache), 'ccache', 'sccache', or 'disabled'") + +# It has pretty complex logic, because the ENABLE_CCACHE is deprecated, but still should +# control the COMPILER_CACHE +# After it will be completely removed, the following block will be much simpler +if (COMPILER_CACHE STREQUAL "ccache" OR (ENABLE_CCACHE AND NOT ENABLE_CCACHE STREQUAL "default")) + find_program (CCACHE_EXECUTABLE ccache) +elseif(COMPILER_CACHE STREQUAL "disabled" OR NOT ENABLE_CCACHE STREQUAL "default") + message(STATUS "Using *ccache: no (disabled via configuration)") + return() +elseif(COMPILER_CACHE STREQUAL "auto") + find_program (CCACHE_EXECUTABLE ccache sccache) +elseif(COMPILER_CACHE STREQUAL "sccache") find_program (CCACHE_EXECUTABLE sccache) else() - find_program (CCACHE_EXECUTABLE ccache sccache) + message(${RECONFIGURE_MESSAGE_LEVEL} "The COMPILER_CACHE must be one of (auto|ccache|sccache|disabled), given '${COMPILER_CACHE}'") endif() if (NOT CCACHE_EXECUTABLE) - message(${RECONFIGURE_MESSAGE_LEVEL} "Using *ccache: no (Could not find find ccache or sccache. To significantly reduce compile times for the 2nd, 3rd, etc. build, it is highly recommended to install one of them. To suppress this message, run cmake with -DENABLE_CCACHE=0)") + message(${RECONFIGURE_MESSAGE_LEVEL} "Using *ccache: no (Could not find find ccache or sccache. To significantly reduce compile times for the 2nd, 3rd, etc. build, it is highly recommended to install one of them. To suppress this message, run cmake with -DCOMPILER_CACHE=disabled)") return() endif() diff --git a/docker/packager/packager b/docker/packager/packager index e4b17a3a1da..7d022df52e6 100755 --- a/docker/packager/packager +++ b/docker/packager/packager @@ -257,12 +257,10 @@ def parse_env_variables( result.append("BUILD_TYPE=None") if not cache: - cmake_flags.append("-DENABLE_CCACHE=OFF") - cmake_flags.append("-DFORCE_SCCACHE=OFF") + cmake_flags.append("-DCOMPILER_CACHE=disabled") if cache == "ccache": - cmake_flags.append("-DENABLE_CCACHE=ON") - cmake_flags.append("-DFORCE_SCCACHE=OFF") + cmake_flags.append("-DCOMPILER_CACHE=ccache") result.append("CCACHE_DIR=/ccache") result.append("CCACHE_COMPRESSLEVEL=5") result.append("CCACHE_BASEDIR=/build") @@ -271,8 +269,7 @@ def parse_env_variables( result.append("CCACHE_MAXSIZE=15G") if cache == "sccache": - cmake_flags.append("-DENABLE_CCACHE=OFF") - cmake_flags.append("-DFORCE_SCCACHE=ON") + cmake_flags.append("-DCOMPILER_CACHE=sccache") # see https://github.com/mozilla/sccache/blob/main/docs/S3.md result.append(f"SCCACHE_BUCKET={s3_bucket}") sccache_dir = "sccache" diff --git a/tests/ci/fast_test_check.py b/tests/ci/fast_test_check.py index 9981234f87c..54367f70b3f 100644 --- a/tests/ci/fast_test_check.py +++ b/tests/ci/fast_test_check.py @@ -43,7 +43,7 @@ def get_fasttest_cmd(workspace, output_path, repo_path, pr_number, commit_sha, i "--network=host " # required to get access to IAM credentials f"-e FASTTEST_WORKSPACE=/fasttest-workspace -e FASTTEST_OUTPUT=/test_output " f"-e FASTTEST_SOURCE=/ClickHouse --cap-add=SYS_PTRACE " - f"-e FASTTEST_CMAKE_FLAGS='-DENABLE_CCACHE=OFF -DFORCE_SCCACHE=ON' " + f"-e FASTTEST_CMAKE_FLAGS='-DCOMPILER_CACHE=sccache' " f"-e PULL_REQUEST_NUMBER={pr_number} -e COMMIT_SHA={commit_sha} " f"-e COPY_CLICKHOUSE_BINARY_TO_OUTPUT=1 " f"-e SCCACHE_BUCKET={S3_BUILDS_BUCKET} -e SCCACHE_S3_KEY_PREFIX=ccache/sccache "