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 f02c4d743..ace195a4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,31 +134,24 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND BUILD_TESTING) list(APPEND CARGO_ENV ${RUNTIME_ENV}) endif() -# Same logic as in Corrosion.cmake -if(CMAKE_VS_PLATFORM_NAME) - set(BUILD_DIR "${CMAKE_VS_PLATFORM_NAME}/$") -elseif(CMAKE_CONFIGURATION_TYPES) - set(BUILD_DIR "$") -else() - set(BUILD_DIR .) -endif() - # Set the target dir to the same that Corrosion uses to reuse build artifacts # from the main build. -set(CARGO_TARGET_DIR "${CMAKE_BINARY_DIR}/${BUILD_DIR}/cargo/build") +set(CARGO_TARGET_DIR "${CMAKE_BINARY_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}" ) + # 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 @@ -168,7 +161,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..b3e58b845 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 --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." @@ -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 --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." @@ -35,20 +36,20 @@ function check_build_no_compiling() { } # Build once -cargo build -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 # 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