Skip to content

Commit ed82060

Browse files
rgommersdnicolodi
authored andcommitted
DOC: add a howto page on debug builds
Closes gh-461 Closes gh-207 Also xref gh-459 and gh-441 which are already closed but contain discussion relevant to debug builds.
1 parent c9ae586 commit ed82060

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

docs/how-to-guides/debug-builds.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.. SPDX-FileCopyrightText: 2023 The meson-python developers
2+
..
3+
.. SPDX-License-Identifier: MIT
4+
5+
.. _how-to-guides-debug-builds:
6+
7+
******************
8+
Using debug builds
9+
******************
10+
11+
For development work on native code in your Python package, you may want to use
12+
a debug build. To do so, we need to use the ``buildtype`` option, which is
13+
equivalent to ``-Ddebug=true -Doptimization=0``, to ``meson setup``. In addition,
14+
it is likely most useful to set up an editable build with a fixed build
15+
directory. That way, the shared libraries in the installed debug build will
16+
contain correct paths, rather than paths pointing to a temporary build
17+
directory which ``meson-python`` will otherwise use. IDEs and other tools will
18+
then be able to show correct file locations and line numbers during debugging.
19+
20+
We can do all that with the following ``pip`` invocation:
21+
22+
.. code-block:: console
23+
24+
$ pip install -e . --no-build-isolation -Csetup-args=-Dbuildtype=debug -Cbuilddir=build-dbg
25+
26+
This debug build of your package will work with either a regular or debug build
27+
of your Python interpreter. A debug Python interpreter isn't necessary, but may
28+
be useful. It can be built from source, or you may be able to get it from your
29+
package manager of choice (typically under a package name like ``python-dbg``).
30+
Note that using a debug Python interpreter does not yield a debug build of your
31+
own package - you must use ``-Dbuildtype=debug`` or an equivalent flag for that.
32+
33+
.. warning::
34+
35+
Inside a Conda environment, environment variables like ``CFLAGS`` and
36+
``CXXFLAGS`` are usually set when the environment is activated. These
37+
environment variables contain optimization flags like ``-O2``, which will
38+
override the optimization level implied by ``-Dbuildtype=debug``. In order
39+
to avoid this, unset these variables:
40+
41+
.. code-block:: console
42+
43+
$ unset CFLAGS
44+
$ unset CXXFLAGS
45+
46+
Finally, note changing the buildtype from its default value of ``release`` to
47+
``debug`` will also cause ``meson-python`` to enable (or better, not disable)
48+
assertions by not defining the ``NDEBUG`` macro (see ``b_ndebug`` under
49+
:ref:`explanations-default-options`).

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ for quick questions - one ``meson-python`` maintainer is active there.
7777
how-to-guides/editable-installs
7878
how-to-guides/config-settings
7979
how-to-guides/meson-args
80+
how-to-guides/debug-builds
8081
projects-using-meson-python
8182

8283
.. how-to-guides/build-directory

0 commit comments

Comments
 (0)