From 85ed2d76c27e98d1ec965d1e497fc1f78bb506a4 Mon Sep 17 00:00:00 2001 From: Morgan Funtowicz Date: Thu, 23 Oct 2025 10:15:29 +0200 Subject: [PATCH] fix(windows): always define _WIN32 preprocessor macro to prevent PyTorch compiling unsupported code --- build2cmake/src/templates/cuda/preamble.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build2cmake/src/templates/cuda/preamble.cmake b/build2cmake/src/templates/cuda/preamble.cmake index 077ce09b..d21d85f3 100644 --- a/build2cmake/src/templates/cuda/preamble.cmake +++ b/build2cmake/src/templates/cuda/preamble.cmake @@ -104,6 +104,11 @@ message(STATUS "Rendered for platform {{ platform }}") {% if platform == 'windows' %} include(${CMAKE_CURRENT_LIST_DIR}/cmake/windows.cmake) +# This preprocessor macro should be defined in building with MSVC but not for CUDA and co. +# Also, if not using MVSC, this may not be set too ... +# So we explicitly set it to avoid any side effect due to preprocessor-guards not being defined. +add_compile_definitions(_WIN32>) + # Generate standardized build name run_python(TORCH_VERSION "import torch; print(torch.__version__.split('+')[0])" "Failed to get Torch version") run_python(CXX11_ABI_VALUE "import torch; print('TRUE' if torch._C._GLIBCXX_USE_CXX11_ABI else 'FALSE')" "Failed to get CXX11 ABI")