8000 DOC: add docs on using the `build-dir` config setting · mesonbuild/meson-python@ce88c51 · GitHub
[go: up one dir, main page]

Skip to content

Commit ce88c51

Browse files
committed
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 24927ec commit ce88c51

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

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

Lines changed: 61 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,63 @@ 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`` will create a temporary build directory, which
68+
gets cleaned up after the sdist or wheel has been built, or if the build fails.
69+
The ``build-dir`` config seting (see :ref:`reference-config-settings`) can be
70+
used to build in a user-specified build directory 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 output created by
90+
``meson``, ``ninja`` and ``meson-python``. This may be useful for a couple of
91+
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. The one thing to keep in mind is that changing
100+
the version of ``meson`` or ``meson-python`` in the build environment between
101+
separate builds in the same build directory is not supported (it often works,
102+
but may fail - and the error message cannot be guaranteed to be clear about the
103+
reason).
104+
105+
Using ``build-dir`` makes it possible to access the log files that Meson
106+
creates. When a build fails, Meson's CLI logging will display the reason for
107+
the failure in most cases. However, it is sometimes necessary to look at more
108+
detailed logs like ``meson-logs/meson-log.txt``. A common reason for this is
109+
when Meson's dependency detection fails: it is often necessary to look at the
110+
detailed output of ``pkg-config`` or other dependency detection methods to
111+
understand why the detection failed. This is particularly common in CI setups -
112+
it can be helpful to show more detailed log files when the build step of a CI
113+
build fails, for example in a GitHub Actions workflow file:
114+
115+
.. code-block:: yaml
116+
117+
- name: Build the package
118+
run: python -m build --wheel -Cbuild-dir=build
119+
- name: Show meson-log.txt
120+
if: failure() # or `always()`, if output is not too long
121+
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)
0