Skip to content
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

numpy v1.26.0 with meson #297

Merged
merged 8 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
34 changes: 14 additions & 20 deletions recipe/bld.bat
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
(
echo [DEFAULT]
echo library_dirs = %LIBRARY_LIB%
echo include_dirs = %LIBRARY_INC%
echo [lapack]
echo libraries = lapack,blas
echo [blas]
echo libraries = cblas,blas
echo [cblas]
echo libraries = cblas,blas
) > site.cfg
@echo on

set "NPY_LAPACK_ORDER=lapack"
set "NPY_BLAS_ORDER=blas"
mkdir builddir

%PYTHON% -m pip install --no-deps --ignore-installed -v .
if errorlevel 1 exit 1
:: -wnx flags mean: --wheel --no-isolation --skip-dependency-check
%PYTHON% -m build -w -n -x ^
-Cbuilddir=builddir ^
-Csetup-args=-Dblas=blas ^
-Csetup-args=-Dlapack=lapack
if %ERRORLEVEL% neq 0 exit 1

XCOPY %RECIPE_DIR%\f2py.bat %SCRIPTS% /s /e
if errorlevel 1 exit 1

del %SCRIPTS%\f2py.exe
if errorlevel 1 exit 1
h-vetinari marked this conversation as resolved.
Show resolved Hide resolved
:: `pip install dist\numpy*.whl` does not work on windows,
:: so use a loop; there's only one wheel in dist/ anyway
for /f %%f in ('dir /b /S .\dist') do (
pip install %%f
if %ERRORLEVEL% neq 0 exit 1
)
45 changes: 27 additions & 18 deletions recipe/build.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
#!/bin/bash
set -ex

set -x
# necessary for cross-compilation to point to the right env
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig

# numpy distutils don't use the env variables.
if [[ ! -f $BUILD_PREFIX/bin/ranlib ]]; then
ln -s $RANLIB $BUILD_PREFIX/bin/ranlib
ln -s $AR $BUILD_PREFIX/bin/ar
fi
mkdir builddir

cat > site.cfg <<EOF
[DEFAULT]
library_dirs = $PREFIX/lib
include_dirs = $PREFIX/include
# HACK: extend $CONDA_PREFIX/meson_cross_file that's created in
# https://github.com/conda-forge/ctng-compiler-activation-feedstock/blob/main/recipe/activate-gcc.sh
# https://github.com/conda-forge/clang-compiler-activation-feedstock/blob/main/recipe/activate-clang.sh
# to use host python; requires that [binaries] section is last in meson_cross_file
echo "python = '${PREFIX}/bin/python'" >> ${CONDA_PREFIX}/meson_cross_file.txt

[lapack]
libraries = lapack,blas
if [[ $target_platform == "osx-arm64" ]]; then
# currently cannot properly detect long double format
# on osx-arm64 when cross-compiling in QEMU, see
# https://github.com/numpy/numpy/pull/24414
echo "[properties]" >> ${CONDA_PREFIX}/meson_cross_file.txt
echo "longdouble_format = 'IEEE_DOUBLE_LE'" >> ${CONDA_PREFIX}/meson_cross_file.txt
fi

[blas]
libraries = cblas,blas
EOF
# meson-python already sets up a -Dbuildtype=release argument to meson, so
# we need to strip --buildtype out of MESON_ARGS or fail due to redundancy
MESON_ARGS_REDUCED="$(echo $MESON_ARGS | sed 's/--buildtype release //g')"

export NPY_LAPACK_ORDER=lapack
export NPY_BLAS_ORDER=blas
# -wnx flags mean: --wheel --no-isolation --skip-dependency-check
$PYTHON -m build -w -n -x \
-Cbuilddir=builddir \
-Csetup-args=-Dblas=blas \
-Csetup-args=-Dlapack=lapack \
-Csetup-args=${MESON_ARGS_REDUCED// / -Csetup-args=} \
|| (cat builddir/meson-logs/meson-log.txt && exit 1)

$PYTHON -m pip install --no-deps --ignore-installed -v .
pip install dist/numpy*.whl
38 changes: 27 additions & 11 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% set version = "1.25.2" %}
{% set version = "1.26.0b1" %}

