Skip to content

Commit

Permalink
BLD: updates to the Meson build
Browse files Browse the repository at this point in the history
Mostly synced from SciPy, and also addresses some warnings that
show up with Meson 1.1.0

[skip circle] [skip azp]
  • Loading branch information
rgommers committed May 18, 2023
1 parent cebb7a6 commit 941bc5b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 36 deletions.
16 changes: 8 additions & 8 deletions building_with_meson.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ into a problem._

**Install build tools:** Use one of:

- `mamba env create -f environment.yml && mamba activate numpy-dev
- `mamba env create -f environment.yml && mamba activate numpy-dev`

- `python -m pip install -r build_requirements.txt
# also make sure you have pkg-config and the usual system dependencies for
# NumPy`
- `python -m pip install -r build_requirements.txt`
*Note: also make sure you have `pkg-config` and the usual system dependencies
for NumPy*

Then install spin:
- `python -m pip install spin`
Expand Down Expand Up @@ -42,10 +42,10 @@ Note that `pip` will use the default build system, which is (as of now) still
`build-backend = "mesonpy"` line at the top of `pyproject.toml`.

After that is done, `pip install .` or `pip install --no-build-isolation .`
will work as expected. As does building an sdist or wheel with `python -m build`.
Note, however, that `pip install -e .` (in-place developer install) does not!
Use `spin` instead (see above).

will work as expected. As does building an sdist or wheel with `python -m build`,
or `pip install -e . --no-build-isolation` for an editable install.
For a more complete developer experience than editable installs, consider using
`spin` instead though (see above).


### Workaround for a hiccup on Fedora
Expand Down
17 changes: 13 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(
# See `numpy/__init__.py`
version: '1.24.0.dev0',
license: 'BSD-3',
meson_version: '>= 0.64.0',
meson_version: '>= 1.1.0',
default_options: [
'buildtype=debugoptimized',
'b_ndebug=if-release',
Expand All @@ -22,6 +22,7 @@ fs = import('fs')

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

# Check compiler is recent enough (see the SciPy Toolchain Roadmap for details)
if cc.get_id() == 'gcc'
Expand All @@ -34,16 +35,24 @@ elif cc.get_id() == 'msvc'
'when building with MSVC')
endif
endif
if not cy.version().version_compare('>=0.29.34')
error('NumPy requires Cython >= 0.29.34')
endif

# https://mesonbuild.com/Python-module.html
py_mod = import('python')
py = py_mod.find_installation(pure: false)
py = import('python').find_installation(pure: false)
py_dep = py.dependency()

if not cc.has_header('Python.h', dependencies: py_dep)
error('Cannot compile `Python.h`. Perhaps you need to install python-dev|python-devel')
endif

# Add default compile flags for any compiler that supports them.
# Note that MSVC does not support strict aliasing at all, and neither do the
# Intel compilers on Windows, so the `-fno` flavor of the flag should be fine.
add_project_arguments(
cc.get_supported_arguments( '-fno-strict-aliasing'), language : 'c'
)

# Generate version number. Note that this will not (yet) update the version
# number seen by pip or reflected in wheel filenames. See
# https://github.com/mesonbuild/meson-python/issues/159 for that.
Expand Down
8 changes: 4 additions & 4 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ 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('disable-svml', type: 'boolean', value: 'false',
option('disable-svml', type: 'boolean', value: false,
description: 'Disable building against SVML')
option('disable-threading', type: 'boolean', value: 'false',
option('disable-threading', type: 'boolean', value: false,
description: 'Disable threading support (see `NPY_ALLOW_THREADS` docs)')
# TODO: flip value to 'false' once we have `npy_cpu_dispatch_config.h` & co.
option('disable-simd-optimizations', type: 'boolean', value: 'true',
option('disable-simd-optimizations', type: 'boolean', value: true,
description: 'Disable SIMD features beyond the baseline ones')
option('relaxed-strides-debug', type: 'boolean', value: 'false',
option('relaxed-strides-debug', type: 'boolean', value: false,
description: 'Enable relaxed strides debug mode (see `NPY_RELAXED_STRIDES_DEBUG` docs)')
42 changes: 23 additions & 19 deletions numpy/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,15 @@ endif
is_windows = host_machine.system() == 'windows'
is_mingw = is_windows and cc.get_id() == 'gcc'

if is_windows
if is_mingw
# For mingw-w64, link statically against the UCRT.
gcc_link_args = ['-lucrt', '-static']
if is_mingw
add_project_link_arguments(gcc_link_args, language: ['c', 'cpp'])
# Force gcc to float64 long doubles for compatibility with MSVC
# builds, for C only.
add_project_arguments('-mlong-double-64', language: 'c')
# Make fprintf("%zd") work (see https://github.com/rgommers/scipy/issues/118)
add_project_arguments('-D__USE_MINGW_ANSI_STDIO=1', language: ['c', 'cpp'])
# Manual add of MS_WIN64 macro when not using MSVC.
# https://bugs.python.org/issue28267
bitness = run_command('_build_utils/gcc_build_bitness.py').stdout().strip()
if bitness == '64'
add_project_arguments('-DMS_WIN64', language: ['c', 'cpp'])
endif
endif
add_project_link_arguments(gcc_link_args, language: ['c', 'cpp'])
# Force gcc to float64 long doubles for compatibility with MSVC
# builds, for C only.
add_project_arguments('-mlong-double-64', language: 'c')
# Make fprintf("%zd") work (see https://github.com/rgommers/scipy/issues/118)
add_project_arguments('-D__USE_MINGW_ANSI_STDIO=1', language: ['c', 'cpp'])
endif

# Enable UNIX large file support on 32-bit systems (64 bit off_t,
Expand Down Expand Up @@ -58,13 +50,27 @@ lapack_name = get_option('lapack')
# pkg-config uses a lower-case name while CMake uses a capitalized name, so try
# that too to make the fallback detection with CMake work
if blas_name == 'openblas'
blas_name = ['openblas', 'OpenBLAS']
blas = dependency(['openblas', 'OpenBLAS'], required: false)
else
blas = dependency(blas_name, required: false)
endif
have_blas = blas.found()
if have_blas and blas_name == '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.
# 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 = []
endif

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

dependency_map = {
'BLAS': blas,
Expand All @@ -74,8 +80,6 @@ dependency_map = {
# BLAS and LAPACK are optional dependencies for NumPy. We can only use a BLAS
# which provides a CBLAS interface.
# TODO: add ILP64 support
have_blas = blas.found() # TODO: and blas.has_cblas()
have_lapack = lapack.found()
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
Expand Down
4 changes: 3 additions & 1 deletion tools/ci/cirrus_macosx_arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ macos_arm64_test_task:
python --version
RUNNER_OS="macOS"
CFLAGS="-std=c99 -fno-strict-aliasing"
SDKROOT=/Applications/Xcode-14.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk
# NOTE: OpenBLAS is not used in this job; if that's done in the future, ensure
# PKG_CONFIG_PATH points to the directory containing the openblas.pc file
# that's installed with the cibw_before_build.sh command.
# used for installing OpenBLAS/gfortran
bash tools/wheels/cibw_before_build.sh $PWD
Expand Down

0 comments on commit 941bc5b

Please sign in to comment.