Skip to content

Commit 2d805ec

Browse files
rgommershenryiii
authored andcommitted
DOC: add docs on using the build-dir config setting
Closes gh-540 Also touches on gh-246, which is a common enough hiccup that it's useful to explicitly show dealing with `meson-log.txt` in CI.
1 parent adfe8cd commit 2d805ec

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

docs/how-to-guides/config-settings.rst

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ the ``-C`` short command line option:
1919

2020
.. tab-set::
2121

22-
.. tab-item:: pypa/buid
22+
.. tab-item:: pypa/build
2323
:sync: key_pypa_build
2424

2525
.. code-block:: console
@@ -59,3 +59,60 @@ immediately install it, replace ``wheel`` with ``install``. See the
5959

6060
.. _build: https://pypa-build.readthedocs.io/en/stable/
6161
.. _pip: https://pip.pypa.io/
62+
63+
64+
Using a persistent build directory
65+
==================================
66+
67+
By default, ``meson-python`` creates a temporary build directory, which is
68+
deleted when the build terminates. The ``build-dir``
69+
:ref:`config setting <reference-config-settings>` can be used to build in a
70+
user-specified build directory which will not be deleted instead. For example:
71+
72+
.. tab-set::
73+
74+
.. tab-item:: pypa/build
75+
:sync: key_pypa_build
76+
77+
.. code-block:: console
78+
79+
$ python -m build -Cbuild-dir=build
80+
81+
.. tab-item:: pip
82+
:sync: key_pip
83+
84+
.. code-block:: console
85+
86+
$ python -m pip install . -Cbuild-dir=build
87+
88+
89+
The ``build`` directory will now contain all the build artifacts and support
90+
files created by ``meson``, ``ninja`` and ``meson-python``. This may be useful
91+
for a couple of reasons:
92+
93+
- For development efficiency (incremental builds)
94+
- For accessing build logs and intermediate build outputs when debugging
95+
96+
The same build directory can be used by subsequent invocations of
97+
``meson-python``. This avoids having to rebuild the whole project when testing
98+
changes during development. This will work with any config settings flags,
99+
including for cross compilation.
100+
101+
Using ``build-dir`` makes it possible to access Meson's log and introspection
102+
files. To diagnose why a build fails at the project configuration stage, it is
103+
sometimes necessary to inspect the detailed Meson log in the
104+
``meson-logs/meson-log.txt`` file in the build directory. The complete path to
105+
the log file is available in the command output when the build fails. For
106+
example, when dependency detection fails it is often necessary to look
107+
at the detailed output of ``pkg-config`` or other dependency detection methods
108+
to understand why the detection failed. This is particularly common in CI
109+
setups - it can be helpful to show more detailed log files when the build step
110+
of a CI build fails, for example in a GitHub Actions workflow file:
111+
112+
.. code-block:: yaml
113+
114+
- name: Build the package
115+
run: python -m build --wheel -Cbuild-dir=build
116+
- name: Show meson-log.txt
117+
if: failure() # or `always()`, if output is not too long
118+
run: cat build/meson-logs/meson-log.txt

docs/reference/config-settings.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ them.
2323
exists and contains a valid Meson build directory setup, the
2424
project will be reconfigured using ``meson setup --reconfigure``.
2525

26-
The same build directory can be used by subsequent invocations of
27-
``meson-python``. This avoids having to rebuild the whole project
28-
when testing changes during development.
29-
3026
For backward compatibility reasons, the alternative ``builddir``
3127
spelling is also accepted.
3228

0 commit comments

Comments
 (0)