Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: add details on default build options used by meson-python #338

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions docs/explanations/default-options.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.. SPDX-FileCopyrightText: 2023 The meson-python developers
..
.. SPDX-License-Identifier: MIT
.. _explanations-default-options:

*********************
Default build options
*********************

Meson offers many `built-in options <https://mesonbuild.com/Builtin-options.html>`__,
and in the vast majority of cases those have good defaults. There are a couple
of cases however where ``meson-python`` either needs to or chooses to override
those with its own defaults. To view what those are for the version of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible improvement:

We could split the paragraph here and also document why we might choose to override the defaults. I wrote about the reasoning in #325 (comment).

We could also note that the options we do need to set are mostly for build/installation details that should not be relevant to the user. The only exception is the native file, but the user should be able to override the parts of it that make sense (IIRC everything but the Python interpreter).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep meson install I would much prefer if we would get rid of the --prefix and --python.{plat,pure}lib options and use the $DESTDIR environment variable pointing to somewhere in /tmp instead. This would have the additional benefit of putting the installation directory on tmpfs, with possible significant speedups when building large wheels.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and also document why we might choose to override the defaults.

This I already have in a fair amount of detail.

We could also note that the options we do need to set are mostly for build/installation details that should not be relevant to the user.

I'll see if I should add a few more words of clarification, but thought it was pretty clear already.

If we keep meson install I would much prefer if we would get rid of the --prefix and --python.{plat,pure}lib options and use the $DESTDIR environment variable pointing to somewhere in /tmp instead.

That sounds potentially useful. Let's cross that bridge when we get to it I'd say; this PR adds docs for the current state of things, and if/when we add $DESTDIR they can be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could split the paragraph here and also document why we might choose to override the defaults. I wrote about the reasoning in #325 (comment).

I checked it in more detail, and it's effectively the same as what I already have in this PR: "because Meson defaults to values that are appropriate for development, while the main purpose of meson-python is to build release artifacts."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep meson install I would much prefer if we would get rid of the --prefix and --python.{plat,pure}lib options and use the $DESTDIR environment variable pointing to somewhere in /tmp instead.

I don't think this is even a question, is it 🤣? Those options and DESTDIR serve two different purposes. We only set those options for the heuristics, so they can be removed now.

Regarding DESTDIR, we already set it to a subdirectory of working_dir, which currently when using the PEP 517 hooks is always set by tempfile.TemporaryDirectory (in with_temp_working_dir), so isn't that true already?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The working dir is created inside the project directory, thus it is on the same filesystem as the project sources.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you're right 😅. IIRC I did that to make things work properly for packagers by default, where access to /tmp might be a bit tricky. We can consider changing the default, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this comment thread open, because it seems like useful info. It doesn't apply to this PR directly though; it's discussion of a potential future design change. If that materializes, the docs can simply be updated.

``meson-python`` you have installed, look at the *User defined options* section
of the output during the configure stage of the build (e.g., by running
``python -m build --wheel``). This will look something like:

.. code-block:: text
User defined options
Native files : /home/username/code/project/.mesonpy-native-file.ini
debug : false
optimization : 2
prefix : /home/username/mambaforge/envs/project-dev
python.platlibdir: /home/username/mambaforge/envs/project-dev/lib/python3.10/site-packages
python.purelibdir: /home/username/mambaforge/envs/project-dev/lib/python3.10/site-packages
b_ndebug : if-release
Let's go through each option and why they are used:

- meson-python uses a native file, written to the build dir and named
``mesonpy-native-file.ini``, in order to point Meson at the correct
``python`` interpreter to use (the same one for which ``meson-python`` was
installed). This is necessary, because Meson may otherwise look for the first
Python interpreter on the PATH (usually the same one, but not always the
case). Users may use ``--native-file`` to pass a second native file to Meson;
Meson will merge contents of both native file, so as long as the
user-provided file does not try to pass a different path for the ``python``
binary, this will work without a conflict.
- The ``prefix`` and ``platlibdir``/``purelibdir`` options also point Meson at
that same interpreter and the environment in which it is installed.
- The ``debug``, ``optimization`` and ``b_ndebug`` options are overridden,
because Meson defaults to values that are appropriate for development, while
the main purpose of meson-python is to build release artifacts.

It is possible to override these defaults, either permanently in your
``pyproject.toml`` or at build time via the build frontend CLI.
See the :ref:`how-to-guides-meson-args` page for examples of both methods.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Contributors
:hidden:

explanations/design
explanations/default-options
explanations/internal-dependencies
explanations/editable-installs

Expand Down
10 changes: 10 additions & 0 deletions docs/reference/pyproject-settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ This page lists the configuration settings supported by ``meson-python`` in the

* - ``tool.meson-python.args.install``
- Extra arguments to be passed to the ``meson install`` command.

Usage example:

.. code-block:: toml
[tool.meson-python.args]
setup = ['-Dwarning_level=2', '-Db_pie=true']
dist = ['--include-subprojects']
compile = ['-j4']
install = ['--quiet']