From 4f9cc8c0afb7fa51a4e920b7f5b8a48c4b72cc07 Mon Sep 17 00:00:00 2001 From: "Andrew J. Hesford" Date: Fri, 10 Jul 2020 23:35:09 -0400 Subject: [PATCH 1/2] xbps-src: add numpy build_helper Packages that link against python3-numpy require special consideration to ensure that, in a cross-building environment, target libraries and headers as well as the FORTRAN compiler and linker are properly identifeid. Previously, this was done directly in the python3-scipy template to support cross compilation. Now, a build_helper generalizes these changes to support other package templates. --- common/build-helper/numpy.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 common/build-helper/numpy.sh diff --git a/common/build-helper/numpy.sh b/common/build-helper/numpy.sh new file mode 100644 index 00000000000..876e24296aa --- /dev/null +++ b/common/build-helper/numpy.sh @@ -0,0 +1,36 @@ +# +# numpy - build-helper for packages that compile against python3-numpy +# +# This build-helper makes sure packages can find python3-numpy libraries and +# headers on the target architecture rather than the host, as well as making +# sure the gfortran cross compiler is properly identified. + +# Even for cross compilation, numpy should be available on the host to ensure +# that the host interpreter doesn't complain about missing deps +if [[ $hostmakedepends != *"python3-numpy" ]]; then + hostmakedepends+=" python3-numpy" +fi + +if [ "$CROSS_BUILD" ]; then + if [[ $makedepends != *"python3-numpy"* ]]; then + makedepends+=" python3-numpy" + fi + + # python3-setuptools finds numpy libs and headers on the host first; + # addding search paths up front allows the target to take priority + CFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_sitelib}/numpy/core/include" + LDFLAGS+=" -L${XBPS_CROSS_BASE}/${py3_sitelib}/numpy/core/lib" + + # distutils from python3-numpy looks to environment variables F77 and + # F90 rather than the XBPS-set FC + export F77="${FC}" + export F90="${FC}" + + # When compiling and linking FORTRAN, distutils from python3-numpy + # refuses respect any linker name except "gfortran"; symlink to the + # cross-compiler to that the right linker and compiler will be used + if _gfortran=$(command -v "${FC}"); then + ln -sf "${_gfortran}" "${XBPS_WRAPPERDIR}/gfortran" + fi + unset _gfortran +fi From d20a0801563845eddddc1a4669091cd64f8385b2 Mon Sep 17 00:00:00 2001 From: "Andrew J. Hesford" Date: Fri, 10 Jul 2020 23:39:29 -0400 Subject: [PATCH 2/2] python3-scipy: use new numpy build_helper --- srcpkgs/python3-scipy/template | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/srcpkgs/python3-scipy/template b/srcpkgs/python3-scipy/template index 3d602c347c9..0554f9c7261 100644 --- a/srcpkgs/python3-scipy/template +++ b/srcpkgs/python3-scipy/template @@ -4,10 +4,10 @@ version=1.5.0 revision=2 wrksrc="scipy-${version}" build_style=python3-module +build_helper="numpy" make_check_args="--force" -hostmakedepends="gcc-fortran python3-setuptools - python3-Cython python3-numpy python3-pybind11" -makedepends="python3-devel python3-numpy python3-pybind11 +hostmakedepends="gcc-fortran python3-setuptools python3-Cython python3-pybind11" +makedepends="python3-devel python3-pybind11 $(vopt_if openblas openblas-devel lapack-devel)" depends="python3-numpy" checkdepends="python3-nose" @@ -29,25 +29,9 @@ case "$XBPS_TARGET_MACHINE" in *) ;; esac -if [ "$CROSS_BUILD" ]; then - # Make sure numpy is found for the target arch first - CFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_sitelib}/numpy/core/include" - LDFLAGS+=" -L${XBPS_CROSS_BASE}/${py3_sitelib}/numpy/core/lib" - - # Tell numpy.distutils where to find FORTRAN compilers - export F77="${FC}" - export F90="${FC}" -fi - LDFLAGS+=" -shared" pre_build() { - if [ "$CROSS_BUILD" ]; then - # numpy.distutils refuses to find the right linker for FORTRAN - # Link the cross compiler so the module will find it as gfortran - ln -sf "/usr/bin/${FC}" "${XBPS_WRAPPERDIR}/gfortran" - fi - # Find the right linear algebra subroutines on the target arch : > site.cfg for _blaslib in $(vopt_if openblas openblas "lapack blas"); do