diff --git a/building_with_meson.md b/building_with_meson.md index 25949899869a..59269877176e 100644 --- a/building_with_meson.md +++ b/building_with_meson.md @@ -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` @@ -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 diff --git a/meson.build b/meson.build index 47e71efc00cb..be0f2985c03d 100644 --- a/meson.build +++ b/meson.build @@ -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', @@ -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' @@ -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. diff --git a/meson_options.txt b/meson_options.txt index f53432def980..0b506385a8ba 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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)') diff --git a/numpy/meson.build b/numpy/meson.build index de36e0d4941d..7b85d8e92f5b 100644 --- a/numpy/meson.build +++ b/numpy/meson.build @@ -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, @@ -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, @@ -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 diff --git a/tools/ci/cirrus_macosx_arm64.yml b/tools/ci/cirrus_macosx_arm64.yml index 2343b807f536..53e4afeb3b46 100644 --- a/tools/ci/cirrus_macosx_arm64.yml +++ b/tools/ci/cirrus_macosx_arm64.yml @@ -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