-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
BLD Add Meson support #28040
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
BLD Add Meson support #28040
Conversation
I wonder at which point @lesteve thinks this is ready to be merged 😁 |
Use conda for this, if you install meson-python with pip, this does not not | ||
include ninja, and you need another way to install ninja (e.g. package | ||
manager) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is gonna be a challenge. We have a LOT of contributors who don't use mamba/conda. But I think it'd be okay, yet another system dependency like the compiler. I'm just not sure about ninja version compatibility with meson-python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This note should be removed I think. You can pip install ninja
just fine (even though it's better done through you distro package manager perhaps).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I was misled by the fact that pip install meson-python
did not install ninja
. Maybe there is a good reason for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because ninja is a C++ application, not a python application.
It is more common for ninja to be installed by a linux distro or as part of Visual Studio, than it is for ninja to be installed from (the unofficial third-party package on) PyPI. In such cases, it won't be detected as "installed" by pip at all, no more than GNU make is detected as installed, or GNU bash.
What meson-python does is check at the time you invoke the build-backend, whether ninja
is available somewhere on $PATH. If it is NOT available, then meson-python adds ninja to get_requires_for_build_wheel, so pip installs ninja after installing and running meson-python, but before launching meson setup
.
So, meson-python guarantees that ninja is installed. But it doesn't voice an opinion on whether you install it via your package manager or via pip install.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK good to know, thanks a lot for the details!
Because we use --no-build-isolation
, the mechanism for installing ninja
automatically is not going to cover our use case unfortunately.
This is really not a big deal at all, this is completely fine to tell contributors to do pip install meson-python ninja
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, absolutely. And if the contributors are positive they already have ninja, they can modify the command line they run, which is quite trivial as long as meson-python doesn't unconditionally force it.
|
||
.. code-block:: bash | ||
|
||
make dev-meson |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this does an editable install. How does one installs in non-editable mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that for now editable command is the way to go. As I mentioned a few times, the idea is to have maintainers include Meson in their day-to-day work and improve/tweak things as we go.
Do you have a specific reason in mind, why you would want to use non-editable installs? One way is to edit pyproject.toml
set build-backend
and use the pip
command without --editable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to see how the workflow works for us, that includes:
- building and installing with meson
- building for contributors, a bunch of those having windows machines where they don't have
make
I'm quite uncomfortable with having a python file calling pip. Also, I would like to separate build from install. We should have the equivalent of pip install -e . --no-build-isolation
as well as make in
, which do very different things. The former including the latter as a step. Also, a make clean
shouldn't uninstall the package.
Exactly because the idea is to check our day-to-day work, I'm not comfortable with the current solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I was not explicit enough about this and/or it may have been lost in the many comments above. This is the way I see things unfolding (happy to tweak things according to feed-back):
- until we decide otherwise, setuptools remain the main way to build scikit-learn. This is the case even if this PR is merged.
- if this PR is merged, maintainers would be more than welcome to try out Meson through
make dev-meson
and report issues so that we can improve the situation if needed. During this transition period, non-maintainers are not expected to try out Meson. Maintainers that want to keep using setuptools are completely free to do so (i.e. usemake in
,pip install -e . --no-use-pep517 --no-build-isolation
orpython setup.py develop
) - hopefully after some time (maybe 1 or 2 months?), most maintainers are convinced that Meson works well and we have fixed teething issues if any arises. We can then switch to Meson as the main build backend, i.e. set
build-backend = "mesonpy"
inpyproject.toml
. This removes the need frombuild_tools/build-meson-editable-install.py
(I guess this is what you mean by by "a python file calling pip"). This file main goal is to conveniently build with Meson during the transition period. - once Meson is our main building tool, the doc is updated and all contributors use Meson. You can still use
setuptools
if you want (viamake in
orpython setup.py develop
). - Hopefully for our next release (1.5), Meson is our main building tool
- One day (maybe for 1.6, maybe later, maybe sooner) we remove
setup.py
and Meson is our only way to build scikit-learn
Hopefully, this alleviates some of your concerns 🤞!
Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see what we're gonna break 😉 I'm very excited for this.
@adrinjalali Wow nice 😍, given your previous message, I was expecting that more convincing would be needed 😅. Anyone should feel completely free to ping me directly on any Meson-related issue. Thanks a lot to everyone that contributed questions, improvements, clarifications on this PR! |
@lesteve I'm not completely happy with the setup as is, but it's much easier to iterate from here than trying to fix things in this huge PR. Since merging this was quite inconsequential, I thought having discussions in smaller issues/prs is gonna be more productive :) |
Or me. ;) |
Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com> Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org> Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com> Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org> Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com> Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org> Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
This adds support for building with Meson. Locally this compiles and the test pass.
As far as I can see, the main motivations are:
ccache
support works without having to tweakPATH
or alternativeSKLEARN_BUILD_PARALLEL
meson.build
writer:sklearn/svm
I found the meson.build files a lot more explicit and readable than our setuptools setup. It is true that they are more verbose, but I think this is a good thing.ninja -C build -t missing-deps
allows to spot issues in yourmeson.build
file for example, that was super useful forsklearn.metrics._pairwise_distances_reduction
, as the dependency between cython code files is far from trivial. Being able to look at ninja files to figure out the exact flags used was super useful (O3 in the trees). commands likemeson introspect build/ -i --targets
could be handy too.pip
(i.e. you recompile from scratch each time) so we tell contributors to use--no-use-pep517
i.e.python setup.py develop
which has been discouraged for a while, see Installation guidelines now display default pip install commands and only expands in the notes #27960. We also bump into weird edge cases with Pytest on Windows see BUG: pytest error when loading conftest (seemingly platform-specific) #27806.Other things Meson could allow:
I guess the plan for now would be to have Meson supported, maybe tested in one CI build in this PR. Longer-term, the idea would be to give people time to get used to Meson and eventually for Meson to be our main way of building scikit-learn.
Tip
If you want to give this a try locally, the simplest is probably:
Make sure you have meson-python installed:
To make it more easy to try, I added
dev-meson
to theMakefile
in this PR:And also
clean-meson
in case you want to go back using setuptools:Note
note, tip, warnings, etc ... are a recent thing in github markdown see https://github.blog/changelog/2023-12-14-new-markdown-extension-alerts-provide-distinctive-styling-for-significant-content/