8000 MAINT: Update meson.build files from main branch by charris · Pull Request #24186 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Update meson.build files from main branch #24186

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
Jul 17, 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
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(
# Note that the git commit hash cannot be added dynamically here
# It is dynamically added upon import by versioneer
# See `numpy/__init__.py`
version: '1.24.0.dev0',
version: '1.26.0.dev0',
license: 'BSD-3',
meson_version: '>= 1.1.0',
default_options: [
Expand Down
4 changes: 4 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ option('blas', type: 'string', value: 'openblas',
description: 'option for BLAS library switching')
option('lapack', type: 'string', value: 'openblas',
description: 'option for LAPACK library switching')
option('use-ilp64', type: 'boolean', value: false,
description: 'Use ILP64 (64-bit integer) BLAS and LAPACK interfaces')
option('blas-symbol-suffix', type: 'string', value: '',
description: 'BLAS and LAPACK symbol suffix to use, if any (often `64_` for ILP64)')
option('disable-svml', type: 'boolean', value: false,
description: 'Disable building against SVML')
option('disable-threading', type: 'boolean', value: false,
Expand Down
11 changes: 9 additions & 2 deletions numpy/core/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ C_ABI_VERSION = '0x01000009'
# 0x00000010 - 1.23.x
# 0x00000010 - 1.24.x
# 0x00000011 - 1.25.x
# 0x00000011 - 1.26.x
C_API_VERSION = '0x00000011'

# Check whether we have a mismatch between the set C API VERSION and the
# actual C API VERSION. Will raise a MismatchCAPIError if so.
run_command('code_generators/verify_c_api_version.py', '--api-version', C_API_VERSION, check: true)
r = run_command('code_generators/verify_c_api_version.py', '--api-version', C_API_VERSION)

if r.returncode() != 0
error('verify_c_api_version.py failed with output:\n' + r.stderr().strip())
endif


# Generate config.h and _numpyconfig.h
Expand Down Expand Up @@ -533,6 +538,8 @@ npymath_lib = static_library('npymath',
dependencies: py_dep,
install: true,
install_dir: np_dir / 'core/lib',
name_prefix: name_prefix_staticlib,
name_suffix: name_suffix_staticlib,
)

dir_separator = '/'
Expand Down Expand Up @@ -923,7 +930,7 @@ py.extension_module('_multiarray_umath',
'src/npymath',
'src/umath',
],
dependencies: blas,
dependencies: blas_dep,
link_with: npymath_lib,
install: true,
subdir: 'numpy/core',
Expand Down
9 changes: 9 additions & 0 deletions numpy/core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ def can_link_svml():
and "linux" in platform
and sys.maxsize > 2**31)

def can_link_svml_fp16():
"""SVML FP16 requires binutils >= 2.38 for an updated assembler
"""
if can_link_svml():
binutils_ver = os.popen("ld -v").readlines()[0].strip()[-4:]
return float(binutils_ver) >= 2.38

def check_git_submodules():
out = os.popen("git submodule status")
modules = out.readlines()
Expand Down Expand Up @@ -1009,6 +1016,8 @@ def generate_umath_doc_header(ext, build_dir):
# The ordering of names returned by glob is undefined, so we sort
# to make builds reproducible.
svml_objs.sort()
if not can_link_svml_fp16():
svml_objs = [o for o in svml_objs if not o.endswith('_h_la.s')]

config.add_extension('_multiarray_umath',
sources=multiarray_src + umath_src +
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/umath/svml
Submodule svml updated 111 files
2 changes: 1 addition & 1 deletion numpy/linalg/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ endif

py.extension_module('lapack_lite',
lapack_lite_module_src,
dependencies: [np_core_dep, lapack],
dependencies: [np_core_dep, blas_dep, lapack_dep],
install: true,
subdir: 'numpy/linalg',
)
Expand Down
107 changes: 90 additions & 17 deletions numpy/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ if is_mingw
add_project_arguments('-D__USE_MINGW_ANSI_STDIO=1', language: ['c', 'cpp'])
endif

# We install libnpymath and libnpyrandom; ensure they're using a `.lib` rather
# than a `.a` file extension in order not to break including them in a
# distutils-based build (see gh-23981 and
# https://mesonbuild.com/FAQ.html#why-does-building-my-project-with-msvc-output-static-libraries-called-libfooa)
if is_windows and cc.get_id() == 'msvc'
name_prefix_staticlib = ''
name_suffix_staticlib = 'lib'
else
name_prefix_staticlib = []
name_suffix_staticlib = []
endif

# Enable UNIX large file support on 32-bit systems (64 bit off_t,
# lseek -> lseek64, etc.)
cflags_large_file_support = []
Expand Down Expand Up @@ -55,36 +67,84 @@ else
blas = dependency(blas_name, required: false)
endif
have_blas = blas.found()
if have_blas and blas_name == 'blas'
cblas = []
if have_blas
# Netlib BLAS has a separate `libcblas.so` which we use directly in the g77
# ABI wrappers, so detect it and error out if we cannot find it.
# ABI wrappers, so detect it and error out if we cannot find it. OpenBLAS can
# be built without CBLAS too (see gh-23909, done by Arch Linux until
# recently)
# In the future, this should be done automatically for:
# `dependency('blas', modules: cblas)`
# see https://github.com/mesonbuild/meson/pull/10921.
cblas = dependency('cblas')
else
cblas = []
have_cblas = false
if cc.links('''
#include <cblas.h>
int main(int argc, const char *argv[])
{
double a[4] = {1,2,3,4};
double b[4] = {5,6,7,8};
return cblas_ddot(4, a, 1, b, 1) > 10;
}
''',
dependencies: blas,
name: 'CBLAS',
)
have_cblas = true
else
cblas = dependency('cblas', required: false)
if cblas.found()
have_cblas = true
endif
endif
endif

if lapack_name == 'openblas'
lapack_name = ['openblas', 'OpenBLAS']
endif
lapack = dependency(lapack_name, required: false)
have_lapack = lapack.found()
lapack_dep = dependency(lapack_name, required: false)
have_lapack = lapack_dep.found()

dependency_map = {
'BLAS': blas,
'LAPACK': lapack,
'LAPACK': lapack_dep,
}

F438 use_ilp64 = get_option('use-ilp64')
if not use_ilp64
# For now, keep supporting this environment variable too (same as in setup.py)
# `false is the default for the CLI flag, so check if env var was set
use_ilp64 = run_command(py,
[
'-c',
'import os; print(1) if os.environ.get("NPY_USE_BLAS_ILP64", "0") != "0" else print(0)'
],
check: true
).stdout().strip() == '1'
endif

# BLAS and LAPACK are optional dependencies for NumPy. We can only use a BLAS
# which provides a CBLAS interface.
# TODO: add ILP64 support
if have_blas
# TODO: this is a shortcut - it needs to be checked rather than used
# unconditionally, and then added to the extension modules that need the
# macro, rather than as a project argument.
add_project_arguments('-DHAVE_CBLAS', language: ['c', 'cpp'])
c_args_blas = [] # note: used for C and C++ via `blas_dep` below
if have_cblas
c_args_blas += ['-DHAVE_CBLAS']
endif
if use_ilp64
c_args_blas += ['-DHAVE_BLAS_ILP64']
endif
# This is currently injected directly into CFLAGS/CXXFLAGS for wheel builds
# (see cibuildwheel settings in pyproject.toml)
blas_symbol_suffix = get_option('blas-symbol-suffix')
if blas_symbol_suffix != ''
c_args_blas += ['-DBLAS_SYMBOL_SUFFIX=' + blas_symbol_suffix]
endif
blas_dep = declare_dependency(
dependencies: [blas, cblas],
compile_args: c_args_blas,
)
else
blas_dep = []
endif

# Copy the main __init__.py|pxd files to the build dir (needed for Cython)
Expand Down Expand Up @@ -138,7 +198,6 @@ pure_subdirs = [
'_utils',
'array_api',
'compat',
'distutils',
'doc',
'f2py',
'lib',
Expand All @@ -149,6 +208,9 @@ pure_subdirs = [
'tests',
'typing',
]
if py.version().version_compare('<3.12')
pure_subdirs += 'distutils'
endif

np_dir = py.get_install_dir() / 'numpy'

Expand All @@ -175,6 +237,14 @@ foreach name, compiler : compilers
conf_data.set(name + '_COMP_LINKER_ID', compiler.get_linker_id())
conf_data.set(name + '_COMP_VERSION', compiler.version())
conf_data.set(name + '_COMP_CMD_ARRAY', ', '.join(compiler.cmd_array()))
conf_data.set(name + '_COMP_ARGS', ', '.join(
get_option(name.to_lower() + '_args')
)
)
conf_data.set(name + '_COMP_LINK_ARGS', ', '.join(
get_option(name.to_lower() + '_link_args')
)
)
endforeach

# Machines CPU and system information
Expand All @@ -198,10 +268,13 @@ foreach name, dep : dependency_map
if dep.found()
conf_data.set(name + '_VERSION', dep.version())
conf_data.set(name + '_TYPE_NAME', dep.type_name())
conf_data.set(name + '_INCLUDEDIR', dep.get_variable('includedir'))
conf_data.set(name + '_LIBDIR', dep.get_variable('libdir'))
conf_data.set(name + '_OPENBLAS_CONFIG', dep.get_variable('openblas_config'))
conf_data.set(name + '_PCFILEDIR', dep.get_variable('pcfiledir'))
if dep.type_name() == 'pkgconfig'
# CMake detection yields less info, so we need to leave it blank there
conf_data.set(name + '_INCLUDEDIR', dep.get_variable('includedir'))
conf_data.set(name + '_LIBDIR', dep.get_variable('libdir'))
conf_data.set(name + '_OPENBLAS_CONFIG', dep.get_variable('openblas_config'))
conf_data.set(name + '_PCFILEDIR', dep.get_variable('pcfiledir'))
endif
endif
endforeach

Expand Down
45 changes: 45 additions & 0 deletions numpy/random/_examples/cython/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
project('random-build-examples', 'c', 'cpp', 'cython')

py_mod = import('python')
py3 = py_mod.find_installation(pure: false)

cc = meson.get_compiler('c')
cy = meson.get_compiler('cython')

if not cy.version().version_compare('>=0.29.35')
error('tests requires Cython >= 0.29.35')
endif

_numpy_abs = run_command(py3, ['-c',
'import os; os.chdir(".."); import numpy; print(os.path.abspath(numpy.get_include() + "../../.."))'],
check: true).stdout().strip()

npymath_path = _numpy_abs / 'core' / 'lib'
npy_include_path = _numpy_abs / 'core' / 'include'
npyrandom_path = _numpy_abs / 'random' / 'lib'
npymath_lib = cc.find_library('npymath', dirs: npymath_path)
npyrandom_lib = cc.find_library('npyrandom', dirs: npyrandom_path)

py3.extension_module(
'extending_distributions',
'extending_distributions.pyx',
install: false,
include_directories: [npy_include_path],
dependencies: [npyrandom_lib, npymath_lib],
)
py3.extension_module(
'extending',
'extending.pyx',
install: false,
include_directories: [npy_include_path],
dependencies: [npyrandom_lib, npymath_lib],
)
py3.extension_module(
'extending_cpp',
'extending_distributions.pyx',
install: false,
override_options : ['cython_language=cpp'],
cython_args: ['--module-name', 'extending_cpp'],
include_directories: [npy_include_path],
dependencies: [npyrandom_lib, npymath_lib],
)
3 changes: 3 additions & 0 deletions numpy/random/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ npyrandom_lib = static_library('npyrandom',
dependencies: [py_dep, np_core_dep],
install: true,
install_dir: np_dir / 'random/lib',
name_prefix: name_prefix_staticlib,
name_suffix: name_suffix_staticlib,
)

# Build Cython extensions for numpy.random
Expand Down Expand Up @@ -150,6 +152,7 @@ py.install_sources(
[
'_examples/cython/extending.pyx',
'_examples/cython/extending_distributions.pyx',
'_examples/cython/meson.build',
'_examples/cython/setup.py',
],
subdir: 'numpy/random/_examples/cython'
Expand Down
0