Skip to content
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

Add compiler cache and fix CMake deprecation warnings #2132

Merged
merged 8 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/scripts/setup-sccache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/sh

export SCCACHE_VERSION="${SCCACHE_VERSION:=0.9.0}"

export sccache_arch="x86_64"
if [ "$RUNNER_ARCH" = "X86" ]; then
export sccache_arch="i686"
elif [ "$RUNNER_ARCH" = "X64" ]; then
export sccache_arch="x86_64"
elif [ "$RUNNER_ARCH" = "ARM" ]; then
export sccache_arch="armv7"
elif [ "$RUNNER_ARCH" = "ARM64" ]; then
export sccache_arch="aarch64"
fi

install_sccache() {
export sccache_archive="sccache-v$SCCACHE_VERSION-$sccache_arch-$sccache_os"
export sccache_url="https://github.com/mozilla/sccache/releases/download/v$SCCACHE_VERSION/$sccache_archive.tar.gz"

echo "Downloading $sccache_url..."
if ! wget -q "$sccache_url"; then
echo "Can't download $sccache_url.">2
exit 1
fi
echo "Extracting $sccache_archive.tar.gz..."
if ! tar -xzf "$sccache_archive.tar.gz" >/dev/null; then
echo "Can't extract $sccache_archive.tar.gz">2
exit 1
fi
chmod +x "$sccache_archive/sccache"
sudo cp "$sccache_archive/sccache" "/usr/local/bin/sccache"
rm -rf "$sccache_archive.tar.gz"
rm -rf "$sccache_archive"
}

export sccache_os="unknown-linux-musl"
if [ "$RUNNER_OS" = "Linux" ]; then
export sccache_os="unknown-linux-musl"
if [ "$RUNNER_ARCH" = "ARM" ]; then
export sccache_os="unknown-linux-musleabi"
fi
if ! install_sccache; then
echo "Unable to install sccache!" >2
exit 1
fi
elif [ "$RUNNER_OS" = "macOS" ]; then
export sccache_os="apple-darwin"
if ! install_sccache; then
echo "Unable to install sccache!" >2
exit 1
fi
elif [ "$RUNNER_OS" = "Windows" ]; then
export sccache_os="pc-windows-msvc"
if ! install_sccache; then
echo "Unable to install sccache!" >2
exit 1
fi
fi

echo "sccache installed."

# Configure
mkdir $HOME/.sccache
echo "SCCACHE_DIR=$HOME/.sccache" >> $GITHUB_ENV
if [ "$RUNNER_DEBUG" = "1" ]; then
echo "Running with debug output; cached binary artifacts will be ignored to produce a cleaner build"
echo "SCCACHE_RECACHE=true" >> $GITHUB_ENV
fi

echo "sccache configured."
23 changes: 19 additions & 4 deletions .github/workflows/build-and-test-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
SCCACHE_VERSION: "0.9.0"

jobs:
build:
strategy:
Expand Down Expand Up @@ -85,6 +88,16 @@ jobs:
g++
- name: Checkout
uses: actions/checkout@v4
- name: Install sccache
run: .github/scripts/setup-sccache.sh
- name: Load cached compilation artifacts
id: compiler-cache
uses: actions/cache@v4
with:
path: "${{ env.SCCACHE_DIR }}"
key: sccache-${{ matrix.os }}-${{ matrix.x11 }}-${{ matrix.wayland }}-${{ matrix.compiler }}-${{ github.ref }}-${{ github.run_id }}
restore-keys: |
sccache-${{ matrix.os }}-${{ matrix.x11 }}-${{ matrix.wayland }}-${{ matrix.compiler }}-${{ github.ref }}
- name: Configure with CMake
run: |
set -x # show the commands we're running
Expand All @@ -100,9 +113,10 @@ jobs:
RSVG_ENABLED=ON
[[ "${{ matrix.os }}" == "ubuntu-20.04"* ]] && RSVG_ENABLED=OFF

mkdir build
cd build
cmake .. -G Ninja \
# Reset sccache statistics
sccache --zero-stats

