8000 ENH: Vendor meson/meson-python for multi-target build support by rgommers · Pull Request #24365 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Vendor meson/meson-python for multi-target build support #24365

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

Closed
wants to merge 5 commits into from

Conversation

rgommers
Copy link
Member
@rgommers rgommers commented Aug 8, 2023

The purpose of this PR is to enable merging the SIMD support for the Meson builds in gh-23096. That PR relies on mesonbuild/meson#11307, which is a significant new feature for Meson. That is multi-target support, allowing us to recompile the same sources multiple times, with compile flags set for different sets of SIMD instructions. Given that that PR is not going to get merged into Meson in time, we'll want to vendor it in order to be able to use it now.

This PR vendors the following:

And then does the required plumbing in order to use the vendored code for building.

I have tested that the combination of this PR and gh-23096 works together, and that the sdist/wheels produced look the way they should. The plan is to merge this PR first, and then rebase gh-23096 on top (Cc @seiko2plus).

I chose vendoring everything over packaging up a separate package (something like meson-numpy), because that'd be a real pain for distributions, they'd have to package that in all of their distros as a new package in other to be able to build numpy 1.26.0.

Licensing-wise: Meson is Apache 2.0 licensed, but because we don't install it as part of a built numpy package, I don't think that's a problem.

@eli-schwartz in case you have any insights or concerns here regarding the approach, or things you'd like to see in terms of validation for mesonbuild/meson#11307, please let us know.

The sources included are only those for the build backend itself,
plus the necessary license files and a .gitignore, not any other
files (tests, docs, ci, etc.).

The files included are from meson-python commit 2e99c7b5bce53403a9,
as of 26 July 2023. This is the most recent commit, and are a
development version (0.14.0-dev).

No changes have been made to any included files, except for removing
some entries from .gitignore.
This vendors the current state of mesonbuild/meson#11307,
which is the "feature module" for the multi-target build support that
NumPy needs to build its SIMD support (by Sayed Adel). That PR is,
as vendored, based on top of the state of the Meson master branch
in commit 9d88d0d5c, which is a dev commit in between the 1.2.0 and
1.2.1 tags from 18 July 2023.

No modifications have been made to any of the vendored files.
Note that this is a bit messy. I tried to vendor spin's `meson.py`
separately, but it's not possible to do so cleanly as far as I can
tell. The import machinery is unhappy bouncing around between
`bin/spin`, `.spin/cmds.py and `.spin/meson.py`. So it was either
folding the `spin/cmds/meson.py` content all into cmds.py, or vendor all
of the spin package. This seems to work.
These licenses are for:

- Meson
- meson-python
- spin

Importantly, Meson is Apache 2.0 licensed, which is incompatible with
NumPy's BSD-3 license. However, the Meson files are not installed, but
only used as a build tool. All installed files are still BSD-3 or
compatible with BSD-3.
@rgommers rgommers added 09 - Backport-Candidate PRs tagged should be backported Meson Items related to the introduction of Meson as the new build system for NumPy labels Aug 8, 2023
@rgommers rgommers added this to the 2.0.0 release milestone Aug 8, 2023
@rgommers rgommers requested a review from charris August 8, 2023 22:57

# Try joining file paths that contain spaces

reg_start = re.compile(r'^([A-Za-z]:)?/(.*/)*[^./]+$')

Check failure

Code scanning / CodeQL

Inefficient regular expression

This part of the regular expression may cause exponential backtracking on strings starting with '/' and containing many repetitions of '/'.
@eli-schwartz
Copy link

@eli-schwartz in case you have any insights or concerns here regarding the approach, or things you'd like to see in terms of validation for mesonbuild/meson#11307, please let us know.

I think this is quite understandable in order to move forward with numpy, it's a very friendly fork indeed. However, it seems a bit unfortunate to vendor meson-python as well, just to set the meson_cli path (I think?). I wonder if it would be possible to instead add your own tiny in-tree build-backend that:

  • manipulates $PATH to include ./vendored-meson/entrypoint
  • imports * from mesonpy

And stick a wrapper in that directory which invokes the meson.py script properly.

It may also make sense to include meson as a submodule -- this would probably be friendlier for git log. It shouldn't be hard to rebase that feature branch if you need fixes in between 1.2.0 and master. If you use a wrapper build backend around mesonpy, you could even try git submodule update --init automatically.

@mattip
Copy link
Member
mattip commented Aug 9, 2023

It may also make sense to include meson as a submodule -- this would probably be friendlier for git log

+1

@rgommers
Copy link
Member Author
rgommers commented Aug 9, 2023

I wonder if it would be possible to instead add your own tiny in-tree build-backend that:

Good idea, thanks. I'll give that a try this morning.

it seems a bit unfortunate to vendor meson-python as well, just to set the meson_cli path (I think?)

I also edited the meson-python dependencies to remove meson, but installing that and then not using it is not really a problem.

It may also make sense to include meson as a submodule

I think the main issue is keeping that working permanently. The PR branch is likely to be rebased multiple times, so we can't rely on it. So we'd have to create a repo at https://github.com/numpy/meson with branches or tags to point to, and keep it there forever. I hope this is a short-lived vendoring, and it can go away towards the end of the year (please correct me if you think that that is unlikely to be the case).

We can go this way if other maintainers prefer this, but I think I personally have a preference for not having another repo around permanently.

@mattip
Copy link
Member
mattip commented Aug 9, 2023

We can go this way if other maintainers prefer this, but I think I personally have a preference for not having another repo around permanently.

I think it will be easier to reason about upstream changes if we manage a fork. Meson seems to still be under active development (over 12 PRs merged in 3 days, and while we may not need many of those changes, managing that churn will be easier if it is a separate repo. Once our changes are merged upstream, we can archive the repo.

@rgommers
Copy link
Member Author
rgommers commented Aug 9, 2023

Okay, thanks Matti. I'll create a new numpy/meson repo then and will update this PR.

@charris charris changed the title Vendor meson/meson-python for multi-target build support ENH: Vendor meson/meson-python for multi-target build support Aug 9, 2023
@rgommers
Copy link
Member Author
rgommers commented Aug 9, 2023

Alternative PR up at gh-24379.

@rgommers rgommers removed this from the 2.0.0 release milestone Aug 10, 2023
@rgommers rgommers removed the 09 - Backport-Candidate PRs tagged should be backported label Aug 10, 2023
@rgommers
Copy link
Member Author

The approach in gh-24379 works and seems preferable, so closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Meson Items related to the introduction of Meson as the new build system for NumPy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0