Skip to content

Commit 98d14a1

Browse files
committed
DOC: add details on default build options used by meson-python
This follows up on the `n_debug` default added in gh-325, documents all other default options and they are used, as well as improves the page on using `pyproject.toml` settings.
1 parent fb1761b commit 98d14a1

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

docs/explanations/default-options.rst

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
.. SPDX-FileCopyrightText: 2023 The meson-python developers
2+
..
3+
.. SPDX-License-Identifier: MIT
4+
5+
.. _explanations-default-options:
6+
7+
*********************
8+
Default build options
9+
*********************
10+
11+
Meson offers many `built-in options <https://mesonbuild.com/Builtin-options.html>`__,
12+
and in the vast majority of cases those have good defaults. There are a couple
13+
of cases however where ``meson-python`` either needs to or chooses to override
14+
those with its own defaults. To view what those are for the version of
15+
``meson-python`` you have installed, look at the *User defined options* section
16+
of the output during the configure stage of the build (e.g., by running
17+
``python -m build --wheel``). This will look something like:
18+
19+
.. code-block:: text
20+
21+
User defined options
22+
Native files : /home/username/code/project/.mesonpy-native-file.ini
23+
debug : false
24+
optimization : 2
25+
prefix : /home/username/mambaforge/envs/project-dev
26+
python.platlibdir: /home/username/mambaforge/envs/project-dev/lib/python3.10/site-packages
27+
python.purelibdir: /home/username/mambaforge/envs/project-dev/lib/python3.10/site-packages
28+
b_ndebug : if-release
29+
30+
Let's go through each option and why they are used:
31+
32+
- meson-python uses a native file, written to the build dir and named
33+
``mesonpy-native-file.ini``, in order to point Meson at the correct
34+
``python`` interpreter to use (the same one for which ``meson-python`` was
35+
installed). This is necessary, because Meson may otherwise look for the first
36+
Python interpreter on the PATH (usually the same one, but not always the
37+
case). Users may use ``--native-file`` to pass a second native file to Meson;
38+
Meson will merge contents of both native file, so as long as the
39+
user-provided file does not try to pass a different path for the ``python``
40+
binary, this will work without a conflict.
41+
- The ``prefix`` and ``platlibdir``/``purelibdir`` options also point Meson at
42+
that same interpreter and the environment in which it is installed.
43+
- The ``debug``, ``optimization`` and ``b_ndebug`` options are overridden,
44+
because Meson defaults to values that are appropriate for development, while
45+
the main purpose of meson-python is to build release artifacts.
46+
47+
It is possible to override these defaults, either permanently in your project
48+
or at build time. For example, to build a wheel with debug symbols, use:
49+
50+
.. code-block:: bash
51+
52+
$ python -m build -Csetup-args=-Ddebug=true
53+
54+
And to override all debug and optimization settings permanently, add this to
55+
your ``pyproject.toml`` file:
56+
57+
.. code-block:: toml
58+
59+
[tool.meson-python.args]
60+
setup = ['-Ddebug=true', '-Doptimization=0', '-Db_ndebug=false']
61+
62+
For more details on overriding build options at build time see
63+
:ref:`here <reference-config-settings>`, and in ``pyproject.toml`` see
64+
:ref:`here <reference-pyproject-settings>`.

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Contributors
135135
:hidden:
136136

137137
explanations/design
138+
explanations/default-options
138139
explanations/internal-dependencies
139140
explanations/editable-installs
140141

docs/reference/pyproject-settings.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,13 @@ This page lists the configuration settings supported by ``meson-python`` in the
3131

3232
* - ``tool.meson-python.args.install``
3333
- Extra arguments to be passed to the ``meson install`` command.
34+
35+
Usage example:
36+
37+
.. code-block:: toml
38+
39+
[tool.meson-python.args]
40+
setup = ['-Dwarning_level=2', '-Db_pie=true']
41+
dist = ['--include-subprojects']
42+
compile = ['-j4']
43+
install = ['--quiet']

0 commit comments

Comments
 (0)