Skip to content

feat(toolchains): support debug runtimes on Linux and macOS - #4471

Merged
rickeylev merged 2 commits into
bazel-contrib:mainfrom
vadikmironov:feat/debug-runtime-unix-layout
Nov 11, 2026
Merged

rickeylev merged 2 commits into
bazel-contrib:mainfrom
vadikmironov:feat/debug-runtime-unix-layout

Conversation

@vadikmironov

@vadikmironov vadikmironov commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #4442.

python-build-standalone debug (Py_DEBUG) archives for Linux and macOS
add a d ABI flag to some names: include/python3.14d and
lib/libpython3.14d.so (.dylib on macOS), or td for free-threaded
debug builds. The runtime repo only knows the release names, so a debug
runtime registered with python.single_version_platform_override does
not work for C code: current_py_cc_headers fails with
Python.h: No such file or directory and current_py_cc_libs with
missing input file '...//:lib/libpython3.14.so'. On a macOS host, the
repo rule's install_name_tool step also looks for the release dylib.

To fix, the repo rule checks the extracted archive for the d include
dir and passes that to the runtime macro, which uses the d names. The
macro also sets abi_flags on py_runtime and py_cc_toolchain,
because <AUTO> only derives t. Extensions built against the debug
headers need a debug interpreter, so they get the debug SOABI (for
example cpython-314d-x86_64-linux-gnu) and wheel ABI tag (cp314d).

Windows debug archives use other names (python_d.exe,
python314_d.dll) and are not handled here. Will be addressed
separately.

  • Also registers a debug runtime for tests in MODULE.bazel and adds
    //tests/toolchains:debug_runtime_test, which builds an extension
    against it and imports it.

python-build-standalone debug (Py_DEBUG) archives add a "d" ABI flag to
the include dir and libpython names (include/python3.14d,
libpython3.14d.so), which the runtime repo did not know. The repo rule
now checks the extracted archive for the "d" include dir. The runtime
macro then uses the "d" names and sets abi_flags to "d" or "td".
Windows is unchanged.

Also registers a debug runtime for tests and adds
//tests/toolchains:debug_runtime_test.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vadikmironov

Copy link
Copy Markdown
Contributor Author

I prepared this with Claude Code. It wrote the change and the test, built against the python-build-standalone 3.14 debug and free-threaded debug archives on Linux x86_64, and ran the new test there. macOS is checked only against the archive layout (include/python3.14d, lib/libpython3.14d.dylib); the install_name_tool step has not been run. I reviewed it myself, and I'll answer review comments myself.

Comment thread MODULE.bazel
# NOTE: 3.14.10, the newest 3.14, would break //tests/toolchains:build_test.
dev_python.single_version_platform_override(
platform = "linux-x86-debug",
python_version = "3.14.4",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raised #4472 for this. 3.14.4 is the highest other than 3.14.10 in the runtimes manifest.

@aignas

aignas commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

What about adding an additional flag to the matching algorith so that if users would like to not use the or use them exclusively, they can do that?

Do these runtimes provide something that would be of interest to the users?

@rickeylev

Copy link
Copy Markdown
Collaborator

adding an additional flag

I'm +1 on being able to set a flag so that a debug runtime can be chosen, but lets defer that to another PR. There's like 3 different ways we could have it specified:

  • --compilation_mode=dbg (bazel builtin flag)
  • --py_pbs_distribution=debug (reuse our existing flag)
  • --py_debug=yes (new flag)

...but we can figure that out separately. This PR will at least make them usable.

Do these runtimes provide something that would be of interest to the users?

I think its mostly of interest to people writing C extensions, e.g. helping debug why an extension is misusing memory.

@rickeylev rickeylev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Github has been queueing jobs for hours, so no idea when this will actually end up in the merge queue.

@rickeylev
rickeylev added this pull request to the merge queue Nov 11, 2026
Merged via the queue into bazel-contrib:main with commit aa81a77 Nov 11, 2026
17 checks passed
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.

3 participants