Skip to content

Commit 0447aff

Browse files
committed
DOC: add documentation for meson-args.rst
This is a draft for the (how to) meson-args documentation
1 parent 6d96b3e commit 0447aff

File tree

1 file changed

+112
-1
lines changed

1 file changed

+112
-1
lines changed

docs/how-to-guides/meson-args.rst

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
Passing arguments to Meson_
99
***************************
1010

11-
1211
.. todo::
1312

1413
- Explain how you can add extra Meson arguments via ``pyproject.toml``
@@ -17,5 +16,117 @@ Passing arguments to Meson_
1716
- Mention the order in which Meson arguments are added, and how it affect
1817
Meson
1918

19+
Advanced meson options can be accessed by specifying extra arguments to the individual meson commands:
20+
21+
- meson dist: https://mesonbuild.com/Commands.html#dist
22+
- meson setup: https://mesonbuild.com/Commands.html#setup
23+
- meson compile: https://mesonbuild.com/Commands.html#compile
24+
- meson install: https://mesonbuild.com/Commands.html#install
25+
26+
These arguments can be added to the project by adding the following section to the project's ``pyproject.toml``:
27+
28+
.. code-block::
29+
30+
[tool.meson-python.args]
31+
dist = ['dist-argument_1', 'dist-argument_2', '...']
32+
setup = ['setup-argument_1', 'setup-argument_2', '...']
33+
compile = ['compile-argument_1', 'compile-argument_2', '...']
34+
install = ['install-argument_1', 'install-argument_2', '...']
35+
36+
Alternatively they can be added when building the package using the :ref:`build config settings<how-to-guides-config-settings>`:
37+
38+
.. tab-set::
39+
40+
.. tab-item:: pypa/buid
41+
42+
.. code-block:: console
43+
44+
$ python -m build -Cdist-args="args" \
45+
-Csetup-args="args" \
46+
-Ccompile-args="args" \
47+
-Cinstall-args="args" .
48+
49+
.. tab-item:: pip
50+
51+
.. code-block:: console
52+
53+
$ python -m pip --config-settings=dist-args="args" \
54+
--config-settings=setup-args="args" \
55+
--config-settings=compile-args="args" \
56+
--config-settings=install-args="args" .
57+
58+
59+
Example 1: set the default libraries to *static*
60+
================================================
61+
62+
Set the target default libraries to "static"
63+
64+
.. tab-set::
65+
66+
.. tab-item:: pyproject.toml
67+
:sync: key1
68+
69+
.. code-block:: console
70+
71+
[tool.meson-python.args]
72+
dist = []
73+
setup = ['--default-library=static']
74+
compile = []
75+
install = []
76+
77+
.. tab-item:: pypa/build
78+
:sync: key2
79+
80+
.. code-block:: console
81+
82+
$ python -m build -Csetup-args="--default-library=static" .
83+
84+
.. tab-item:: pip
85+
:sync: key3
86+
87+
.. code-block:: console
88+
89+
$ python -m pip --config-settings=setup-args="--default-library=static" .
90+
91+
92+
Example 2: use meson install_tags for selective installs
93+
========================================================
94+
95+
Since ``meson-python`` >= 0.13 possible to use meson install_tags to select which targets are installed into the binary wheels.
96+
97+
.. admonition:: Meson installation tags
98+
:class: seealso
99+
100+
Each meson target has a default install_tag (e.g. ``runtime`` for shared libraries and ``devel`` for headers.). Using ``meson install --tags=tag1,tag2,...`` will cause meson to only install the targets tagged with any of the specified tags. The default tag of each target can be overwritten using the target's "install_tag" option. For more information refer mesons documentation in installation-tags: https://mesonbuild.com/Installing.html#installation-tags
101+
102+
This example causes meson-python to only install targets tagged with ``runtime`` or ``python-runtime``) into the binary wheel (ignoring e.g. C++ headers):
103+
104+
.. tab-set::
105+
106+
.. tab-item:: pyproject.toml
107+
:sync: key1
108+
109+
.. code-block:: console
110+
111+
[tool.meson-python.args]
112+
dist = []
113+
setup = []
114+
compile = []
115+
install = ['--tags=runtime,python-runtime']
116+
117+
.. tab-item:: pypa/build
118+
:sync: key2
119+
120+
.. code-block:: console
121+
122+
$ python -m build -install-args="--tags=runtime,python-runtime" .
123+
124+
.. tab-item:: pip
125+
:sync: key3
126+
127+
.. code-block:: console
128+
129+
$ python -m pip --config-settings=install-args="--tags=runtime,python-runtime" .
130+
20131

21132
.. _Meson: https://github.com/mesonbuild/meson

0 commit comments

Comments
 (0)