Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building with a debug python build should generate a debug build #207

Closed
ngoldbaum opened this issue Nov 14, 2022 · 7 comments · Fixed by #466
Closed

Building with a debug python build should generate a debug build #207

ngoldbaum opened this issue Nov 14, 2022 · 7 comments · Fixed by #466
Labels
documentation Improvements or additions to documentation

Comments

@ngoldbaum
Copy link

Currently meson-python will generate the same wheel for a debug python build and a regular python build. I think this violates the principle of least surprise, since if one is using a debug python build I think one expects the C extensions to also be debug builds. This is what setuptools currently does.

I'm working around this by manually passing compiler flags to the meson build for my C extension when I need a debug build.

gh-154 would enable setting flags from the command line, so I wouldn't need to edit meson.build, however I think it's still worth having better default behavior for debug builds.

@lithomas1
Copy link
Member

Hmmm. I think I would lean more towards keeping the default as a release build, with a command line option to toggle.

Wheels are meant to be distributed, and having debug symbols makes it quite a bit bigger. I think users would also expect to have optimized code within a wheel.

@lithomas1 lithomas1 added the enhancement New feature or request label Nov 16, 2022
@FFY00
Copy link
Member

FFY00 commented Nov 16, 2022

I think the proposal here is that the Python interpreter itself is a debug build, meson-python should default to a debug build in Meson, and if the interpreter is a release build, default to a release build.

The proposed default behavior seems a bit surprising to me, I don't think I would expect it, and I generally treat debug interpreters and building extensions with debug arguments as different things that'd I would change independently. However, I don't maintain a lot of Python extensions, so I can't really tell if these are normal expectations. Perhaps @rgommers could provide some better feedback.

@rgommers
Copy link
Contributor

The proposal makes sense to me. The only reason I'd want a debug build of Python is to do some actual debugging - at which point you do want debug builds of everything else as well (may be necessary, can't really hurt). Some Linux distros even distribute packages like that, e.g. Ubuntu 18.04 has python-dbg and then matching packages like python-numpy-dbg, python-scipy-dbg. I'd also say that a debug Python build is nothing special here (or, Python as a package is nothing special, only the limitations of PyPI make it different) - it's just another package.

As for the details:

  • I wouldn't use c_args: ['-g', '-O0'], like @ngoldbaum does, I'd just add -Ddebug-true. The -g is a GCC-specific way of writing -Ddebug=true. And I would not touch optimization settings; a typical default for Meson is debugoptimized.
  • I don't know without looking in more detail how to tell whether a Python install is a debug build. And there's corner cases like the user passing in a cross file that need a simple answer/implementation.

@ngoldbaum
Copy link
Author

ngoldbaum commented Nov 16, 2022

My understanding is that setuptools will use sysconfig to get the compiler flags used to build python itself and reuses those flags when building C extensions. This behavior is probably what most python developers would expect since setuptools was ubiquitous until recently. I'm not saying that meson-python should necessarily do that (since it makes using a different compiler than whatever was used to build Python painful, among other issues), just that is what most people who work on C extensions would expect.

Until Python 3.8 the debug build of Python had a different ABI than the regular build, meaning that all packages had to be rebuilt for the debug build and wheels wouldn't work unless explicitly built as debug builds, so it's relatively common to expect to rebuild an entire dependency tree with debug support. Since Python 3.8 that's no longer the case, but I think it still impacts expectations for how things "should" work.

There's also a debug platform tag for wheels (e.g. cp310-cp310d-linux_x86_64 for debug versus cp310-cp310-linux_x86_64 for a regular build). Just because you've built a wheel doesn't necessarily mean it's stripped and optimized. While I agree that the main purpose of wheels is distribution, I don't think there's a way to use meson-python without ultimately generating a wheel that will be installed, even when working locally on some development task. That's why meson-python should consider that use-case too, or at least try to make it more streamlined (e.g. gh-154, gh-47).

@rgommers
Copy link
Contributor

Very useful context, thanks @ngoldbaum. Taking over other compiler flags we definitely don't want to do - as you point out it makes using a different compiler different. But the debug flag is a bit of a special case.

There's also a debug platform tag for wheels (e.g. cp310-cp310d-linux_x86_64 for debug versus cp310-cp310-linux_x86_64 for a regular build).

Is that actually used? It does make sense to me to support it, because a local debug build may otherwise pollute Pip's cache and be preferred the next time you want a regular install.

@ngoldbaum
Copy link
Author

Is that actually used?

Yup, in fact meson-python (or perhaps build?) currently generates a wheel for my project with the debug ABI tag when I build my project with a debug python.

It's also mentioned in PEP 425.

I don't know whether anyone is shipping debug wheels on pypi.

@rgommers
Copy link
Contributor

Yup, in fact meson-python (or perhaps build?) currently generates a wheel for my project with the debug ABI tag when I build my project with a debug python.

Ah, then it's also arguably a bug that there isn't any debug info inside:)

@rgommers rgommers added documentation Improvements or additions to documentation and removed enhancement New feature or request labels Sep 1, 2023
rgommers added a commit to rgommers/meson-python that referenced this issue Sep 1, 2023
Closes mesonbuildgh-461
Closes mesonbuildgh-207
Also xref mesonbuildgh-459 and mesonbuildgh-441 which are already closed but contain
discussion relevant to debug builds.
rgommers added a commit to rgommers/meson-python that referenced this issue Sep 2, 2023
Closes mesonbuildgh-461
Closes mesonbuildgh-207
Also xref mesonbuildgh-459 and mesonbuildgh-441 which are already closed but contain
discussion relevant to debug builds.
dnicolodi pushed a commit that referenced this issue Sep 2, 2023
Closes gh-461
Closes gh-207
Also xref gh-459 and gh-441 which are already closed but contain
discussion relevant to debug builds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants