@@ -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
0 commit comments