Skip to content

Commit 4accafc

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 4accafc

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

docs/explanations/default-options.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 is forced 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, named ``.mesonpy-native-file.ini`` in order
33+
to point Meson at the correct ``python`` interpreter to use (the same one for
34+
which ``meson-python`` was installed). This is necessary, because Meson may
35+
otherwise look for the first Python interpreter on the PATH (usually the same
36+
one, but not always the case).
37+
- The ``prefix`` and ``platlibdir``/``purelibdir`` options also point Meson at
38+
that same interpreter and the environment in which it is installed.
39+
- The ``debug``, ``optimization`` and ``b_ndebug`` options are overridden,
40+
because Meson defaults to values that are appropriate for development, while
41+
the main purpose of meson-python is to build release artifacts.
42+
43+
It is possible to override these defaults, either permanently in your project
44+
or at build time. For example, to build a wheel with debug symbols, use:
45+
46+
.. code-block:: bash
47+
48+
$ python -m build -Csetup-args=-Ddebug=true
49+
50+
And to override all debug and optimization settings permanently, add this to
51+
your ``pyproject.toml`` file:
52+
53+
.. code-block:: toml
54+
55+
[tool.meson-python.args]
56+
setup = ['-Ddebug=true', '-Doptimization=0', '-Db_ndebug=false']
57+
dist = []
58+
compile = []
59+
install = []
60+
61+
For more details on overriding build options at build time see
62+
:ref:`here <reference-config-settings>`, and in ``pyproject.toml`` see
63+
: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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,19 @@ 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']
44+
45+
.. note::
46+
47+
At the moment it is necessary to specify all four arguments (``dist``,
48+
``setup```, ``compile`` and ``install``). This limitation will go away in a
49+
future version.

0 commit comments

Comments
 (0)