Skip to content

Commit 1dd9398

Browse files
committed
MAINT: Update meson.build files from main branch
In addition to the meson.build files in numpy, the submodules `numpy/core/src/npysort/x86-simd-sort` and `numpy/core/src/umath/svml` have also been updated to get the meson build changes in them. The include files have not been updated, as the main change seems to be removal of some of them in line with the changes in 2.0.0. Likewise the ABI and API numbers in `numpy/core/meson.build` have been kept in line with 1.25.x, but the dependencies there should be checked by someone more familiar with the new build infrastructure.
1 parent c300e10 commit 1dd9398

File tree

8 files changed

+151
-25
lines changed

8 files changed

+151
-25
lines changed

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project(
44
# Note that the git commit hash cannot be added dynamically here
55
# It is dynamically added upon import by versioneer
66
# See `numpy/__init__.py`
7-
version: '1.24.0.dev0',
7+
version: '1.26.0.dev0',
88
license: 'BSD-3',
99
meson_version: '>= 1.1.0',
1010
default_options: [

numpy/core/meson.build

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,16 @@ C_ABI_VERSION = '0x01000009'
4545
# 0x00000010 - 1.23.x
4646
# 0x00000010 - 1.24.x
4747
# 0x00000011 - 1.25.x
48+
# 0x00000011 - 1.26.x
4849
C_API_VERSION = '0x00000011'
4950

5051
# Check whether we have a mismatch between the set C API VERSION and the
5152
# actual C API VERSION. Will raise a MismatchCAPIError if so.
52-
run_command('code_generators/verify_c_api_version.py', '--api-version', C_API_VERSION, check: true)
53+
r = run_command('code_generators/verify_c_api_version.py', '--api-version', C_API_VERSION)
54+
55+
if r.returncode() != 0
56+
error('verify_c_api_version.py failed with output:\n' + r.stderr().strip())
57+
endif
5358

5459

5560
# Generate config.h and _numpyconfig.h
@@ -533,6 +538,8 @@ npymath_lib = static_library('npymath',
533538
dependencies: py_dep,
534539
install: true,
535540
install_dir: np_dir / 'core/lib',
541+
name_prefix: name_prefix_staticlib,
542+
name_suffix: name_suffix_staticlib,
536543
)
537544

538545
dir_separator = '/'
@@ -923,7 +930,7 @@ py.extension_module('_multiarray_umath',
923930
'src/npymath',
924931
'src/umath',
925932
],
926-
dependencies: blas,
933+
dependencies: blas_dep,
927934
link_with: npymath_lib,
928935
install: true,
929936
subdir: 'numpy/core',
@@ -994,7 +1001,6 @@ python_sources = [
9941001
'shape_base.py',
9951002
'shape_base.pyi',
9961003
'umath.py',
997-
'umath_tests.py',
9981004
]
9991005

10001006
py.install_sources(

numpy/core/src/umath/svml

Submodule svml updated 111 files

numpy/linalg/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endif
2020

2121
py.extension_module('lapack_lite',
2222
lapack_lite_module_src,
23-
dependencies: [np_core_dep, lapack],
23+
dependencies: [np_core_dep, blas_dep, lapack_dep],
2424
install: true,
2525
subdir: 'numpy/linalg',
2626
)

numpy/meson.build

Lines changed: 90 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ if is_mingw
2222
add_project_arguments('-D__USE_MINGW_ANSI_STDIO=1', language: ['c', 'cpp'])
2323
endif
2424

25+
# We install libnpymath and libnpyrandom; ensure they're using a `.lib` rather
26+
# than a `.a` file extension in order not to break including them in a
27+
# distutils-based build (see gh-23981 and
28+
# https://mesonbuild.com/FAQ.html#why-does-building-my-project-with-msvc-output-static-libraries-called-libfooa)
29+
if is_windows and cc.get_id() == 'msvc'
30+
name_prefix_staticlib = ''
31+
name_suffix_staticlib = 'lib'
32+
else
33+
name_prefix_staticlib = []
34+
name_suffix_staticlib = []
35+
endif
36+
2537
# Enable UNIX large file support on 32-bit systems (64 bit off_t,
2638
# lseek -> lseek64, etc.)
2739
cflags_large_file_support = []
@@ -55,36 +67,84 @@ else
5567
blas = dependency(blas_name, required: false)
5668
endif
5769
have_blas = blas.found()
58-
if have_blas and blas_name == 'blas'
70+
cblas = []
71+
if have_blas
5972
# Netlib BLAS has a separate `libcblas.so` which we use directly in the g77
60-
# ABI wrappers, so detect it and error out if we cannot find it.
73+
# ABI wrappers, so detect it and error out if we cannot find it. OpenBLAS can
74+
# be built without CBLAS too (see gh-23909, done by Arch Linux until
75+
# recently)
6176
# In the future, this should be done automatically for:
6277
# `dependency('blas', modules: cblas)`
6378
# see https://github.com/mesonbuild/meson/pull/10921.
64-
cblas = dependency('cblas')
65-
else
66-
cblas = []
79+
have_cblas = false
80+
if cc.links('''
81+
#include <cblas.h>
82+
int main(int argc, const char *argv[])
83+
{
84+
double a[4] = {1,2,3,4};
85+
double b[4] = {5,6,7,8};
86+
return cblas_ddot(4, a, 1, b, 1) > 10;
87+
}
88+
''',
89+
dependencies: blas,
90+
name: 'CBLAS',
91+
)
92+
have_cblas = true
93+
else
94+
cblas = dependency('cblas', required: false)
95+
if cblas.found()
96+
have_cblas = true
97+
endif
98+
endif
6799
endif
68100

69101
if lapack_name == 'openblas'
70102
lapack_name = ['openblas', 'OpenBLAS']
71103
endif
72-
lapack = dependency(lapack_name, required: false)
73-
have_lapack = lapack.found()
104+
lapack_dep = dependency(lapack_name, required: false)
105+
have_lapack = lapack_dep.found()
74106

75107
dependency_map = {
76108
'BLAS': blas,
77-
'LAPACK': lapack,
109+
'LAPACK': lapack_dep,
78110
}
79111

112+
use_ilp64 = get_option('use-ilp64')
113+
if not use_ilp64
114+
# For now, keep supporting this environment variable too (same as in setup.py)
115+
# `false is the default for the CLI flag, so check if env var was set
116+
use_ilp64 = run_command(py,
117+
[
118+
'-c',
119+
'import os; print(1) if os.environ.get("NPY_USE_BLAS_ILP64", "0") != "0" else print(0)'
120+
],
121+
check: true
122+
).stdout().strip() == '1'
123+
endif
124+
80125
# BLAS and LAPACK are optional dependencies for NumPy. We can only use a BLAS
81126
# which provides a CBLAS interface.
82127
# TODO: add ILP64 support
83128
if have_blas
84-
# TODO: this is a shortcut - it needs to be checked rather than used
85-
# unconditionally, and then added to the extension modules that need the
86-
# macro, rather than as a project argument.
87-
add_project_arguments('-DHAVE_CBLAS', language: ['c', 'cpp'])
129+
c_args_blas = [] # note: used for C and C++ via `blas_dep` below
130+
if have_cblas
131+
c_args_blas += ['-DHAVE_CBLAS']
132+
endif
133+
if use_ilp64
134+
c_args_blas += ['-DHAVE_BLAS_ILP64']
135+
endif
136+
# This is currently injected directly into CFLAGS/CXXFLAGS for wheel builds
137+
# (see cibuildwheel settings in pyproject.toml)
138+
blas_symbol_suffix = get_option('blas-symbol-suffix')
139+
if blas_symbol_suffix != ''
140+
c_args_blas += ['-DBLAS_SYMBOL_SUFFIX=' + blas_symbol_suffix]
141+
endif
142+
blas_dep = declare_dependency(
143+
dependencies: [blas, cblas],
144+
compile_args: c_args_blas,
145+
)
146+
else
147+
blas_dep = []
88148
endif
89149

90150
# Copy the main __init__.py|pxd files to the build dir (needed for Cython)
@@ -138,7 +198,6 @@ pure_subdirs = [
138198
'_utils',
139199
'array_api',
140200
'compat',
141-
'distutils',
142201
'doc',
143202
'f2py',
144203
'lib',
@@ -149,6 +208,9 @@ pure_subdirs = [
149208
'tests',
150209
'typing',
151210
]
211+
if py.version().version_compare('<3.12')
212+
pure_subdirs += 'distutils'
213+
endif
152214

153215
np_dir = py.get_install_dir() / 'numpy'
154216

@@ -175,6 +237,14 @@ foreach name, compiler : compilers
175237
conf_data.set(name + '_COMP_LINKER_ID', compiler.get_linker_id())
176238
conf_data.set(name + '_COMP_VERSION', compiler.version())
177239
conf_data.set(name + '_COMP_CMD_ARRAY', ', '.join(compiler.cmd_array()))
240+
conf_data.set(name + '_COMP_ARGS', ', '.join(
241+
get_option(name.to_lower() + '_args')
242+
)
243+
)
244+
conf_data.set(name + '_COMP_LINK_ARGS', ', '.join(
245+
get_option(name.to_lower() + '_link_args')
246+
)
247+
)
178248
endforeach
179249

180250
# Machines CPU and system information
@@ -198,10 +268,13 @@ foreach name, dep : dependency_map
198268
if dep.found()
199269
conf_data.set(name + '_VERSION', dep.version())
200270
conf_data.set(name + '_TYPE_NAME', dep.type_name())
201-
conf_data.set(name + '_INCLUDEDIR', dep.get_variable('includedir'))
202-
conf_data.set(name + '_LIBDIR', dep.get_variable('libdir'))
203-
conf_data.set(name + '_OPENBLAS_CONFIG', dep.get_variable('openblas_config'))
204-
conf_data.set(name + '_PCFILEDIR', dep.get_variable('pcfiledir'))
271+
if dep.type_name() == 'pkgconfig'
272+
# CMake detection yields less info, so we need to leave it blank there
273+
conf_data.set(name + '_INCLUDEDIR', dep.get_variable('includedir'))
274+
conf_data.set(name + '_LIBDIR', dep.get_variable('libdir'))
275+
conf_data.set(name + '_OPENBLAS_CONFIG', dep.get_variable('openblas_config'))
276+
conf_data.set(name + '_PCFILEDIR', dep.get_variable('pcfiledir'))
277+
endif
205278
endif
206279
endforeach
207280

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
project('random-build-examples', 'c', 'cpp', 'cython')
2+
3+
py_mod = import('python')
4+
py3 = py_mod.find_installation(pure: false)
5+
6+
cc = meson.get_compiler('c')
7+
cy = meson.get_compiler('cython')
8+
9+
if not cy.version().version_compare('>=0.29.35')
10+
error('tests requires Cython >= 0.29.35')
11+
endif
12+
13+
_numpy_abs = run_command(py3, ['-c',
14+
'import os; os.chdir(".."); import numpy; print(os.path.abspath(numpy.get_include() + "../../.."))'],
15+
check: true).stdout().strip()
16+
17+
npymath_path = _numpy_abs / 'core' / 'lib'
18+
npy_include_path = _numpy_abs / 'core' / 'include'
19+
npyrandom_path = _numpy_abs / 'random' / 'lib'
20+
npymath_lib = cc.find_library('npymath', dirs: npymath_path)
21+
npyrandom_lib = cc.find_library('npyrandom', dirs: npyrandom_path)
22+
23+
py3.extension_module(
24+
'extending_distributions',
25+
'extending_distributions.pyx',
26+
install: false,
27+
include_directories: [npy_include_path],
28+
dependencies: [npyrandom_lib, npymath_lib],
29+
)
30+
py3.extension_module(
31+
'extending',
32+
'extending.pyx',
33+
install: false,
34+
include_directories: [npy_include_path],
35+
dependencies: [npyrandom_lib, npymath_lib],
36+
)
37+
py3.extension_module(
38+
'extending_cpp',
39+
'extending_distributions.pyx',
40+
install: false,
41+
override_options : ['cython_language=cpp'],
42+
cython_args: ['--module-name', 'extending_cpp'],
43+
include_directories: [npy_include_path],
44+
dependencies: [npyrandom_lib, npymath_lib],
45+
)

numpy/random/meson.build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ npyrandom_lib = static_library('npyrandom',
1515
dependencies: [py_dep, np_core_dep],
1616
install: true,
1717
install_dir: np_dir / 'random/lib',
18+
name_prefix: name_prefix_staticlib,
19+
name_suffix: name_suffix_staticlib,
1820
)
1921

2022
# Build Cython extensions for numpy.random
@@ -150,7 +152,7 @@ py.install_sources(
150152
[
151153
'_examples/cython/extending.pyx',
152154
'_examples/cython/extending_distributions.pyx',
153-
'_examples/cython/setup.py',
155+
'_examples/cython/meson.build',
154156
],
155157
subdir: 'numpy/random/_examples/cython'
156158
)

0 commit comments

Comments
 (0)