package:
name: numpy
Expand All @@ -9,7 +9,10 @@ package:

source:
- url: https://github.com/numpy/numpy/releases/download/v{{ version }}/numpy-{{ version }}.tar.gz
sha256: fd608e19c8d7c55021dffd43bfe5492fab8cc105cc8986f813f8c3c048b38760
sha256: c67eea90827e1e9aa220a3fc380ce8776428deba8ac9e7c931ce7b69e8dce115
patches:
# backport numpy/numpy#24414 for unblocking cross-compilation on osx-arm64
- patches/0001-BLD-allow-specifying-the-long-double-format-to-avoid.patch
# the sources by upstream themselves (as opposed to automated by github) contain the
# svml submodule (which isn't in github tarball due to dear-github/dear-github#214);
# keep this for reference & debugging when necessary; for exact commit, see:
Expand All @@ -34,13 +37,24 @@ requirements:
- python # [build_platform != target_platform]
- cross-python_{{ target_platform }} # [build_platform != target_platform]
- cython # [build_platform != target_platform]
- setuptools <60.0.0 # [build_platform != target_platform]
- ninja # [build_platform != target_platform]
- pkg-config # [build_platform != target_platform]
- {{ compiler('c') }}
- {{ compiler('cxx') }}
host:
- setuptools <60.0.0
- python
# temporarily vendored by numpy
# - meson
# - meson-python
# deps of meson-python
- pyproject-metadata
- tomli # [py<=310]
- setuptools >=60 # [py==312]
# rest
- pip
- ninja
- pkg-config
- python
- python-build
- cython
- libblas
- libcblas
Expand Down Expand Up @@ -68,12 +82,15 @@ test:
- cffi # [py<=39 and python_impl != "pypy"]
- cython
- hypothesis
- meson
- pytz
- setuptools <60.0.0
- setuptools <60.0.0 # [py<=311]
- setuptools # [py==312]
- typing_extensions
# some linux tests need a C compiler;
# some linux tests need a C/C++ compiler;
# extra f2py tests need a fortran compiler
- {{ compiler('c') }} # [linux]
- {{ compiler('cxx') }} # [linux]
- {{ compiler('fortran') }} # [linux]
commands:
- f2py -h
Expand All @@ -92,10 +109,9 @@ test:
- numpy.array_api
- numpy.array_api.linalg
- numpy.ctypeslib
- numpy.distutils
- numpy.doc
- numpy.doc.constants
- numpy.doc.ufuncs
- numpy.distutils # [py<312]
- numpy.dtypes
- numpy.exceptions
- numpy.f2py
- numpy.fft
- numpy.lib
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From 08248156eecbe2051470fda0162303a38c65f2fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Filipe=20La=C3=ADns?= <lains@riseup.net>
Date: Mon, 14 Aug 2023 15:28:17 +0100
Subject: [PATCH] BLD: allow specifying the long double format to avoid the
runtime check
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Filipe Laíns <lains@riseup.net>
---
numpy/core/meson.build | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/numpy/core/meson.build b/numpy/core/meson.build
index ccc060aac..a6c37fd23 100644
--- a/numpy/core/meson.build
+++ b/numpy/core/meson.build
@@ -377,7 +377,9 @@ endforeach
# https://github.com/numpy/numpy/blob/eead09a3d02c09374942cdc787c0b5e4fe9e7472/numpy/core/setup_common.py#L264-L434
# This port is in service of solving gh-23972
# as well as https://github.com/mesonbuild/meson/issues/11068
-longdouble_format = meson.get_compiler('c').run(
+longdouble_format = meson.get_external_property('longdouble_format', 'UNKNOWN')
+if longdouble_format == 'UNKNOWN'
+ longdouble_format = meson.get_compiler('c').run(
'''
#include <stdio.h>
#include <string.h>
@@ -456,7 +458,8 @@ int main(void) {
}
}
}
-''').stdout()
+ ''').stdout()
+endif
if longdouble_format == 'UNKNOWN' or longdouble_format == 'UNDEFINED'
error('Unknown long double format of size: ' + cc.sizeof('long double').to_string())
endif