From d51f808e5c7a7776f51d1bbc9f7de7ce98bbfc95 Mon Sep 17 00:00:00 2001 From: Andrew Hayzen Date: Mon, 17 Feb 2025 14:23:46 +0000 Subject: [PATCH 1/4] ctest: use same target folder for build rerun test --- CMakeLists.txt | 2 +- scripts/check_cargo_build_rerun.sh | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f02c4d743..dfccba331 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,7 +168,7 @@ if(BUILD_TESTING) add_test(NAME cxx_qt_gen_test_outputs_gen COMMAND rustfmt --check ${CXX_QT_GEN_TEST_OUTPUTS}) # Add test which checks that a build rerun doesn't recompile and uses caches instead - add_test(NAME cargo_build_rerun COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/scripts/check_cargo_build_rerun.sh" "${CMAKE_CURRENT_SOURCE_DIR}") + add_test(NAME cargo_build_rerun COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/scripts/check_cargo_build_rerun.sh" "${CMAKE_CURRENT_SOURCE_DIR}" "${CARGO_TARGET_DIR}") # Ensure that cargo_build_rerun doesn't run while we are already building set_tests_properties(cargo_build_rerun PROPERTIES RUN_SERIAL TRUE) diff --git a/scripts/check_cargo_build_rerun.sh b/scripts/check_cargo_build_rerun.sh index 5cf4cd570..46649eca1 100755 --- a/scripts/check_cargo_build_rerun.sh +++ b/scripts/check_cargo_build_rerun.sh @@ -7,15 +7,16 @@ set -ex +SOURCE_FOLDER=$1 +BUILD_FOLDER=$2 + # Ensure we are in the right directory -SCRIPT=$(realpath "$0") -SCRIPTPATH=$(dirname "$SCRIPT") -cd "$SCRIPTPATH/../" +cd "$SOURCE_FOLDER" # Ensure that we do see a "Compiling" in the output # as if we do it means we have a cargo::rerun-if-changed incorrectly function check_build_contains_compiling() { - BUILD=$(cargo build -p qml-minimal-no-cmake 2>&1) + BUILD=$(cargo build --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake 2>&1) if ! echo "$BUILD" | grep -q Compiling; then echo "cargo build is missing text 'Compiling', likely an incorrect cargo::rerun-if-changed in a build script." @@ -26,7 +27,7 @@ function check_build_contains_compiling() { # Ensure that we don't see any "Compiling" in the output # as if we do it means we have a cargo::rerun-if-changed incorrectly function check_build_no_compiling() { - BUILD=$(cargo build -p qml-minimal-no-cmake 2>&1) + BUILD=$(cargo build --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake 2>&1) if echo "$BUILD" | grep -q Compiling; then echo "cargo build contained text 'Compiling', likely an incorrect cargo::rerun-if-changed in a build script." @@ -35,20 +36,20 @@ function check_build_no_compiling() { } # Build once -cargo build -p qml-minimal-no-cmake +cargo build --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake # Build a second time check_build_no_compiling # Modify a qml file -touch "$SCRIPTPATH/../examples/cargo_without_cmake/qml/main.qml" +touch "$SOURCE_FOLDER/examples/cargo_without_cmake/qml/main.qml" # Build a third and fourth time check_build_contains_compiling check_build_no_compiling # Modify a Rust file -touch "$SCRIPTPATH/../examples/cargo_without_cmake/src/cxxqt_object.rs" +touch "$SOURCE_FOLDER/examples/cargo_without_cmake/src/cxxqt_object.rs" # Build a fifth and sixth time check_build_contains_compiling From fe57c742b7b1b1a41903ef8838777b913a4eb057 Mon Sep 17 00:00:00 2001 From: Andrew Hayzen Date: Mon, 17 Feb 2025 15:16:57 +0000 Subject: [PATCH 2/4] scripts: use release mode for rerun test to reuse caches --- scripts/check_cargo_build_rerun.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/check_cargo_build_rerun.sh b/scripts/check_cargo_build_rerun.sh index 46649eca1..da8ffc7f1 100755 --- a/scripts/check_cargo_build_rerun.sh +++ b/scripts/check_cargo_build_rerun.sh @@ -16,7 +16,7 @@ cd "$SOURCE_FOLDER" # Ensure that we do see a "Compiling" in the output # as if we do it means we have a cargo::rerun-if-changed incorrectly function check_build_contains_compiling() { - BUILD=$(cargo build --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake 2>&1) + BUILD=$(cargo build --release --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake 2>&1) if ! echo "$BUILD" | grep -q Compiling; then echo "cargo build is missing text 'Compiling', likely an incorrect cargo::rerun-if-changed in a build script." @@ -27,7 +27,7 @@ function check_build_contains_compiling() { # Ensure that we don't see any "Compiling" in the output # as if we do it means we have a cargo::rerun-if-changed incorrectly function check_build_no_compiling() { - BUILD=$(cargo build --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake 2>&1) + BUILD=$(cargo build --release --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake 2>&1) if echo "$BUILD" | grep -q Compiling; then echo "cargo build contained text 'Compiling', likely an incorrect cargo::rerun-if-changed in a build script." @@ -36,7 +36,7 @@ function check_build_no_compiling() { } # Build once -cargo build --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake +cargo build --release --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake # Build a second time check_build_no_compiling From ce6b261dbb619c9450e4f97cac5057d03e23a12a Mon Sep 17 00:00:00 2001 From: Andrew Hayzen Date: Mon, 17 Feb 2025 16:11:37 +0000 Subject: [PATCH 3/4] tests: use --locked for all cargo calls --- CMakeLists.txt | 6 +++--- scripts/check_cargo_build_rerun.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dfccba331..3f5846b73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,10 +149,10 @@ set(CARGO_TARGET_DIR "${CMAKE_BINARY_DIR}/${BUILD_DIR}/cargo/build") if(BUILD_TESTING) # Add CMake tests for `cargo test/clippy/fmt/doc`. - add_test(NAME cargo_tests COMMAND cargo test --release --all-features --target-dir ${CARGO_TARGET_DIR}) - add_test(NAME cargo_doc COMMAND cargo doc --release --all-features --target-dir ${CARGO_TARGET_DIR}) + add_test(NAME cargo_tests COMMAND cargo test --locked --release --all-features --target-dir ${CARGO_TARGET_DIR}) + add_test(NAME cargo_doc COMMAND cargo doc --locked --release --all-features --target-dir ${CARGO_TARGET_DIR}) # Minimum clippy version for the incompatible_msrv lint is 1.78.0 - add_test(NAME cargo_clippy COMMAND cargo +1.78.0 clippy --release --all-features --target-dir ${CARGO_TARGET_DIR} -- -D warnings) + add_test(NAME cargo_clippy COMMAND cargo +1.78.0 clippy --locked --release --all-features --target-dir ${CARGO_TARGET_DIR} -- -D warnings) set_tests_properties(cargo_tests cargo_clippy PROPERTIES ENVIRONMENT_MODIFICATION "${CARGO_ENV}" diff --git a/scripts/check_cargo_build_rerun.sh b/scripts/check_cargo_build_rerun.sh index da8ffc7f1..b3e58b845 100755 --- a/scripts/check_cargo_build_rerun.sh +++ b/scripts/check_cargo_build_rerun.sh @@ -16,7 +16,7 @@ cd "$SOURCE_FOLDER" # Ensure that we do see a "Compiling" in the output # as if we do it means we have a cargo::rerun-if-changed incorrectly function check_build_contains_compiling() { - BUILD=$(cargo build --release --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake 2>&1) + BUILD=$(cargo build --locked --release --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake 2>&1) if ! echo "$BUILD" | grep -q Compiling; then echo "cargo build is missing text 'Compiling', likely an incorrect cargo::rerun-if-changed in a build script." @@ -27,7 +27,7 @@ function check_build_contains_compiling() { # Ensure that we don't see any "Compiling" in the output # as if we do it means we have a cargo::rerun-if-changed incorrectly function check_build_no_compiling() { - BUILD=$(cargo build --release --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake 2>&1) + BUILD=$(cargo build --locked --release --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake 2>&1) if echo "$BUILD" | grep -q Compiling; then echo "cargo build contained text 'Compiling', likely an incorrect cargo::rerun-if-changed in a build script." @@ -36,7 +36,7 @@ function check_build_no_compiling() { } # Build once -cargo build --release --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake +cargo build --locked --release --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake # Build a second time check_build_no_compiling From ca785dbb894bd3bbce1873909ec3bbdde4a386dd Mon Sep 17 00:00:00 2001 From: Andrew Hayzen Date: Mon, 17 Feb 2025 15:33:10 +0000 Subject: [PATCH 4/4] ci: set the CARGO_BUILD_TARGET to reuse same cache Corrosion sets the --target flag to rustc which means that crates are built in the target sub folder. Ensure that other places that call cargo directly reuse this same folder by setting CARGO_BUILD_TARGET. --- .github/workflows/github-cxx-qt-tests.yml | 9 +++++++++ CMakeLists.txt | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github-cxx-qt-tests.yml b/.github/workflows/github-cxx-qt-tests.yml index 0ab0d53ce..7b994168d 100644 --- a/.github/workflows/github-cxx-qt-tests.yml +++ b/.github/workflows/github-cxx-qt-tests.yml @@ -269,6 +269,7 @@ jobs: clang_format_path: /home/runner/.local/bin/clang-format cargo_dir: ~/.cargo rustc_wrapper: sccache + cargo_target: x86_64-unknown-linux-gnu - name: Ubuntu 24.04 (gcc) Qt6 os: ubuntu-24.04 qt_version: 6 @@ -289,6 +290,7 @@ jobs: libgl1-mesa-dev libvulkan-dev libxkbcommon-dev + cargo_target: x86_64-unknown-linux-gnu - name: macOS 13 (clang) Qt5 os: macos-13 @@ -311,6 +313,7 @@ jobs: cc: clang cxx: clang++ rustc_wrapper: sccache + cargo_target: x86_64-apple-darwin - name: macOS 14 (clang) Qt6 os: macos-14 qt_version: 6 @@ -332,6 +335,7 @@ jobs: cc: clang cxx: clang++ rustc_wrapper: sccache + cargo_target: aarch64-apple-darwin - name: Windows 2022 (MSVC) Qt5 os: windows-2022 @@ -350,6 +354,7 @@ jobs: cc: cl cxx: cl rustc_wrapper: sccache + cargo_target: x86_64-pc-windows-msvc - name: Windows 2022 (MSVC2019) Qt6 os: windows-2022 qt_version: 6 @@ -367,6 +372,7 @@ jobs: cc: cl cxx: cl rustc_wrapper: sccache + cargo_target: x86_64-pc-windows-msvc - name: Windows 2022 (MSVC2022) Qt6 os: windows-2022 qt_version: 6 @@ -384,6 +390,7 @@ jobs: cc: cl cxx: cl rustc_wrapper: sccache + cargo_target: x86_64-pc-windows-msvc runs-on: ${{ matrix.os }} name: ${{ matrix.name }} @@ -397,6 +404,8 @@ jobs: SCCACHE_CACHE_SIZE: 600M SCCACHE_LOG: debug SCCACHE_ERROR_LOG: ${{ matrix.sccache_log_path }} + # Ensure that we share the same target sub folder + CARGO_BUILD_TARGET: ${{ matrix.cargo_target }} steps: - name: "Clone Git repository" diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f5846b73..f2e06c95a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,8 +157,10 @@ if(BUILD_TESTING) set_tests_properties(cargo_tests cargo_clippy PROPERTIES ENVIRONMENT_MODIFICATION "${CARGO_ENV}" ) + # Cargo doc cannot have a target set otherwise it fails + # https://github.com/rust-lang/cargo/issues/10368 set_tests_properties(cargo_doc PROPERTIES - ENVIRONMENT_MODIFICATION "${CARGO_ENV};RUSTDOCFLAGS=set:--deny=warnings" + ENVIRONMENT_MODIFICATION "${CARGO_ENV};RUSTDOCFLAGS=set:--deny=warnings;CARGO_BUILD_TARGET=unset:;" ) # Ensure test inputs and outputs are formatted