Skip to content

Commit

Permalink
Set RUSTC_WRAPPER to sccache to speed up building
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonMatthesKDAB committed Jan 24, 2024
1 parent d6ede05 commit 92baeff
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ add_test(NAME cargo_tests COMMAND cargo test --release --all-features --target-d
add_test(NAME cargo_doc COMMAND cargo doc --release --all-features --target-dir ${CARGO_TARGET_DIR})
add_test(NAME cargo_clippy COMMAND cargo clippy --release --all-features --target-dir ${CARGO_TARGET_DIR} -- -D warnings)

if(CMAKE_RUSTC_WRAPPER)
list(APPEND CARGO_ENV "RUSTC_WRAPPER=set:${CMAKE_RUSTC_WRAPPER}")
endif()

set_tests_properties(cargo_tests cargo_clippy PROPERTIES
ENVIRONMENT_MODIFICATION "${CARGO_ENV}"
)
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ syn = { version = "2.0", features = ["extra-traits", "full"] }
quote = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

# Use a patched version of cc-rs that respects the rustc wrapper
# This should greatly speed up CI builds!
[patch.crates-io]
cc = { git = "https://github.com/LeonMatthesKDAB/cc-rs.git", branch="respect-rustc-wrapper" }
19 changes: 12 additions & 7 deletions cmake/CompilerCaching.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# SPDX-FileCopyrightText: 2021 Tenacity Audio Editor contributors
# SPDX-FileContributor: Be <be.0@gmx.com>
# SPDX-FileContributor: Emily Mabrey <emabrey@tenacityaudio.org>
# SPDX-FileContributor: Leon Matthes <leon.matthes@kdab.com>
#
# SPDX-License-Identifier: BSD-3-Clause
#[=======================================================================[.rst:
CompilerCaching
---------------

Search for sccache and ccache and use them for compiler caching for C & C++.
ccache is preferred if both are found, but the user can override this by
explicitly setting CCACHE=OFF to use sccache when both are installed.
sccache is preferred if both are found, but the user can override this by
explicitly setting SCCACHE=OFF to use ccache when both are installed.
#]=======================================================================]

# ccache does not support MSVC
Expand All @@ -33,14 +34,14 @@ else()
option(SCCACHE "Use sccache for compiler caching to speed up rebuilds." ON)
endif()

if(CCACHE)
message(STATUS "Using ccache for compiler caching to speed up rebuilds")
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
elseif(SCCACHE)
if(SCCACHE)
message(STATUS "Using sccache for compiler caching to speed up rebuilds")
set(CMAKE_C_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}")
if (NOT DEFINED ENV{RUSTC_WRAPPER})
# Enable sccache for rustc - especially important when building cxx-qt-lib!
set(CMAKE_RUSTC_WRAPPER "${SCCACHE_PROGRAM}" CACHE PATH "RUSTC_WRAPPER detected by CMake")
endif()

# Instruct MSVC to generate symbolic debug information within object files for sccache
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
Expand All @@ -56,6 +57,10 @@ elseif(SCCACHE)
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_${CONFIG} "${CMAKE_C_FLAGS_${CONFIG}}")
endif()
endif()
elseif(CCACHE)
message(STATUS "Using ccache for compiler caching to speed up rebuilds")
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
else()
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
message(STATUS "No compiler caching enabled. Install sccache to speed up rebuilds.")
Expand Down
1 change: 1 addition & 0 deletions examples/demo_threading/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt")
corrosion_set_env_vars(${CRATE}
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
"QMAKE=${QMAKE}"
$<$<BOOL:${CMAKE_RUSTC_WRAPPER}>:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}>
)

add_library(${APP_NAME}_lib INTERFACE)
Expand Down
1 change: 1 addition & 0 deletions examples/qml_features/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt")
corrosion_set_env_vars(${CRATE}
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
"QMAKE=${QMAKE}"
$<$<BOOL:${CMAKE_RUSTC_WRAPPER}>:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}>
)
add_library(${APP_NAME}_lib INTERFACE)
target_include_directories(${APP_NAME}_lib INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
Expand Down
1 change: 1 addition & 0 deletions examples/qml_minimal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt")
corrosion_set_env_vars(${CRATE}
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
"QMAKE=${QMAKE}"
$<$<BOOL:${CMAKE_RUSTC_WRAPPER}>:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}>
)

# Create an INTERFACE library target to link libraries to and add include paths.
Expand Down
1 change: 1 addition & 0 deletions tests/basic_cxx_only/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt")
corrosion_set_env_vars(${CRATE}
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
"QMAKE=${QMAKE}"
$<$<BOOL:${CMAKE_RUSTC_WRAPPER}>:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}>
)
target_include_directories(${CRATE} INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
target_link_libraries(${CRATE} INTERFACE
Expand Down
1 change: 1 addition & 0 deletions tests/basic_cxx_qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt")
corrosion_set_env_vars(${CRATE}
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
"QMAKE=${QMAKE}"
$<$<BOOL:${CMAKE_RUSTC_WRAPPER}>:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}>
)
target_include_directories(${CRATE} INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
target_link_libraries(${CRATE} INTERFACE
Expand Down
1 change: 1 addition & 0 deletions tests/qt_types_standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt")
corrosion_set_env_vars(${CRATE}
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
"QMAKE=${QMAKE}"
$<$<BOOL:${CMAKE_RUSTC_WRAPPER}>:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}>
)
target_include_directories(${CRATE} INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
target_link_libraries(${CRATE} INTERFACE
Expand Down

0 comments on commit 92baeff

Please sign in to comment.