|
| 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>`. |
0 commit comments