8000 Merge pull request #24379 from rgommers/vendor-meson-try2 · numpy/numpy@e6d5a19 · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit e6d5a19

Browse files
authored
Merge pull request #24379 from rgommers/vendor-meson-try2
ENH: Vendor meson for multi-target build support
2 parents a1de603 + 8854212 commit e6d5a19

File tree

9 files changed

+118
-5
lines changed

9 files changed

+118
-5
lines changed

.github/workflows/linux_musl.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
git checkout $GITHUB_BASE_REF
4545
git -c user.email="you@example.com" merge --no-commit my_ref_name
4646
fi
47+
git submodule update --init
4748
4849
ln -s /usr/local/bin/python3.10 /usr/local/bin/python
4950

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "numpy/core/src/npysort/x86-simd-sort"]
88
path = numpy/core/src/npysort/x86-simd-sort
99
url = https://github.com/intel/x86-simd-sort
10+
[submodule "vendored-meson/meson"]
11+
path = vendored-meson/meson
12+
url = https://github.com/numpy/meson.git

.spin/cmds.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,54 @@
1111
from spin import util
1212

1313

14+
# The numpy-vendored version of Meson. Put the directory that the executable
15+
# `meson` is in at the front of the PATH.
16+
curdir = pathlib.Path(__file__).parent.resolve()
17+
meson_executable_dir = str(curdir.parent / 'vendored-meson' / 'entrypoint')
18+
os.environ['PATH'] = meson_executable_dir + os.pathsep + os.environ['PATH']
19+
20+
# Check that the meson git submodule is present
21+
meson_import_dir = curdir.parent / 'vendored-meson' / 'meson' / 'mesonbuild'
22+
if not meson_import_dir.exists():
23+
raise RuntimeError(
24+
'The `vendored-meson/meson` git submodule does not exist! ' +
25+
'Run `git submodule update --init` to fix this problem.'
26+
)
27+
28+
29+
@click.command()
30+
@click.option(
31+
"-j", "--jobs",
32+
help="Number of parallel tasks to launch",
33+
type=int
34+
)
35+
@click.option(
36+
"--clean", is_flag=True,
37+
help="Clean build directory before build"
38+
)
39+
@click.option(
40+
"-v", "--verbose", is_flag=True,
41+
help="Print all build output, even installation"
42+
)
43+
@click.argument("meson_args", nargs=-1)
44+
@click.pass_context
45+
def build(ctx, meson_args, jobs=None, clean=False, verbose=False):
46+
"""🔧 Build package with Meson/ninja and install
47+
48+
MESON_ARGS are passed through e.g.:
49+
50+
spin build -- -Dpkg_config_path=/lib64/pkgconfig
51+
52+
The package is installed to build-install
53+
54+
By default builds for release, to be able to use a debugger set CFLAGS
55+
appropriately. For example, for linux use
56+
57+
CFLAGS="-O0 -g" spin build
58+
"""
59+
ctx.forward(meson.build)
60+
61+
1462
@click.command()
1563
@click.argument("sphinx_target", default="html")
1664
@click.option(
@@ -32,7 +80,7 @@
3280
)
3381
@click.option(
3482
"--install-deps/--no-install-deps",
35-
default=True,
83+
default=False,
3684
help="Install dependencies before building"
3785
)
3886
@click.pass_context

LICENSES_bundled.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ Name: libdivide
2020
Files: numpy/core/include/numpy/libdivide/*
2121
License: Zlib
2222
For license text, see numpy/core/include/numpy/libdivide/LICENSE.txt
23+
24+
25+
Note that the following files are ve 1E79 ndored in the repository and sdist but not
26+
installed in built numpy packages:
27+
28+
Name: Meson
29+
Files: vendored-meson/meson/*
30+
License: Apache 2.0
31+
For license text, see vendored-meson/meson/COPYING

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[build-system]
2-
build-backend = "mesonpy"
2+
build-backend = "npbuild"
3+
backend-path = ['./vendored-meson/build-backend-wrapper']
34
requires = [
45
"Cython>=3.0",
56
"meson-python>=0.13.1",
@@ -184,7 +185,7 @@ repair-wheel-command = "bash ./tools/wheels/repair_windows.sh {wheel} {dest_dir}
184185
package = 'numpy'
185186

186187
[tool.spin.commands]
187-
"Build" = ["spin.cmds.meson.build", ".spin/cmds.py:test"]
188+
"Build" = [".spin/cmds.py:build", ".spin/cmds.py:test"]
188189
"Environments" = [
189190
".spin/cmds.py:run", ".spin/cmds.py:ipython",
190191
".spin/cmds.py:python", ".spin/cmds.py:gdb"

tools/travis-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fi
1616

1717
source builds/venv/bin/activate
1818

19-
pip install --upgrade pip 'setuptools<49.2.0'
19+
pip install --upgrade pip 'setuptools<49.2.0' build
2020

2121
pip install -r build_requirements.txt
2222

@@ -223,7 +223,7 @@ elif [ -n "$USE_SDIST" ] && [ $# -eq 0 ]; then
223223
$PYTHON -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)"
224224
# ensure some warnings are not issued
225225
export CFLAGS=$CFLAGS" -Wno-sign-compare -Wno-unused-result -Wno-error=undef"
226-
$PYTHON setup.py sdist
226+
$PYTHON -m build --sdist
227227
# Make another virtualenv to install into
228228
$PYTHON -m venv venv-for-wheel
229229
. venv-for-wheel/bin/activate
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
import sys
3+
import pathlib
4+
5+
from mesonpy import (
6+
build_sdist,
7+
build_wheel,
8+
build_editable,
9+
get_requires_for_build_sdist,
10+
get_requires_for_build_wheel,
11+
get_requires_for_build_editable,
12+
)
13+
14+
15+
# The numpy-vendored version of Meson. Put the directory that the executable
16+
# `meson` is in at the front of the PATH.
17+
curdir = pathlib.Path(__file__).parent.resolve()
18+
meson_executable_dir = str(curdir.parent.parent / 'entrypoint')
19+
os.environ['PATH'] = meson_executable_dir + os.pathsep + os.environ['PATH']
20+
21+
# Check that the meson git submodule is present
22+
meson_import_dir = curdir.parent.parent / 'meson' / 'mesonbuild'
23+
if not meson_import_dir.exists():
24+
raise RuntimeError(
25+
'The `vendored-meson/meson` git submodule does not exist! ' +
26+
'Run `git submodule update --init` to fix this problem.'
27+
)

vendored-meson/entrypoint/meson

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
import re
4+
import sys
5+
import pathlib
6+
7+
8+
# The numpy-vendored version of Meson
9+
meson_dir = str(pathlib.Path(__file__).resolve().parent.parent / 'meson')
10+
sys.path.insert(0, meson_dir)
11+
12+
from mesonbuild.mesonmain import main
13+
import mesonbuild
14+
if not 'vendored-meson' in mesonbuild.__path__[0]:
15+
# Note: only the print statement will show most likely, not the exception.
16+
# If this goes wrong, it first fails inside meson-python on the `meson
17+
# --version` check.
18+
print(f'picking up the wrong `meson`: {mesonbuild.__path__}')
19+
raise RuntimeError('incorrect mesonbuild module, exiting')
20+
21+
if __name__ == '__main__':
22+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
23+
sys.exit(main())

vendored-meson/meson

Submodule meson added at 1f8351f

0 commit comments

Comments
 (0)
0