mesonbuild / meson-python

Meson PEP 517 Python build backend
https://mesonbuild.com/meson-python/
MIT License
126 stars 65 forks source link

Explicitly setting a debug build also requires explicitly setting b_ndebug=false #441

Closed ngoldbaum closed 1 year ago

ngoldbaum commented 1 year ago

For whatever reason I need to have setup = ["-Dbuildtype=debug", "-Db_ndebug=false"] in my pyproject.toml, not just setup = ["-Dbuildtype=debug"].

I think what's happening is the default meson settings meson-python sets all need to be explicitly overriden. If I just pass -Dbuildtype=debug, the meson setup command meson-python creates is:

+ meson setup --reconfigure /home/nathan/Documents/numpy-user-dtypes/stringdtype /home/nathan/Documents/numpy-user-dtypes/stringdtype/build -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md -Dbuildtype=debug --native-file=/home/nathan/Documents/numpy-user-dtypes/stringdtype/build/meson-python-native-file.ini

So I guess meson-python's settings take precedence because they are explicitly set, but then my custom settings for the build type override that, but since I don't have a custom ndebug, the previously set if-release choice doesn't get reset.

Maybe meson-python could check if there is a user-provided buildtype and not set ndebug or buildtype if so?

dnicolodi commented 1 year ago

When reporting an issue it is desirable to explicitly state what you are trying to achieve, the solution you tried, how it did not work, preferably corroborated by some evidence. The description of this issue allows us only to guess what you are trying to do and why you thin it does not work as expected.

I guess you are trying to obtain a build with debug symbols and with assertions enabled. To achieve that you added

[tool.meson-python.args]
setup = ["-Dbuildtype=debug"]

However, in your opinion that is not sufficient in enabling assertions (ie compile without the -DNDEBUG compilation flag). Why do you think this is the case? The combination of -Dn_debug=if-release -Dbuildtype=debug should not result in the -DNDEBUG compilation flag being set.

ngoldbaum commented 1 year ago

Sorry if the initial description wasn’t clear. You’re right that I’d expect the combination of -Dn_debug=if-release and -Dbuildtype=debug to not set -DNDEBUG. However, I’m finding that not to be the case, I need to explicitly set -Dn_debug=false.

dnicolodi commented 1 year ago

How did you verify that? I just tested it and it works as expected, see #442

ngoldbaum commented 1 year ago

Hmm, I can't seem to reproduce what I was seeing yesterday in my project. Sorry for the noise! I'll try to write a failing test next time I report a bug.

dnicolodi commented 1 year ago

A complete test is not necessary, however providing a way to reproduce the issue would be nice.

rgommers commented 1 year ago

Glad this is working as expected after all 😅. Choosing defaults has turned out to be tricky enough already.