@@ -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,70 @@ 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 `` uses a temporary build directory which is
68+ deleted when the build terminates. A persistent build directory allows
69+ faster incremental builds and to access build logs and intermediate
70+ build artifacts. The ``build-dir `` :ref: `config setting
71+ <reference-config-settings>` instructs ``meson-python `` to use a
72+ user-specified build directory which will not be deleted. For example:
73+
74+ .. tab-set ::
75+
76+ .. tab-item :: pypa/build
77+ :sync: key_pypa_build
78+
79+ .. code-block :: console
80+
81+ $ python -m build -Cbuild-dir=build
82+
83+ .. tab-item :: pip
84+ :sync: key_pip
85+
86+ .. code-block :: console
87+
88+ $ python -m pip install . -Cbuild-dir=build
89+
90+ After running this command, the ``build `` directory will contain all
91+ the build artifacts and support files created by ``meson ``, ``ninja ``
92+ and ``meson-python ``. The same build directory can be used by
93+ subsequent invocations of ``meson-python ``, avoiding the need to
94+ rebuild the whole project when testing changes during development.
95+
96+ Using a permanent build directory also aids in debugging a failing
97+ build by allowing access to build logs and intermediate build outputs,
98+ including the Meson introspection files and detailed log. The latter
99+ is stored in the ``meson-logs/meson-log.txt `` file in the build
100+ directory and can be useful to diagnose why a build fails at the
101+ project configuration stage. For example, to understand why dependency
102+ detection failed, it is often necessary to look at the ``pkg-config ``
103+ or other dependency detection methods output.
104+
105+ Access to detailed logs and intermediate build outputs is particularly
106+ helpful in CI setups where introspecting the build environment is
107+ usually more difficult than on a local system. Therefore, it can be
108+ useful to show the more detailed log files when the CI build step
109+ fails. For example, the following GitHub Actions workflow file snippet
110+ shows the detailed Meson setup log when the build fails:
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()
118+ run : cat build/meson-logs/meson-log.txt
119+
120+ Replacing ``failure() `` with ``always() `` in the code above will
121+ result in the Meson log file always being shown. See the GitHub
122+ Actions documentation __ for more details. Please be aware that the
123+ setup log can become very long for complex projects, and the GitHub
124+ Actions web interface becomes unresponsive when the running job emits
125+ many output lines.
126+
127+
128+ __ https://docs.github.com/en/actions/learn-github-actions/expressions#status-check-functions
0 commit comments