Skip to content

Commit 07e644d

Browse files
committed
feat: Enhance MSVC support with global flags and update dependencies
1 parent 04682cb commit 07e644d

11 files changed

Lines changed: 58 additions & 17 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ include(cmake/Options.cmake) # VMPILOT_ENABLE_TESTS, _SANITIZERS, _LT
1818
include(cmake/CompilerWarnings.cmake) # vmpilot_options INTERFACE target
1919
include(cmake/Sanitizers.cmake) # vmpilot_sanitizer INTERFACE target
2020
include(cmake/LTO.cmake) # CMAKE_INTERPROCEDURAL_OPTIMIZATION
21+
include(cmake/MSVCGlobal.cmake) # /utf-8, /fsanitize=address (global)
2122
include(cmake/Dependencies.cmake) # googletest (conditional)
2223

2324
# ─────────────────────────────────────────────────────────────────────────────

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ The runtime VM implements the **doc 16 forward-secrecy extension**:
152152
153153
- [CMake](https://cmake.org/download/) 3.20+
154154
- C++17 compiler (GCC 14+, Clang 18+, MSVC 2022+, Apple Clang)
155-
- [Ninja](https://github.com/ninja-build/ninja) (recommended)
155+
- [Ninja](https://github.com/ninja-build/ninja) (required on Linux/macOS; not needed for Windows `*-win` presets)
156156
157157
### Third-party
158158
@@ -196,7 +196,7 @@ cmake --list-presets # show all available presets
196196
git submodule update --init --recursive
197197
198198
cmake --preset dev-win
199-
cmake --build --preset dev-win
199+
cmake --build --preset dev-win --parallel
200200
ctest --preset dev-win
201201
202202
# Other presets: release-win, ci-win

cmake/CompilerWarnings.cmake

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,27 @@ add_library(vmpilot_options INTERFACE)
77

88
target_compile_features(vmpilot_options INTERFACE cxx_std_17)
99

10+
# Guard MSVC flags with COMPILE_LANGUAGE:CXX so they are not passed to
11+
# MASM (ml64.exe), which does not understand /utf-8, /Od, /W4, etc.
1012
target_compile_options(vmpilot_options INTERFACE
1113
# Warnings
1214
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall -Wextra -Werror -pedantic>
13-
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX /utf-8>
15+
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<COMPILE_LANGUAGE:CXX>>:/W4 /WX /utf-8>
1416
# Colour diagnostics
1517
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
1618
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fcolor-diagnostics>
1719
# Debug
1820
$<$<AND:$<CONFIG:Debug>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:-g -fno-omit-frame-pointer -O0>
19-
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:MSVC>>:/Zi /Od>
21+
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:MSVC>,$<COMPILE_LANGUAGE:CXX>>:/Zi /Od>
2022
# Release
2123
$<$<AND:$<CONFIG:Release>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:-O3 -fdata-sections -ffunction-sections>
22-
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:MSVC>>:/O2 /Gy>
24+
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:MSVC>,$<COMPILE_LANGUAGE:CXX>>:/O2 /Gy>
2325
# MinSizeRel
2426
$<$<AND:$<CONFIG:MinSizeRel>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:-Os -fdata-sections -ffunction-sections>
25-
$<$<AND:$<CONFIG:MinSizeRel>,$<CXX_COMPILER_ID:MSVC>>:/O1 /Gy>
27+
$<$<AND:$<CONFIG:MinSizeRel>,$<CXX_COMPILER_ID:MSVC>,$<COMPILE_LANGUAGE:CXX>>:/O1 /Gy>
2628
# RelWithDebInfo
2729
$<$<AND:$<CONFIG:RelWithDebInfo>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:-O2 -g -fno-omit-frame-pointer>
28-
$<$<AND:$<CONFIG:RelWithDebInfo>,$<CXX_COMPILER_ID:MSVC>>:/O2 /Zi>
30+
$<$<AND:$<CONFIG:RelWithDebInfo>,$<CXX_COMPILER_ID:MSVC>,$<COMPILE_LANGUAGE:CXX>>:/O2 /Zi>
2931
)
3032

3133
target_compile_definitions(vmpilot_options INTERFACE

cmake/Dependencies.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ if (VMPILOT_ENABLE_TESTS)
5555
)
5656
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
5757
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
58+
# Note: MSVC ASan (/fsanitize=address) and /utf-8 are set globally in
59+
# the root CMakeLists.txt, so GoogleTest inherits them automatically.
5860
FetchContent_MakeAvailable(googletest)
5961
enable_testing()
6062
include(GoogleTest)

cmake/MSVCGlobal.cmake

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# cmake/MSVCGlobal.cmake — MSVC-wide flags applied to ALL targets
2+
#
3+
# These flags must be global (not per-target) so that every translation unit
4+
# shares the same encoding and sanitizer annotation metadata. A mismatch
5+
# between any two .obj files causes LNK2038 (annotate_string / annotate_vector)
6+
# or C4819 (codepage) errors.
7+
8+
if (NOT MSVC)
9+
return()
10+
endif()
11+
12+
# UTF-8 source encoding: avoids C4819 on non-English codepages (e.g. Big5/950).
13+
# Guarded with COMPILE_LANGUAGE so MASM (ml64.exe) is not affected.
14+
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/utf-8>)
15+
16+
# ASan must be consistent across every .obj that links together.
17+
# Setting it globally prevents annotate_string / annotate_vector mismatches (LNK2038).
18+
# /fsanitize=address is compile-only; the linker does not accept it.
19+
# Incremental linking is incompatible with ASan.
20+
if (VMPILOT_ENABLE_SANITIZERS)
21+
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/fsanitize=address>)
22+
add_link_options(/INCREMENTAL:NO)
23+
endif()
24+
25+
# TODO: fix the underlying alignment issues and remove these suppressions.
26+
# C4324: struct padded due to alignas (runtime VmExecution, VmOramState, PlatformCallDesc)
27+
# C4146: unary minus on unsigned type (runtime NEG handler, ORAM strategies)
28+
add_compile_options(
29+
$<$<COMPILE_LANGUAGE:C,CXX>:/wd4324>
30+
$<$<COMPILE_LANGUAGE:C,CXX>:/wd4146>
31+
)

cmake/Sanitizers.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ if (VMPILOT_ENABLE_SANITIZERS)
2222
-fsanitize=address,undefined)
2323
endif()
2424
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
25-
# MSVC supports ASan only (no UBsan)
26-
target_compile_options(vmpilot_sanitizer INTERFACE /fsanitize=address)
27-
target_link_options(vmpilot_sanitizer INTERFACE /fsanitize=address)
25+
# MSVC ASan compile flags (/fsanitize=address) and /INCREMENTAL:NO
26+
# are set globally in root CMakeLists.txt so that ALL targets
27+
# (including third-party) share the same annotation metadata.
28+
# This target is kept as a no-op on MSVC for interface compatibility.
2829
endif()
2930
endif()

