Skip to content

Commit f795700

Browse files
committed
Enable MSVC's conformwat /Zc:preprocessor
Enable MSVC's conformant preprocessor (/Zc:preprocessor, available since VS 2019 16.5) in both CMake and the setuptools extension, and lock the behaviour in with a build-time _Static_assert self-test so any future regression (new compiler, new build system, accidental flag removal) fails the build immediately on every platform — including the MSVC CI lane. Related-to: #289 Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
1 parent 7f4eea5 commit f795700

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ include(BuildType)
5151
## Global settings
5252
if(NOT MSVC)
5353
add_compile_options(-Wall -Wextra)
54+
else()
55+
# MSVC's legacy preprocessor mis-handles the token-paste + rescan used
56+
# by IS_ENABLED() in utils/include/utils/utils.h, silently returning 0
57+
# for every defined-as-1 flag. /Zc:preprocessor switches to the
58+
# C99/C11-conformant preprocessor (VS 2019 16.5+).
59+
add_compile_options(/Zc:preprocessor)
5460
endif()
5561

5662
if (OPT_BUILD_BARE_METAL)

python/setup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import os
88
import re
9+
import sys
910
from setuptools import setup, Extension
1011
import shutil
1112
import subprocess
@@ -205,6 +206,12 @@ def try_vendor_sources(src_dir, src_files, vendor_dir):
205206
[ "-D" + define + "=1" for define in definitions ]
206207
)
207208

209+
# PyPI Windows wheels are built with MSVC via cibuildwheel. Its legacy
210+
# preprocessor breaks the IS_ENABLED() macro in utils/include/utils/utils.h;
211+
# /Zc:preprocessor switches to the C99/C11-conformant preprocessor.
212+
if sys.platform == "win32":
213+
compile_args.append("/Zc:preprocessor")
214+
208215
if os.path.exists("README.md"):
209216
with open("README.md", "r") as f:
210217
long_description = f.read()

utils

Submodule utils updated 1 file

0 commit comments

Comments
 (0)