Skip to content

Add debug support for MSVC builds - patch 1 - #1263

Open
vadikmironov wants to merge 1 commit into
astral-sh:mainfrom
vadikmironov:windows-debug-option-build-py
Open

Add debug support for MSVC builds - patch 1#1263
vadikmironov wants to merge 1 commit into
astral-sh:mainfrom
vadikmironov:windows-debug-option-build-py

Conversation

@vadikmironov

@vadikmironov vadikmironov commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

This change is a part of set of changes addressing #26. This is exactly the same change as the first commit in #1262. It is raised separately for the ease of reviewing by maintainers while #1262 is to give an overview of the full set of patches (can be deleted once individual commits are merged).

What changes in cpython-windows/build.py:

  • debug is added to the option set beside noopt and pgo, with the same ordering as Unix build already uses. Same as with Unix, this removes illegal combinations like debug+pgo. The set is renamed from optimizations to options also inline with the Unix build.
  • configuration="Debug" is passed to msbuild and artifact_config accordingly. PC/layout gets --debug and that drives the _d artifact suffixes.
  • executables, extension modules and dependency libraries pick up the _d suffix $(PyDebugExt) produces
  • the tail-calling interpreter is not enabled for Debug (comments embedded in the patch)
  • docs/building.rst updated with the debug option and the debug CRT requirement

Evidence: every debug configuration was built with this commit as the base, validated and tested. 26 jobs across 3.10 to 3.15 on x64, x86 and arm64, VS 2022 and VS 2026: https://github.com/vadikmironov/omniglot-bazel-starter/actions/runs/34095975591. The details, the archive layout and the other findings are in #1262.

cpython-unix/build.py offers `debug` alongside noopt and pgo, and every
Unix target declares it in ci-targets.yaml. Windows accepts only
noopt/pgo and hardcodes configuration="Release", so there is no way to
produce a debug interpreter.

That matters for embedding. MSVC's pyconfig.h selects the import library
from _DEBUG, which the debug CRT defines, so a consumer building with
/MDd asks for python3XX_d.lib and cannot link against a release
distribution.

Follows the Unix spelling: `debug` is a peer of noopt and pgo in the
option set, so debug+pgo is simply not a valid combination. The set is
renamed to `options` to match, since debug is not an optimization.

The rest is naming. A Debug configuration suffixes its artifacts with
$(PyDebugExt), so PC/layout is passed --debug, and the executables,
extension libraries and dependency libraries pick up the _d suffix.

The tail-calling interpreter is disabled for Debug. PBS turns it on for
3.15 on x64, but [[msvc::musttail]] requires /O2 and under /Od MSVC
reports C4737 for each dispatch site. CPython's early check for this was
reverted and the build still fails as of September 2026.

  https://learn.microsoft.com/en-us/cpp/cpp/attributes#msvcmusttail
  python/cpython#148047

building.rst documents the option and the debug CRT requirement: the
binaries import ucrtbased.dll and vcruntime*d.dll, which ship with
Visual Studio and are not redistributable.
@vadikmironov
vadikmironov marked this pull request as ready for review September 12, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant