Add debug support for MSVC builds - patch 1 - #1263
Open
vadikmironov wants to merge 1 commit into
Open
Conversation
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
marked this pull request as ready for review
September 12, 2026 09:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:debugis added to the option set besidenooptandpgo, with the same ordering as Unix build already uses. Same as with Unix, this removes illegal combinations likedebug+pgo. The set is renamed fromoptimizationstooptionsalso inline with the Unix build.configuration="Debug"is passed to msbuild andartifact_configaccordingly.PC/layoutgets--debugand that drives the_dartifact suffixes._dsuffix$(PyDebugExt)producesdocs/building.rstupdated with the debug option and the debug CRT requirementEvidence: 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.