diff --git a/CMakeLists.txt b/CMakeLists.txt index e13575c0c..611029e42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}" ) diff --git a/Cargo.toml b/Cargo.toml index 329fbda09..fc8949907 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/cmake/CompilerCaching.cmake b/cmake/CompilerCaching.cmake index d3c565fa6..5030fe546 100644 --- a/cmake/CompilerCaching.cmake +++ b/cmake/CompilerCaching.cmake @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 Tenacity Audio Editor contributors # SPDX-FileContributor: Be # SPDX-FileContributor: Emily Mabrey +# SPDX-FileContributor: Leon Matthes # # SPDX-License-Identifier: BSD-3-Clause #[=======================================================================[.rst: @@ -8,8 +9,8 @@ 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 @@ -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") @@ -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.") diff --git a/examples/demo_threading/CMakeLists.txt b/examples/demo_threading/CMakeLists.txt index 85c4adde0..4518eff95 100644 --- a/examples/demo_threading/CMakeLists.txt +++ b/examples/demo_threading/CMakeLists.txt @@ -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}" + $<$:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}> ) add_library(${APP_NAME}_lib INTERFACE) diff --git a/examples/qml_features/CMakeLists.txt b/examples/qml_features/CMakeLists.txt index 0d6e04b34..630a1bcd8 100644 --- a/examples/qml_features/CMakeLists.txt +++ b/examples/qml_features/CMakeLists.txt @@ -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}" + $<$:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}> ) add_library(${APP_NAME}_lib INTERFACE) target_include_directories(${APP_NAME}_lib INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}") diff --git a/examples/qml_minimal/CMakeLists.txt b/examples/qml_minimal/CMakeLists.txt index 00b2ab520..1e1912550 100644 --- a/examples/qml_minimal/CMakeLists.txt +++ b/examples/qml_minimal/CMakeLists.txt @@ -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}" + $<$:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}> ) # Create an INTERFACE library target to link libraries to and add include paths. diff --git a/tests/basic_cxx_only/CMakeLists.txt b/tests/basic_cxx_only/CMakeLists.txt index eb34d8b2b..20a69f52f 100644 --- a/tests/basic_cxx_only/CMakeLists.txt +++ b/tests/basic_cxx_only/CMakeLists.txt @@ -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}" + $<$:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}> ) target_include_directories(${CRATE} INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}") target_link_libraries(${CRATE} INTERFACE diff --git a/tests/basic_cxx_qt/CMakeLists.txt b/tests/basic_cxx_qt/CMakeLists.txt index bfa6355dc..ec6d4cfc4 100644 --- a/tests/basic_cxx_qt/CMakeLists.txt +++ b/tests/basic_cxx_qt/CMakeLists.txt @@ -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}" + $<$:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}> ) target_include_directories(${CRATE} INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}") target_link_libraries(${CRATE} INTERFACE diff --git a/tests/qt_types_standalone/CMakeLists.txt b/tests/qt_types_standalone/CMakeLists.txt index 91f1c95e0..df17f85e1 100644 --- a/tests/qt_types_standalone/CMakeLists.txt +++ b/tests/qt_types_standalone/CMakeLists.txt @@ -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}" + $<$:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}> ) target_include_directories(${CRATE} INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}") target_link_libraries(${CRATE} INTERFACE