From 6ce58becd2d541e84cfad59ec60addbfff004f26 Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Tue, 9 Mar 2021 21:51:50 +0000 Subject: [PATCH] Fix VS clang-cl build * Disable "undefined-var-template" in code, rather than in build files * Add back some missing headers required when building in this context * Make sure gtest/gmock do not override the default runtime library Change-Id: I12c05943fc1d2dee4733ae70db7da026f67e0dad Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44180 Reviewed-by: Ben Clayton Commit-Queue: Antonio Maiorano --- src/castable.h | 35 ++++++++++++++++++++++++++++----- src/reader/spirv/parser_impl.cc | 1 + src/source.h | 1 + third_party/CMakeLists.txt | 1 + 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/castable.h b/src/castable.h index c5d88c323f..956f4f65d0 100644 --- a/src/castable.h +++ b/src/castable.h @@ -17,6 +17,26 @@ #include +#if defined(__clang__) +/// Temporarily disable certain warnings when using Castable API +#define TINT_CASTABLE_PUSH_DISABLE_WARNINGS() \ + _Pragma("clang diagnostic push") /**/ \ + _Pragma("clang diagnostic ignored \"-Wundefined-var-template\"") /**/ \ + static_assert(true, "require extra semicolon") + +/// Restore disabled warnings +#define TINT_CASTABLE_POP_DISABLE_WARNINGS() \ + _Pragma("clang diagnostic pop") /**/ \ + static_assert(true, "require extra semicolon") +#else +#define TINT_CASTABLE_PUSH_DISABLE_WARNINGS() \ + static_assert(true, "require extra semicolon") +#define TINT_CASTABLE_POP_DISABLE_WARNINGS() \ + static_assert(true, "require extra semicolon") +#endif + +TINT_CASTABLE_PUSH_DISABLE_WARNINGS(); + namespace tint { namespace detail { @@ -25,11 +45,14 @@ struct TypeInfoOf; } // namespace detail /// Helper macro to instantiate the TypeInfo template for `CLASS`. -#define TINT_INSTANTIATE_TYPEINFO(CLASS) \ - template <> \ - const tint::TypeInfo tint::detail::TypeInfoOf::info { \ - &tint::detail::TypeInfoOf::info, #CLASS, \ - } +#define TINT_INSTANTIATE_TYPEINFO(CLASS) \ + TINT_CASTABLE_PUSH_DISABLE_WARNINGS(); \ + template <> \ + const tint::TypeInfo tint::detail::TypeInfoOf::info{ \ + &tint::detail::TypeInfoOf::info, \ + #CLASS, \ + }; \ + TINT_CASTABLE_POP_DISABLE_WARNINGS() /// TypeInfo holds type information for a Castable type. struct TypeInfo { @@ -197,4 +220,6 @@ inline TO* As(FROM* obj) { } // namespace tint +TINT_CASTABLE_POP_DISABLE_WARNINGS(); + #endif // SRC_CASTABLE_H_ diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index 729e33ddf6..b694b6d205 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -15,6 +15,7 @@ #include "src/reader/spirv/parser_impl.h" #include +#include #include "source/opt/build_module.h" #include "src/ast/bitcast_expression.h" diff --git a/src/source.h b/src/source.h index f56953c85d..416a30e2cd 100644 --- a/src/source.h +++ b/src/source.h @@ -16,6 +16,7 @@ #ifndef SRC_SOURCE_H_ #define SRC_SOURCE_H_ +#include #include #include diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index b14613c944..734ebca931 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -13,6 +13,7 @@ # limitations under the License. if (${TINT_BUILD_TESTS} AND NOT TARGET gmock) + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/googletest EXCLUDE_FROM_ALL) endif()