Skip to content

Commit 71a3f24

Browse files
Set RUSTC_WRAPPER to sccache to speed up building
1 parent d6ede05 commit 71a3f24

File tree

9 files changed

+25
-7
lines changed

9 files changed

+25
-7
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ add_test(NAME cargo_tests COMMAND cargo test --release --all-features --target-d
218218
add_test(NAME cargo_doc COMMAND cargo doc --release --all-features --target-dir ${CARGO_TARGET_DIR})
219219
add_test(NAME cargo_clippy COMMAND cargo clippy --release --all-features --target-dir ${CARGO_TARGET_DIR} -- -D warnings)
220220

221+
if(CMAKE_RUSTC_WRAPPER)
222+
list(APPEND CARGO_ENV "RUSTC_WRAPPER=set:${CMAKE_RUSTC_WRAPPER}")
223+
endif()
224+
221225
set_tests_properties(cargo_tests cargo_clippy PROPERTIES
222226
ENVIRONMENT_MODIFICATION "${CARGO_ENV}"
223227
)

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ syn = { version = "2.0", features = ["extra-traits", "full"] }
5656
quote = "1.0"
5757
serde = { version = "1.0", features = ["derive"] }
5858
serde_json = "1.0"
59+
60+
# Use a patched version of cc-rs that respects the rustc wrapper
61+
# This should greatly speed up CI builds!
62+
[patch.crates-io]
63+
cc = { git = "https://github.com/LeonMatthesKDAB/cc-rs.git", branch="respect-rustc-wrapper" }

cmake/CompilerCaching.cmake

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# SPDX-FileCopyrightText: 2021 Tenacity Audio Editor contributors
22
# SPDX-FileContributor: Be <be.0@gmx.com>
33
# SPDX-FileContributor: Emily Mabrey <emabrey@tenacityaudio.org>
4+
# SPDX-FileContributor: Leon Matthes <leon.matthes@kdab.com>
45
#
56
# SPDX-License-Identifier: BSD-3-Clause
67
#[=======================================================================[.rst:
78
CompilerCaching
89
---------------
910
1011
Search for sccache and ccache and use them for compiler caching for C & C++.
11-
ccache is preferred if both are found, but the user can override this by
12-
explicitly setting CCACHE=OFF to use sccache when both are installed.
12+
sccache is preferred if both are found, but the user can override this by
13+
explicitly setting SCCACHE=OFF to use ccache when both are installed.
1314
#]=======================================================================]
1415

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

36-
if(CCACHE)
37-
message(STATUS "Using ccache for compiler caching to speed up rebuilds")
38-
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
39-
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
40-
elseif(SCCACHE)
37+
if(SCCACHE)
4138
message(STATUS "Using sccache for compiler caching to speed up rebuilds")
4239
set(CMAKE_C_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}")
4340
set(CMAKE_CXX_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}")
41+
# Enable sccache for rustc - especially important when building cxx-qt-lib!
42+
set(CMAKE_RUSTC_WRAPPER "${SCCACHE_PROGRAM}" CACHE PATH "RUSTC_WRAPPER detected by CMake")
4443

4544
# Instruct MSVC to generate symbolic debug information within object files for sccache
4645
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
@@ -56,6 +55,10 @@ elseif(SCCACHE)
5655
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_${CONFIG} "${CMAKE_C_FLAGS_${CONFIG}}")
5756
endif()
5857
endif()
58+
elseif(CCACHE)
59+
message(STATUS "Using ccache for compiler caching to speed up rebuilds")
60+
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
61+
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
5962
else()
6063
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
6164
message(STATUS "No compiler caching enabled. Install sccache to speed up rebuilds.")

examples/demo_threading/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt")
4747
corrosion_set_env_vars(${CRATE}
4848
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
4949
"QMAKE=${QMAKE}"
50+
$<$<BOOL:${CMAKE_RUSTC_WRAPPER}>:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}>
5051
)
5152

5253
add_library(${APP_NAME}_lib INTERFACE)

examples/qml_features/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt")
4747
corrosion_set_env_vars(${CRATE}
4848
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
4949
"QMAKE=${QMAKE}"
50+
$<$<BOOL:${CMAKE_RUSTC_WRAPPER}>:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}>
5051
)
5152
add_library(${APP_NAME}_lib INTERFACE)
5253
target_include_directories(${APP_NAME}_lib INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")

examples/qml_minimal/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt")
6464
corrosion_set_env_vars(${CRATE}
6565
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
6666
"QMAKE=${QMAKE}"
67+
$<$<BOOL:${CMAKE_RUSTC_WRAPPER}>:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}>
6768
)
6869

6970
# Create an INTERFACE library target to link libraries to and add include paths.

tests/basic_cxx_only/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt")
3737
corrosion_set_env_vars(${CRATE}
3838
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
3939
"QMAKE=${QMAKE}"
40+
$<$<BOOL:${CMAKE_RUSTC_WRAPPER}>:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}>
4041
)
4142
target_include_directories(${CRATE} INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
4243
target_link_libraries(${CRATE} INTERFACE

tests/basic_cxx_qt/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt")
3737
corrosion_set_env_vars(${CRATE}
3838
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
3939
"QMAKE=${QMAKE}"
40+
$<$<BOOL:${CMAKE_RUSTC_WRAPPER}>:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}>
4041
)
4142
target_include_directories(${CRATE} INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
4243
target_link_libraries(${CRATE} INTERFACE

tests/qt_types_standalone/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt")
3737
corrosion_set_env_vars(${CRATE}
3838
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
3939
"QMAKE=${QMAKE}"
40+
$<$<BOOL:${CMAKE_RUSTC_WRAPPER}>:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}>
4041
)
4142
target_include_directories(${CRATE} INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
4243
target_link_libraries(${CRATE} INTERFACE

0 commit comments

Comments
 (0)