Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.

Commit 1bed908

Browse files
authored
fix(windows): always define _WIN32 preprocessor macro to prevent PyTorch compiling unsupported code (#275)
PyTorch (especially dynamo) relies on the preprocessor macro `_WIN32` to guard compilation of code sections in some places when targetting Windows. This macro is defined by MSVC defacto but, NVCC and others are not setting it by default which can lead to compilation errors. This PR ensures the macro is defined when targetting Windows platform so we can safely rely its availability for the preprocessor.
1 parent 106bb77 commit 1bed908

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

build2cmake/src/templates/cuda/preamble.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ message(STATUS "Rendered for platform {{ platform }}")
104104
{% if platform == 'windows' %}
105105
include(${CMAKE_CURRENT_LIST_DIR}/cmake/windows.cmake)
106106

107+
# This preprocessor macro should be defined in building with MSVC but not for CUDA and co.
108+
# Also, if not using MVSC, this may not be set too ...
109+
# So we explicitly set it to avoid any side effect due to preprocessor-guards not being defined.
110+
add_compile_definitions(_WIN32>)
111+
107112
# Generate standardized build name
108113
run_python(TORCH_VERSION "import torch; print(torch.__version__.split('+')[0])" "Failed to get Torch version")
109114
run_python(CXX11_ABI_VALUE "import torch; print('TRUE' if torch._C._GLIBCXX_USE_CXX11_ABI else 'FALSE')" "Failed to get CXX11 ABI")

0 commit comments

Comments
 (0)