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

Skip to content

ENH: Vendor meson for multi-target build support #24379

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

Merged
merged 4 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
BLD: build with our numpy fork of meson
  • Loading branch information
rgommers committed Aug 10, 2023
commit 4d05cd1ef67f6c9b4f0bb63d69d388f7651c62bf
48 changes: 48 additions & 0 deletions .spin/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,54 @@
from spin import util


# The numpy-vendored version of Meson. Put the directory that the executable
# `meson` is in at the front of the PATH.
curdir = pathlib.Path(__file__).parent.resolve()
meson_executable_dir = str(curdir.parent / 'vendored-meson' / 'entrypoint')
os.environ['PATH'] = meson_executable_dir + os.pathsep + os.environ['PATH']

# Check that the meson git submodule is present
meson_import_dir = curdir.parent / 'vendored-meson' / 'meson' / 'mesonbuild'
if not meson_import_dir.exists():
raise RuntimeError(
'The `vendored-meson/meson` git submodule does not exist! ' +
'Run `git submodule update --init` to fix this problem.'
)


@click.command()
@click.option(
"-j", "--jobs",
help="Number of parallel tasks to launch",
type=int
)
@click.option(
"--clean", is_flag=True,
help="Clean build directory before build"
)
@click.option(
"-v", "--verbose", is_flag=True,
help="Print all build output, even installation"
)
@click.argument("meson_args", nargs=-1)
@click.pass_context
def build(ctx, meson_args, jobs=None, clean=False, verbose=False):
"""🔧 Build package with Meson/ninja and install

MESON_ARGS are passed through e.g.:

spin build -- -Dpkg_config_path=/lib64/pkgconfig

The package is installed to build-install

By default builds for release, to be able to use a debugger set CFLAGS
appropriately. For example, for linux use

CFLAGS="-O0 -g" spin build
"""
ctx.forward(meson.build)


@click.command()
@click.argument("sphinx_target", default="html")
@click.option(
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[build-system]
build-backend = "mesonpy"
build-backend = "npbuild"
backend-path = ['./vendored-meson/build-backend-wrapper']
requires = [
"Cython>=3.0",
"meson-python>=0.13.1",
Expand Down Expand Up @@ -184,7 +185,7 @@ repair-wheel-command = "bash ./tools/wheels/repair_windows.sh {wheel} {dest_dir}
package = 'numpy'

[tool.spin.commands]
"Build" = ["spin.cmds.meson.build", ".spin/cmds.py:test"]
"Build" = [".spin/cmds.py:build", ".spin/cmds.py:test"]
"Environments" = [
".spin/cmds.py:run", ".spin/cmds.py:ipython",
".spin/cmds.py:python", ".spin/cmds.py:gdb"
Expand Down
27 changes: 27 additions & 0 deletions vendored-meson/build-backend-wrapper/npbuild/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import sys
import pathlib

from mesonpy import (
build_sdist,
build_wheel,
build_editable,
get_requires_for_build_sdist,
get_requires_for_build_wheel,
get_requires_for_build_editable,
)


# The numpy-vendored version of Meson. Put the directory that the executable
# `meson` is in at the front of the PATH.
curdir = pathlib.Path(__file__).parent.resolve()
meson_executable_dir = str(curdir.parent.parent / 'entrypoint')
os.environ['PATH'] = meson_executable_dir + os.pathsep + os.environ['PATH']

# Check that the meson git submodule is present
meson_import_dir = curdir.parent.parent / 'meson' / 'mesonbuild'
if not meson_import_dir.exists():
raise RuntimeError(
'The `vendored-meson/meson` git submodule does not exist! ' +
'Run `git submodule update --init` to fix this problem.'
)
23 changes: 23 additions & 0 deletions vendored-meson/entrypoint/meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import sys
import pathlib


# The numpy-vendored version of Meson
meson_dir = str(pathlib.Path(__file__).resolve().parent.parent / 'meson')
sys.path.insert(0, meson_dir)

from mesonbuild.mesonmain import main
import mesonbuild
if not 'vendored-meson' in mesonbuild.__path__[0]:
# Note: only the print statement will show most likely, not the exception.
# If this goes wrong, it first fails inside meson-python on the `meson
# --version` check.
print(f'picking up the wrong `meson`: {mesonbuild.__path__}')
raise RuntimeError('incorrect mesonbuild module, exiting')

if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
0