common/crypto

sdk/src/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ string(REPLACE "/WX" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
1010
string(REPLACE "-Werror" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
1111
string(REPLACE "-Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
1212

13-
# Suppress all warnings from third-party code (abseil/protobuf)
13+
# Suppress all warnings from third-party code (abseil/protobuf).
14+
# On MSVC we only strip /WX (above) — adding /w would conflict with abseil's
15+
# /W3 and protobuf's /W1 target_compile_options, causing D9025 spam.
16+
# Both libraries are clean at their own warning levels so no extra noise appears.
1417
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
1518
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
1619
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
17-
elseif (MSVC)
18-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /w")
19-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w")
2020
endif()
2121

2222
# Abseil — pinned submodule (LTS 2026-01-07), built before protobuf

sdk/tests/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ add_compile_definitions(
2727
TEST_DATA_DATA_REFS="${CMAKE_SOURCE_DIR}/data/data_refs/bin"
2828
)
2929

30+
# Note: MSVC ASan is set globally in root CMakeLists.txt for consistency.
31+
# GCC/Clang sanitizers propagate from linked libraries (VMPilot_Common, etc.)
32+
# via vmpilot_sanitizer INTERFACE target.
33+
3034
# --- Test targets ---
3135

3236
add_executable(test_native_function_base test_native_function_base.cpp)

third_party/coffi-modern

0 commit comments

Comments
 (0)