cmake . -B build -G Ninja \
-DBUILD_AUDACIOUS=ON \
-DBUILD_HTTP=ON \
-DBUILD_ICAL=ON \
Expand All @@ -119,7 +133,6 @@ jobs:
-DBUILD_PULSEAUDIO=ON \
-DBUILD_CURL=ON \
-DBUILD_RSS=ON \
-DBUILD_TESTS=ON \
-DBUILD_WLAN=ON \
-DBUILD_WAYLAND=${{ matrix.wayland }}\
-DBUILD_X11=${{ matrix.x11 }} \
Expand All @@ -129,6 +142,8 @@ jobs:
-DMAINTAINER_MODE=ON
- name: Compile
run: cmake --build build
- name: Show sccache stats
run: sccache --show-stats
- name: Test
working-directory: build
run: ctest --output-on-failure
26 changes: 21 additions & 5 deletions .github/workflows/build-and-test-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ on:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
SCCACHE_VERSION: "0.9.0"

jobs:
build:
env:
Expand Down Expand Up @@ -50,18 +54,30 @@ jobs:
|| true # Ignore errors
- name: Checkout
uses: actions/checkout@v4
- run: mkdir build
- name: Configure sccache
run: .github/scripts/setup-sccache.sh
- name: Load cached compilation artifacts
id: compiler-cache
uses: actions/cache@v4
with:
path: "${{ env.SCCACHE_DIR }}"
key: sccache-${{ matrix.os }}-${{ github.ref }}-${{ github.run_id }}
restore-keys: |
sccache-${{ matrix.os }}-${{ github.ref }}
- name: Configure with CMake
working-directory: build
run: |
cmake .. -G Ninja \
# Reset sccache statistics
sccache --zero-stats

cmake . -B build -G Ninja \
-DMAINTAINER_MODE=ON \
-DBUILD_WAYLAND=OFF \
-DBUILD_RSS=ON \
-DBUILD_CURL=ON \
-DBUILD_TESTS=ON
-DBUILD_CURL=ON
- name: Compile
run: cmake --build build
- name: Show sccache stats
run: sccache --show-stats
- name: Test
working-directory: build
run: ctest --output-on-failure
19 changes: 19 additions & 0 deletions .github/workflows/publish-appimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
SCCACHE_VERSION: "0.9.0"

jobs:
build:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -106,10 +109,26 @@ jobs:
libc++abi-${CLANG_VERSION}-dev
echo "CC=clang-${CLANG_VERSION}" | tee -a $GITHUB_ENV
echo "CXX=clang++-${CLANG_VERSION}" | tee -a $GITHUB_ENV
- name: Install sccache
if: startsWith(github.ref, 'refs/tags/') != true
run: .github/scripts/setup-sccache.sh
- name: Load cached compilation artifacts
if: startsWith(github.ref, 'refs/tags/') != true
id: compiler-cache
uses: actions/cache@v4
with:
path: "${{ env.SCCACHE_DIR }}"
key: sccache-${{ matrix.os }}-${{ matrix.arch }}-${{ github.ref }}-${{ github.run_id }}
restore-keys: |
sccache-${{ matrix.os }}-${{ matrix.arch }}-${{ github.ref }}
- name: Build AppImage
run: ./appimage/build.sh
env:
RELEASE: "${{ startsWith(github.ref, 'refs/tags/') && 'ON' || 'OFF' }}"
- name: Show sccache stats
if: startsWith(github.ref, 'refs/tags/') != true
run: sccache --show-stats
- run: ./conky-x86_64.AppImage --version # print version
- name: Set CONKY_VERSION
run: echo "CONKY_VERSION=$(./conky-x86_64.AppImage --short-version)" | tee -a $GITHUB_ENV
Expand Down
9 changes: 0 additions & 9 deletions 3rdparty/Vc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ else()
message(WARNING "No optimized implementation of the Vc types available for ${CMAKE_SYSTEM_PROCESSOR}")
endif()

option(USE_CCACHE "If enabled, ccache will be used (if it exists on the system) to speed up recompiles." OFF)
if(USE_CCACHE)
find_program(CCACHE_COMMAND ccache)
if(CCACHE_COMMAND)
mark_as_advanced(CCACHE_COMMAND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_COMMAND}")
endif()
endif()

