Skip to content

Commit 1769366

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> (cherry picked from commit f795700)
1 parent ccc2c4d commit 1769366

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ include(BuildType)
4646
## Global settings
4747
if(NOT MSVC)
4848
add_compile_options(-Wall -Wextra)
49+
else()
50+
# MSVC's legacy preprocessor mis-handles the token-paste + rescan used
51+
# by IS_ENABLED() in utils/include/utils/utils.h, silently returning 0
52+
# for every defined-as-1 flag. /Zc:preprocessor switches to the
53+
# C99/C11-conformant preprocessor (VS 2019 16.5+).
54+
add_compile_options(/Zc:preprocessor)
4955
endif()
5056

5157
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
@@ -210,6 +211,12 @@ def try_vendor_sources(src_dir, src_files, vendor_dir):
210211
[ "-D" + define + "=1" for define in definitions ]
211212
)
212213

214+
# PyPI Windows wheels are built with MSVC via cibuildwheel. Its legacy
215+
# preprocessor breaks the IS_ENABLED() macro in utils/include/utils/utils.h;
216+
# /Zc:preprocessor switches to the C99/C11-conformant preprocessor.
217+
if sys.platform == "win32":
218+
compile_args.append("/Zc:preprocessor")
219+
213220
if os.path.exists("README.md"):
214221
with open("README.md", "r") as f:
215222
long_description = f.read()

0 commit comments

Comments
 (0)