@@ -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,68 @@ 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. The ``build-dir `` :ref: `config
69+ setting <reference-config-settings>` can be used to build in a
70+ user-specified build directory which will not be deleted. 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+ After running this command, the ``build `` directory will contain all
89+ the build artifacts and support files created by ``meson ``, ``ninja ``
90+ and ``meson-python ``. The same build directory can be used by
91+ subsequent invocations of ``meson-python ``, avoiding the need to
92+ rebuild the whole project when testing changes during development.
93+
94+ Using a permanent build directory also aids in debugging a failing
95+ build by allowing access to build logs and intermediate build outputs,
96+ including the Meson introspection files and detailed log. The latter
97+ is stored in the ``meson-logs/meson-log.txt `` file in the build
98+ directory and can be useful to diagnose why a build fails at the
99+ project configuration stage. For example, to understand why dependency
100+ detection failed, it is often necessary to look at the ``pkg-config ``
101+ or other dependency detection methods output.
102+
103+ Access to detailed logs and intermediate build outputs is particularly
104+ helpful in CI setups where introspecting the build environment is
105+ usually more difficult than on a local system. Therefore, it can be
106+ useful to show the more detailed log files when the CI build step
107+ fails. For example, the following GitHub Actions workflow file snippet
108+ shows the detailed Meson setup log when the build fails:
109+
110+ .. code-block :: yaml
111+
112+ - name : Build the package
113+ run : python -m build --wheel -Cbuild-dir=build
114+ - name : Show meson-log.txt
115+ if : failure()
116+ run : cat build/meson-logs/meson-log.txt
117+
118+ Replacing ``failure() `` with ``always() `` in the code above will
119+ result in the Meson log file always being shown. See the GitHub
120+ Actions documentation __ for more details. Please be aware that the
121+ setup log can become very long for complex projects and the GitHub
122+ Actions web interface becomes unresponsive when the running job emits
123+ many output lines.
124+
125+
126+ __ https://docs.github.com/en/actions/learn-github-actions/expressions#status-check-functions
0 commit comments