if(NOT Vc_COMPILER_IS_MSVC)
AddCompilerFlag("-std=c++14" CXX_RESULT _ok CXX_FLAGS CMAKE_CXX_FLAGS)
if(NOT _ok)
Expand Down
5 changes: 4 additions & 1 deletion 3rdparty/Vc/cmake/OptimizeForArchitecture.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ macro(AutodetectHostArchitecture)
string(REGEX REPLACE ".*model[ \t]*:[ \t]+([a-zA-Z0-9_-]+).*" "\\1" _cpu_model "${_cpuinfo}")
string(REGEX REPLACE ".*flags[ \t]*:[ \t]+([^\n]+).*" "\\1" _cpu_flags "${_cpuinfo}")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
exec_program("/usr/sbin/sysctl -n machdep.cpu.vendor machdep.cpu.model machdep.cpu.family machdep.cpu.features" OUTPUT_VARIABLE _sysctl_output_string)
execute_process(COMMAND "/usr/sbin/sysctl" -n machdep.cpu.vendor machdep.cpu.model machdep.cpu.family machdep.cpu.features
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE _sysctl_output_string)
mark_as_advanced(_sysctl_output_string)
string(REPLACE "\n" ";" _sysctl_output ${_sysctl_output_string})
list(GET _sysctl_output 0 _vendor_id)
list(GET _sysctl_output 1 _cpu_model)
Expand Down
40 changes: 29 additions & 11 deletions 3rdparty/Vc/cmake/VcMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ include("${_currentDir}/OptimizeForArchitecture.cmake")

macro(vc_determine_compiler)
if(NOT DEFINED Vc_COMPILER_IS_INTEL)
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE _cxx_compiler_version ERROR_VARIABLE _cxx_compiler_version)
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version"
OUTPUT_VARIABLE _cxx_compiler_version
ERROR_VARIABLE _cxx_compiler_version)
set(Vc_COMPILER_IS_INTEL false)
set(Vc_COMPILER_IS_OPEN64 false)
set(Vc_COMPILER_IS_CLANG false)
Expand All @@ -50,7 +52,8 @@ macro(vc_determine_compiler)

if(CMAKE_CXX_COMPILER MATCHES "/(icpc|icc)$")
set(Vc_COMPILER_IS_INTEL true)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE Vc_ICC_VERSION)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
OUTPUT_VARIABLE Vc_ICC_VERSION)
message(STATUS "Detected Compiler: Intel ${Vc_ICC_VERSION}")

# break build with too old clang as early as possible.
Expand All @@ -62,7 +65,8 @@ macro(vc_determine_compiler)
message(STATUS "Detected Compiler: Open64")
elseif(CMAKE_CXX_COMPILER MATCHES "clang\\+\\+$" OR "${_cxx_compiler_version}" MATCHES "clang")
set(Vc_COMPILER_IS_CLANG true)
exec_program(${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE Vc_CLANG_VERSION)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version
OUTPUT_VARIABLE Vc_CLANG_VERSION)
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" Vc_CLANG_VERSION "${Vc_CLANG_VERSION}")
message(STATUS "Detected Compiler: Clang ${Vc_CLANG_VERSION}")

Expand All @@ -75,13 +79,15 @@ macro(vc_determine_compiler)
message(STATUS "Detected Compiler: MSVC ${MSVC_VERSION}")
elseif(CMAKE_COMPILER_IS_GNUCXX)
set(Vc_COMPILER_IS_GCC true)
exec_program(${CMAKE_CXX_COMPILER} ARGS -dumpversion OUTPUT_VARIABLE Vc_GCC_VERSION)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ARGS -dumpversion
OUTPUT_VARIABLE Vc_GCC_VERSION)
message(STATUS "Detected Compiler: GCC ${Vc_GCC_VERSION}")

# some distributions patch their GCC to return nothing or only major and minor version on -dumpversion.
# In that case we must extract the version number from --version.
if(NOT Vc_GCC_VERSION OR Vc_GCC_VERSION MATCHES "^[0-9]\\.[0-9]+$")
exec_program(${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE Vc_GCC_VERSION)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ARGS --version
OUTPUT_VARIABLE Vc_GCC_VERSION)
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" Vc_GCC_VERSION "${Vc_GCC_VERSION}")
message(STATUS "GCC Version from --version: ${Vc_GCC_VERSION}")
endif()
Expand All @@ -93,21 +99,29 @@ macro(vc_determine_compiler)

