Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11599 from shuffle2/vs17.5
vs: update to 17.5
  • Loading branch information
delroth committed Mar 13, 2023
2 parents 37366f6 + 5bf9ad7 commit 936c05e
Show file tree
Hide file tree
Showing 69 changed files with 14,962 additions and 2,695 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -326,7 +326,7 @@ if(MSVC)
# Note: In msbuild build, this gets set by msbuild by default
add_compile_options(/Zc:inline)
# Fix various other non-conformant behaviors
add_compile_options(/Zc:__cplusplus,enumTypes,externConstexpr,preprocessor,throwingNew)
add_compile_options(/Zc:__cplusplus,enumTypes,externConstexpr,preprocessor,templateScope,throwingNew)
# Enforce strict volatile semantics as per ISO C++
add_compile_options(/volatile:iso)

Expand Down
48 changes: 45 additions & 3 deletions Externals/WIL/CMakeLists.txt
@@ -1,13 +1,21 @@
cmake_minimum_required(VERSION 3.11)
cmake_minimum_required(VERSION 3.15)
project(WIL)

include(GNUInstallDirs)

# Set by build server to speed up build/reduce file/object size
option(FAST_BUILD "Sets options to speed up build/reduce obj/executable size" OFF)
option(WIL_BUILD_PACKAGING "Sets option to build the packaging, default on" ON)
option(WIL_BUILD_TESTS "Sets option to build the unit tests, default on" ON)

if (NOT DEFINED WIL_BUILD_VERSION)
set(WIL_BUILD_VERSION "0.0.0")
endif()

if (NOT DEFINED CPPWINRT_VERSION)
set(CPPWINRT_VERSION "2.0.221121.5")
endif()

# Detect the Windows SDK version. If we're using the Visual Studio generator, this will be provided for us. Otherwise
# we'll need to assume that this value comes from the command line (e.g. through the VS command prompt)
if (DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION)
Expand All @@ -17,5 +25,39 @@ else()
string(REGEX REPLACE "\\\\$" "" WIL_WINDOWS_SDK_VERSION "$ENV{WindowsSDKVersion}")
endif()

add_subdirectory(packaging)
add_subdirectory(tests)
if (${WIL_BUILD_PACKAGING})
add_subdirectory(packaging)
endif()

if (${WIL_BUILD_TESTS})
add_subdirectory(tests)
endif()

# Gather headers into an interface library.
file(GLOB_RECURSE HEADER_FILES "${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/*.h")
add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

# The interface's include directory.
target_include_directories(${PROJECT_NAME} INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

# Include the .natvis files
if (MSVC)
target_sources(${PROJECT_NAME} INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/natvis/wil.natvis>")
endif()

# Install Package Configuration
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME_LOWER}_targets)
install(EXPORT ${PROJECT_NAME_LOWER}_targets
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME_LOWER}Config.cmake
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}"
)

