Build Windows debug extensions without debug Python
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Feature or enhancement
Proposal:
Summary of a problem
On Windows when users are building a debug version of anything, including Python extensions, they typically provide /MDd/MTd flag to link against the debug version of the C runtime library.
Which automatically sets _DEBUG, which, historically, sets Py_DEBUG macro.
Py_DEBUG macro makes it impossible to link against release version of Python library:
-
because of implicit linking against
_d.libby# pragma comment(lib,"python315_d.lib").
This restriction was overcomed in Python 3.14 by introduction ofPy_NO_LINK_LIBmacro. -
Py_DEBUGalso automatically setsPy_REF_DEBUG, which in turn enables additional symbols (namelyPy_NegativeRefcount,Py_INCREF_IncRefTotal,Py_DECREF_DecRefTotal), which of course are not present in Release library, so linking Debug build against it is still impossible.
But if we disablePy_REF_DEBUGwhenPy_DEBUGis set, then linking succeeds, so there are no more obstacles
to build debug extensions against release Python.
Typically, users don't want to use debug Python for their extensions, they just want debug version of their own extension, as debug Python binaries are not widely available and even if they are, after build user now would also need debug versions of the entire extensions ecosystem they were using.
So it would be great to provide an option to finally figure this out after all those years.
Changes
There are two approaches to consider (PR currently implements both of them just to showcase the options, but we need to pick one):
-
Py_NO_PY_REF_DEBUG- macro to avoid settingPy_REF_DEBUGbased onPy_DEBUG.
It's a minimal change change to overcome the current problem.
It seems currently there are no implications when setPy_DEBUGwould conflict with unsetPy_REF_DEBUG, but Python developers will need to keep it in mind in future thatPy_REF_DEBUGmight be unset even in debug builds. -
Py_WIN_NO_PY_DEBUG- that would make_DEBUGnot implyPy_DEBUG.
Honestly, I would prefer this option, as it seems to be a fix for the root cause of the problem and makes flags more consistent between Windows and other platforms - makingPy_DEBUGdeliberate choice on both Windows and Unix systems.
_DEBUGimplyingPy_DEBUGseems to be mostly historical thing introduced awhile ago (https://github.com/python/cpython/commit/9f9fa6d0c937a2cbc51feb3c92212688b09235f0) and they're not closely related.
AddingPy_WIN_NO_PY_DEBUGalso opens an opportunity in the future to completely deprecate_DEBUGsettingPy_DEBUG.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/building-debug-version-of-extensions-on-windows-without-debug-binaries
Linked PRs
- gh-142761
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với PR gh-142761 được liên kết và cuộc thảo luận trên Discourse, sau đó lần theo các entry point Py_DEBUG, Py_REF_DEBUG, Py_NO_LINK_LIB, Py_NO_PY_REF_DEBUG và Py_WIN_NO_PY_DEBUG được mô tả ở đây. Được xem là hoàn tất khi đã chọn một phương pháp macro được đề xuất và xác thực rằng các extension debug trên Windows có thể liên kết với Python release mà không yêu cầu các symbol chỉ dành cho debug.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- c, python
- Lĩnh vực
- build-system
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100