if(Vc_lsb_release)
if(NOT Vc_distributor_id)
execute_process(COMMAND ${Vc_lsb_release} -is OUTPUT_VARIABLE Vc_distributor_id OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${Vc_lsb_release} -is
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE Vc_distributor_id)
string(TOUPPER "${Vc_distributor_id}" Vc_distributor_id)
set(Vc_distributor_id "${Vc_distributor_id}" CACHE STRING "lsb distribution id")
execute_process(COMMAND ${Vc_lsb_release} -rs OUTPUT_VARIABLE Vc_distributor_release OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${Vc_lsb_release} -rs
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE Vc_distributor_release)
set(Vc_distributor_release "${Vc_distributor_release}" CACHE STRING "lsb release id")
endif()

if(Vc_distributor_id STREQUAL "UBUNTU")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE _gcc_version)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE _gcc_version)
string(REGEX MATCH "\\(.* ${Vc_GCC_VERSION}-([0-9]+).*\\)" _tmp "${_gcc_version}")

if(_tmp)
set(_patch ${CMAKE_MATCH_1})
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)$" _tmp "${Vc_distributor_release}")
execute_process(COMMAND printf 0x%x%02x%02x ${CMAKE_MATCH_1} ${CMAKE_MATCH_2} ${_patch} OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE _tmp)
execute_process(COMMAND printf 0x%x%02x%02x ${CMAKE_MATCH_1} ${CMAKE_MATCH_2} ${_patch}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE _tmp)
set(Vc_DEFINITIONS "${Vc_DEFINITIONS} -D__GNUC_UBUNTU_VERSION__=${_tmp}")
endif()
endif()
Expand Down Expand Up @@ -151,15 +165,19 @@ macro(vc_add_compiler_flag VAR _flag)
endmacro()

macro(vc_check_assembler)
exec_program(${CMAKE_CXX_COMPILER} ARGS -print-prog-name=as OUTPUT_VARIABLE _as)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-prog-name=as
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE _as)
mark_as_advanced(_as)

if(NOT _as)
message(WARNING "Could not find 'as', the assembler used by GCC. Hoping everything will work out...")
else()
exec_program(${_as} ARGS --version OUTPUT_VARIABLE _as_version)
execute_process(COMMAND ${_as} --version
OUTPUT_VARIABLE _as_version)
string(REGEX REPLACE "\\([^\\)]*\\)" "" _as_version "${_as_version}")
string(REGEX MATCH "[1-9]\\.[0-9]+(\\.[0-9]+)?" _as_version "${_as_version}")
message(STATUS "Detected assembler: ${_as} ${_as_version}")

if(_as_version VERSION_LESS "2.18.93")
UserWarning("Your binutils is too old (${_as_version}). Some optimizations of Vc will be disabled.")
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ include(ConkyPlatformChecks)
# CPack module for installation tasks
include(ConkyCPackSetup)

# Use compilation cache (if enabled)
include(CCache)

# setup our configuration headers
configure_file(${CMAKE_MODULE_PATH}/config.h.in ${CMAKE_BINARY_DIR}/config.h)
configure_file(${CMAKE_MODULE_PATH}/build.h.in ${CMAKE_BINARY_DIR}/build.h)
Expand All @@ -61,7 +64,7 @@ if(BUILD_EXTRAS)
add_subdirectory(extras)
endif(BUILD_EXTRAS)

if(BUILD_TESTS)
if(BUILD_TESTING)
if(CODE_COVERAGE)
# Enable coverage checks
include(CodeCoverage)
Expand All @@ -73,7 +76,7 @@ endif()

add_subdirectory(src)

if(BUILD_TESTS)
if(BUILD_TESTING)
add_subdirectory(tests)
enable_testing()
endif()
Expand Down
22 changes: 22 additions & 0 deletions cmake/CCache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if(NOT USE_CCACHE)
return()
endif()

find_program(CCACHE_COMMAND sccache)
if(CCACHE_COMMAND)
mark_as_advanced(CCACHE_COMMAND)
message(STATUS "Using sccache; disable with '-DUSE_CCACHE=OFF'")
else()
find_program(CCACHE_COMMAND ccache)
if(CCACHE_COMMAND)
mark_as_advanced(CCACHE_COMMAND)
message(STATUS "Using ccache; disable with '-DUSE_CCACHE=OFF'")
else()
message(WARNING "Neither sccache nor ccache found")
return()
endif()
endif()

set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_COMMAND}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_COMMAND}")
set(CMAKE_CUDA_COMPILER_LAUNCHER "${CCACHE_COMMAND}")
Loading
Loading