# Install the headers at a standard cmake location.
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/wil" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
12 changes: 9 additions & 3 deletions Externals/WIL/README.md
Expand Up @@ -12,7 +12,8 @@ Some things that WIL includes to whet your appetite:
Smart pointers and auto-releasing resource wrappers to let you manage Windows
API HANDLEs, HWNDs, and other resources and resource handles with
[RAII](https://en.cppreference.com/w/cpp/language/raii) semantics.
- [`include/wil/win32_helpers.h`](include/wil/win32_helpers.h): Wrappers for API functions
- [`include/wil/win32_helpers.h`](include/wil/win32_helpers.h)
([documentation](https://github.com/microsoft/wil/wiki/Win32-helpers)): Wrappers for API functions
that save you the work of manually specifying buffer sizes, calling a function twice
to get the needed buffer size and then allocate and pass the right-size buffer,
casting or converting between types, and so on.
Expand All @@ -24,6 +25,11 @@ Some things that WIL includes to whet your appetite:
Preprocessor macros to help you check for errors from Windows API functions,
in many of the myriad ways those errors are reported, and surface them as
error codes or C++ exceptions in your code.
- [`include/wil/Tracelogging.h`](include/wil/Tracelogging.h): This file contains the convenience macros
that enable developers define and log telemetry. These macros use
[`TraceLogging API`](https://docs.microsoft.com/en-us/windows/win32/tracelogging/trace-logging-portal)
to log data. This data can be viewed in tools such as
[`Windows Performance Analyzer`](https://docs.microsoft.com/en-us/windows-hardware/test/wpt/windows-performance-analyzer).

WIL can be used by C++ code that uses C++ exceptions as well as code that uses returned
error codes to report errors. All of WIL can be used from user-space Windows code,
Expand All @@ -50,7 +56,7 @@ Note that even though WIL is a header-only library, you still need to install th
# Building/Testing
To get started testing WIL, first make sure that you have a recent version of [Visual Studio](https://visualstudio.microsoft.com/downloads/) and the most recent [Windows SDK](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk) installed. If you are doing
any non-trivial work, also be sure to have a recent version of [Clang](http://releases.llvm.org/download.html) installed. Once everything is installed, open a VS
native command window (e.g. "x64 Native Tools Command Prompt for VS 2019"). If you are familiar with CMake you can get started building normally. Otherwise, or if you prefer to skip all of the boilerplate, you can use one of the scripts in the [scripts](scripts) directory:
native command window (e.g. "x64 Native Tools Command Prompt for VS 2022"). If you are familiar with CMake you can get started building normally. Otherwise, or if you prefer to skip all of the boilerplate, you can use one of the scripts in the [scripts](scripts) directory:
```cmd
C:\wil> scripts\init.cmd -c clang -g ninja -b debug
```
Expand All @@ -76,7 +82,7 @@ C:\wil> scripts\build_all.cmd
C:\wil> scripts\runtests.cmd
```
Note that this will only test for the architecture that corresponds to the command window you opened. You will want to
repeat this process for the other architecture (e.g. by using the "x86 Native Tools Command Prompt for VS 2019")
repeat this process for the other architecture (e.g. by using the "x86 Native Tools Command Prompt for VS 2022")

# Contributing

Expand Down
106 changes: 54 additions & 52 deletions Externals/WIL/cmake/common_build_flags.cmake
@@ -1,5 +1,6 @@

# E.g. replace_cxx_flag("/W[0-4]", "/W4")
# This is unfortunately still needed to disable exceptions/RTTI since modern CMake still has no builtin support...
# E.g. replace_cxx_flag("/EHsc", "/EHs-c-")
macro(replace_cxx_flag pattern text)
foreach (flag
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
Expand All @@ -10,60 +11,61 @@ macro(replace_cxx_flag pattern text)
endforeach()
endmacro()

macro(append_cxx_flag text)
foreach (flag
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)

string(APPEND ${flag} " ${text}")

endforeach()
endmacro()

# Fixup default compiler settings

# Be as strict as reasonably possible, since we want to support consumers using strict warning levels
replace_cxx_flag("/W[0-4]" "/W4")
append_cxx_flag("/WX")

# We want to be as conformant as possible, so tell MSVC to not be permissive (note that this has no effect on clang-cl)
append_cxx_flag("/permissive-")

# wistd::function has padding due to alignment. This is expected
append_cxx_flag("/wd4324")

if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
# Ignore a few Clang warnings. We may want to revisit in the future to see if any of these can/should be removed
append_cxx_flag("-Wno-switch")
append_cxx_flag("-Wno-c++17-compat-mangling")
append_cxx_flag("-Wno-missing-field-initializers")

# For tests, we want to be able to test self assignment, so disable this warning
append_cxx_flag("-Wno-self-assign-overloaded")
append_cxx_flag("-Wno-self-move")

# clang-cl does not understand the /permissive- flag (or at least it opts to ignore it). We can achieve similar
# results through the following flags.
append_cxx_flag("-fno-delayed-template-parsing")

# NOTE: Windows headers not clean enough for us to realistically attempt to start fixing these errors yet. That
# said, errors that originate from WIL headers may benefit
# append_cxx_flag("-fno-ms-compatibility")
# append_cxx_flag("-ferror-limit=999")
# append_cxx_flag("-fmacro-backtrace-limit=0")
# -fno-ms-compatibility turns off preprocessor compatability, which currently only works when __VA_OPT__ support is
# available (i.e. >= C++20)
# append_cxx_flag("-Xclang -std=c++2a")
add_compile_options(
# Be as strict as reasonably possible, since we want to support consumers using strict warning levels
/W4 /WX
)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(
# Ignore some pedantic warnings enabled by '-Wextra'
-Wno-missing-field-initializers

# Ignore some pedantic warnings enabled by '-Wpedantic'
-Wno-language-extension-token
-Wno-c++17-attribute-extensions
-Wno-gnu-zero-variadic-macro-arguments
-Wno-extra-semi

# For tests, we want to be able to test self assignment, so disable this warning
-Wno-self-assign-overloaded
-Wno-self-move

# clang needs this to enable _InterlockedCompareExchange128
-mcx16

# We don't want legacy MSVC conformance
-fno-delayed-template-parsing

# NOTE: Windows headers not clean enough for us to realistically attempt to start fixing these errors yet. That
# said, errors that originate from WIL headers may benefit
# -fno-ms-compatibility
# -ferror-limit=999
# -fmacro-backtrace-limit=0

# -fno-ms-compatibility turns off preprocessor compatability, which currently only works when __VA_OPT__ support
# is available (i.e. >= C++20)
# -Xclang -std=c++2a
)
else()
# Flags that are either ignored or unrecognized by clang-cl
# TODO: https://github.com/Microsoft/wil/issues/6
# append_cxx_flag("/experimental:preprocessor")
add_compile_options(
# We want to be as conformant as possible, so tell MSVC to not be permissive (note that this has no effect on clang-cl)
/permissive-

# wistd::function has padding due to alignment. This is expected
/wd4324

# TODO: https://github.com/Microsoft/wil/issues/6
# /experimental:preprocessor

# CRT headers are not yet /experimental:preprocessor clean, so work around the known issues
# append_cxx_flag("/Wv:18")
# CRT headers are not yet /experimental:preprocessor clean, so work around the known issues
# /Wv:18

append_cxx_flag("/bigobj")
# Some tests have a LOT of template instantiations
/bigobj

# NOTE: Temporary workaround while https://github.com/microsoft/wil/issues/102 is being investigated
append_cxx_flag("/d2FH4-")
# NOTE: Temporary workaround while https://github.com/microsoft/wil/issues/102 is being investigated
/d2FH4-
)
endif()

0 comments on commit 936c05e

Please sign in to comment.