From 46e60717adea0bb68bab3ffa2abf777b9063f5c3 Mon Sep 17 00:00:00 2001 From: Andrew Hayzen Date: Wed, 6 Sep 2023 11:40:31 +0100 Subject: [PATCH] cmake: set MSVC_RUNTIME_LIBRARY to MultiThreadedDLL As Rust always uses the non-debug Windows runtime for MSVC targets. Related to #682 Related to #676 --- CHANGELOG.md | 1 + examples/demo_threading/CMakeLists.txt | 8 ++++++++ examples/qml_features/CMakeLists.txt | 8 ++++++++ examples/qml_minimal/CMakeLists.txt | 8 ++++++++ tests/basic_cxx_only/CMakeLists.txt | 8 ++++++++ tests/basic_cxx_qt/CMakeLists.txt | 8 ++++++++ tests/qt_types_standalone/CMakeLists.txt | 8 ++++++++ 7 files changed, 49 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f63a4196..7dd51cddd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Do not use -bundle otherwise CMake builds are missing qt-static-initalizers (note this is broken in rustc 1.69) - Do not import `Pin` in hidden module as invokables are outside now, resolving IDE integration +- Rust always links against a non-debug Windows runtime with *-msvc targets, so we need to link to MultiThreadedDLL ### Removed diff --git a/examples/demo_threading/CMakeLists.txt b/examples/demo_threading/CMakeLists.txt index 138ea4e02..e817b70e5 100644 --- a/examples/demo_threading/CMakeLists.txt +++ b/examples/demo_threading/CMakeLists.txt @@ -8,6 +8,14 @@ cmake_minimum_required(VERSION 3.24) project(demo_threading) set(APP_NAME ${PROJECT_NAME}) +# Rust always links against non-debug Windows runtime on *-msvc targets +# Note it is best to set this on the command line to ensure all targets are consistent +# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets +# https://github.com/rust-lang/rust/issues/39016 +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") +endif() + set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) diff --git a/examples/qml_features/CMakeLists.txt b/examples/qml_features/CMakeLists.txt index 64b1ae3e9..2d8f97cdb 100644 --- a/examples/qml_features/CMakeLists.txt +++ b/examples/qml_features/CMakeLists.txt @@ -9,6 +9,14 @@ cmake_minimum_required(VERSION 3.24) project(example_qml_features) set(APP_NAME ${PROJECT_NAME}) +# Rust always links against non-debug Windows runtime on *-msvc targets +# Note it is best to set this on the command line to ensure all targets are consistent +# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets +# https://github.com/rust-lang/rust/issues/39016 +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") +endif() + set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) diff --git a/examples/qml_minimal/CMakeLists.txt b/examples/qml_minimal/CMakeLists.txt index 04e3363a7..970054db3 100644 --- a/examples/qml_minimal/CMakeLists.txt +++ b/examples/qml_minimal/CMakeLists.txt @@ -10,6 +10,14 @@ cmake_minimum_required(VERSION 3.24) project(example_qml_minimal) set(APP_NAME ${PROJECT_NAME}) +# Rust always links against non-debug Windows runtime on *-msvc targets +# Note it is best to set this on the command line to ensure all targets are consistent +# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets +# https://github.com/rust-lang/rust/issues/39016 +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") +endif() + set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) diff --git a/tests/basic_cxx_only/CMakeLists.txt b/tests/basic_cxx_only/CMakeLists.txt index a3f3be1c8..55618b040 100644 --- a/tests/basic_cxx_only/CMakeLists.txt +++ b/tests/basic_cxx_only/CMakeLists.txt @@ -9,6 +9,14 @@ cmake_minimum_required(VERSION 3.24) project(tests_basic_cxx_only) set(APP_NAME ${PROJECT_NAME}) +# Rust always links against non-debug Windows runtime on *-msvc targets +# Note it is best to set this on the command line to ensure all targets are consistent +# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets +# https://github.com/rust-lang/rust/issues/39016 +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") +endif() + # TODO: Add a helper function to our CMake module which automatically # handles some of this boilerplate for a "typical" Qt application set(CMAKE_AUTOMOC ON) diff --git a/tests/basic_cxx_qt/CMakeLists.txt b/tests/basic_cxx_qt/CMakeLists.txt index 252679763..bfa6355dc 100644 --- a/tests/basic_cxx_qt/CMakeLists.txt +++ b/tests/basic_cxx_qt/CMakeLists.txt @@ -9,6 +9,14 @@ cmake_minimum_required(VERSION 3.24) project(tests_basic_cxx_qt) set(APP_NAME ${PROJECT_NAME}) +# Rust always links against non-debug Windows runtime on *-msvc targets +# Note it is best to set this on the command line to ensure all targets are consistent +# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets +# https://github.com/rust-lang/rust/issues/39016 +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") +endif() + # TODO: Add a helper function to our CMake module which automatically # handles some of this boilerplate for a "typical" Qt application set(CMAKE_AUTOMOC ON) diff --git a/tests/qt_types_standalone/CMakeLists.txt b/tests/qt_types_standalone/CMakeLists.txt index 2dd07d8ee..b1d0b1400 100644 --- a/tests/qt_types_standalone/CMakeLists.txt +++ b/tests/qt_types_standalone/CMakeLists.txt @@ -9,6 +9,14 @@ cmake_minimum_required(VERSION 3.24) project(tests_qt_types_standalone) set(APP_NAME ${PROJECT_NAME}) +# Rust always links against non-debug Windows runtime on *-msvc targets +# Note it is best to set this on the command line to ensure all targets are consistent +# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets +# https://github.com/rust-lang/rust/issues/39016 +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") +endif() + # TODO: Add a helper function to our CMake module which automatically # handles some of this boilerplate for a "typical" Qt application set(CMAKE_AUTOMOC ON)