Skip to content

Commit 0497378

Browse files
authored
Merge pull request numpy#24186 from charris/update-meson.build
MAINT: Update meson.build files from main branch
2 parents c300e10 + 5b62e95 commit 0497378

File tree

10 files changed

+164
-23
lines changed

10 files changed

+164
-23
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: [

meson_options.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ option('blas', type: 'string', value: 'openblas',
22
description: 'option for BLAS library switching')
33
option('lapack', type: 'string', value: 'openblas',
44
description: 'option for LAPACK library switching')
5+
option('use-ilp64', type: 'boolean', value: false,
6+
description: 'Use ILP64 (64-bit integer) BLAS and LAPACK interfaces')
7+
option('blas-symbol-suffix', type: 'string', value: '',
8+
description: 'BLAS and LAPACK symbol suffix to use, if any (often `64_` for ILP64)')
59
option('disable-svml', type: 'boolean', value: false,
610
description: 'Disable building against SVML')
711
option('disable-threading', type: 'boolean', value: false,

numpy/core/meson.build

Lines changed: 9 additions & 2 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',

numpy/core/setup.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ def can_link_svml():
7979
and "linux" in platform
8080
and sys.maxsize > 2**31)
8181

82+
def can_link_svml_fp16():
83+
"""SVML FP16 requires binutils >= 2.38 for an updated assembler
84+
"""
85+
if can_link_svml():
86+
binutils_ver = os.popen("ld -v").readlines()[0].strip()[-4:]
87+
return float(binutils_ver) >= 2.38
88+
8289
def check_git_submodules():
8390
out = os.popen("git submodule status")
8491
modules = out.readlines()
@@ -1009,6 +1016,8 @@ def generate_umath_doc_header(ext, build_dir):
10091016
# The ordering of names returned by glob is undefined, so we sort
10101017
# to make builds reproducible.
10111018
svml_objs.sort()
1019+
if not can_link_svml_fp16():
1020+
svml_objs = [o for o in svml_objs if not o.endswith('_h_la.s')]
10121021

10131022
config.add_extension('_multiarray_umath',
10141023
sources=multiarray_src + umath_src +

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 & 0 deletions
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,6 +152,7 @@ py.install_sources(
150152
[
151153
'_examples/cython/extending.pyx',
152154
'_examples/cython/extending_distributions.pyx',
155+
'_examples/cython/meson.build',
153156
'_examples/cython/setup.py',
154157
],
155158
subdir: 'numpy/random/_examples/cython'

0 commit comments

Comments
 (0)