Run core tests in Safari. Partially addresses https://github.com/pyodide/pyodide/issues/989

It runs, but there are several test failures, I'll open separate issues about those.
package:
  name: scipy
  version: 1.9.1
  top-level:
    - scipy

# See extra explanation in info.md
#
# For future reference: if you see the following errors:
#   Declaration error: adjustable dimension on non-argument
# or:
#   nonconstant array size
# you are trying to compile code that isn't written to the fortran 77 standard.
# The line number in the error points to the last line of the problematic
# subroutine. Try deleting it.

source:
  url: https://files.pythonhosted.org/packages/db/af/16906139f52bc6866c43401869ce247662739ad71afa11c6f18505eb0546/scipy-1.9.1.tar.gz
  sha256: 26d28c468900e6d5fdb37d2812ab46db0ccd22c63baa095057871faa3a498bc9

  patches:
    - patches/0001-Fix-dstevr-in-special-lapack_defs.h.patch
    - patches/0002-loadDynamicLibrary-flapack.patch
    - patches/0003-Add-lapack_extras-to-linalg-setup.py.patch
    - patches/0004-int-to-string.patch
    - patches/0005-fix-fotran-files-minpack.patch
    - patches/0006-gemm_-no-const.patch
    - patches/0007-make-int-return-values.patch
    - patches/0008-Rename-_page_trend_test.py-to-prevent-test-unvendori.patch
    - patches/0009-sasum-returns-double-not-float.patch
    - patches/0010-skip-fortran-fails-to-link.patch
    - patches/0011-Add-extra-END-to-prini.f.patch
    - patches/0012-Change-qh_eachvoronoi_all-FILE-type.patch
    - patches/0013-Remove-meson-requirements.patch
    - patches/0014-Fix-fitpack.patch
    - patches/0015-Cast-linear_sum_assignment-to-PyCFunction.patch

build:
  cflags: |
    -I$(WASM_LIBRARY_DIR)/CLAPACK/INCLUDE
    -I$(HOSTSITEPACKAGES)/pythran/
    -Wno-return-type
    -DUNDERSCORE_G77
  ldflags: |
    -L$(NUMPY_LIB)/core/lib/
    -L$(NUMPY_LIB)/random/lib/
  # IMPORTANT: Other locations important in scipy build process:
  # There are two files built in the "capture" pass that need patching:
  #    _blas_subroutines.h, and _cython
  # Scipy has a bunch of custom logic implemented in
  # pyodide-build/pyodide_build/_f2c_fixes.py.
  script: |
    set -x
    export PKG_CONFIG_LIBDIR=$WASM_PKG_CONFIG_PATH
    export NPY_BLAS_LIBS="-I$WASM_LIBRARY_DIR/CLAPACK/INCLUDE $WASM_LIBRARY_DIR/CLAPACK/LIB/clapack_all.so"
    export NPY_LAPACK_LIBS="-I$WASM_LIBRARY_DIR/CLAPACK/INCLUDE"

    pip install -t $HOSTSITEPACKAGES pythran
    # We get linker errors because the following 36 functions are missing
    # Copying them from a more recent LAPACK seems to work fine.
    wget https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.10.0.tar.gz
    tar xzf v3.10.0.tar.gz
    cd lapack-3.10.0/SRC

    cat \
      cgemqrt.f cgeqrfp.f cgeqrt.f clahqr.f csyconv.f csyconvf.f csyconvf_rook.f ctpmqrt.f ctpqrt.f cuncsd.f \
      dgemqrt.f dgeqrfp.f dgeqrt.f dlahqr.f dsyconv.f dsyconvf.f dsyconvf_rook.f dtpmqrt.f dtpqrt.f dorcsd.f \
      sgemqrt.f sgeqrfp.f sgeqrt.f slahqr.f ssyconv.f ssyconvf.f ssyconvf_rook.f stpmqrt.f stpqrt.f sorcsd.f \
      zgemqrt.f zgeqrfp.f zgeqrt.f zlahqr.f zsyconv.f zsyconvf.f zsyconvf_rook.f ztpmqrt.f ztpqrt.f zuncsd.f \
    >>  ../../scipy/linalg/lapack_extras.f
    cd ../..
    sed -i 's/CHARACTER/INTEGER/g' scipy/linalg/lapack_extras.f
    sed -i 's/RECURSIVE//g' scipy/linalg/lapack_extras.f
    sed -i 's/recursive //g' scipy/integrate/quadpack/* scipy/interpolate/fitpack/*

    # Change many functions that return void into functions that return int
    find scipy -name "*.c*" -type f | xargs sed -i 's/extern void F_FUNC/extern int F_FUNC/g'

    sed -i 's/void F_FUNC/int F_FUNC/g' scipy/odr/__odrpack.c
    sed -i 's/^void/int/g' scipy/odr/odrpack.h
    sed -i 's/^void/int/g' scipy/odr/__odrpack.c

    sed -i 's/void BLAS_FUNC/int BLAS_FUNC/g' scipy/special/lapack_defs.h
    # sed -i 's/void F_FUNC/int F_FUNC/g' scipy/linalg/_lapack_subroutines.h
    sed -i 's/extern void/extern int/g' scipy/optimize/__minpack.h
    sed -i 's/void/int/g' scipy/linalg/cython_blas_signatures.txt
    sed -i 's/^void/int/g' scipy/interpolate/src/_fitpackmodule.c

    sed -i 's/^void/int/g' scipy/optimize/_trlib/trlib_private.h
    sed -i 's/^void/int/g' scipy/optimize/_trlib/trlib/trlib_private.h
    sed -i 's/, int)/)/g' scipy/optimize/_trlib/trlib_private.h
    sed -i 's/, 1)/)/g' scipy/optimize/_trlib/trlib_private.h

    sed -i 's/^void/int/g' scipy/spatial/qhull_misc.h
    sed -i 's/, size_t)/)/g' scipy/spatial/qhull_misc.h
    sed -i 's/,1)/)/g' scipy/spatial/qhull_misc.h


    # Missing declaration from cython_lapack_signatures.txt
    echo "void ilaenv(int *ispec, char *name, char *opts, int *n1, int *n2, int *n3, int *n4)" \
      >>  scipy/linalg/cython_lapack_signatures.txt

    # sed -i 's/^void/int/g' scipy/linalg/cython_lapack_signatures.txt

    # Input error causes "duplicate symbol" linker errors. Empty out the file.
    echo "" > scipy/sparse/linalg/_dsolve/SuperLU/SRC/input_error.c
  cross-build-env: true
  cross-build-files:
    - scipy/linalg/cython_lapack.pxd
    - scipy/linalg/cython_blas.pxd

requirements:
  host:
    - numpy
    - CLAPACK
  run:
    - numpy
    - CLAPACK

test:
  imports:
    - scipy
    - scipy.cluster
    - scipy.cluster.vq
    - scipy.cluster.hierarchy
    - scipy.constants
    - scipy.fft
    - scipy.fftpack
    - scipy.integrate
    - scipy.interpolate
    - scipy.io
    - scipy.io.arff
    - scipy.io.matlab
    - scipy.io.wavfile
    - scipy.linalg
    - scipy.linalg.blas
    - scipy.linalg.cython_blas
    - scipy.linalg.lapack
    - scipy.linalg.cython_lapack
    - scipy.linalg.interpolative
    - scipy.misc
    - scipy.ndimage
    - scipy.odr
    - scipy.optimize
    - scipy.signal
    - scipy.signal.windows
    - scipy.sparse
    - scipy.sparse.linalg
    - scipy.sparse.csgraph
    - scipy.spatial
    - scipy.spatial.distance
    - scipy.spatial.transform
    - scipy.special
    - scipy.stats
    - scipy.stats.contingency
    - scipy.stats.distributions
    - scipy.stats.mstats
    - scipy.stats.qmc
about:
  home: https://www.scipy.org
  PyPI: https://pypi.org/project/scipy
  summary: "SciPy: Scientific Library for Python"
  license: BSD

package:
  name: scipy
  version: 1.9.1
  top-level:
    - scipy

# See extra explanation in info.md
#
# For future reference: if you see the following errors:
#   Declaration error: adjustable dimension on non-argument
# or:
#   nonconstant array size
# you are trying to compile code that isn't written to the fortran 77 standard.
# The line number in the error points to the last line of the problematic
# subroutine. Try deleting it.

source:
  url: https://files.pythonhosted.org/packages/db/af/16906139f52bc6866c43401869ce247662739ad71afa11c6f18505eb0546/scipy-1.9.1.tar.gz
  sha256: 26d28c468900e6d5fdb37d2812ab46db0ccd22c63baa095057871faa3a498bc9

  patches:
    - patches/0001-Fix-dstevr-in-special-lapack_defs.h.patch
    - patches/0002-loadDynamicLibrary-flapack.patch
    - patches/0003-Add-lapack_extras-to-linalg-setup.py.patch
    - patches/0004-int-to-string.patch
    - patches/0005-fix-fotran-files-minpack.patch
    - patches/0006-gemm_-no-const.patch
    - patches/0007-make-int-return-values.patch
    - patches/0008-Rename-_page_trend_test.py-to-prevent-test-unvendori.patch
    - patches/0009-sasum-returns-double-not-float.patch
    - patches/0010-skip-fortran-fails-to-link.patch
    - patches/0011-Add-extra-END-to-prini.f.patch
    - patches/0012-Change-qh_eachvoronoi_all-FILE-type.patch
    - patches/0013-Remove-meson-requirements.patch
    - patches/0014-Fix-fitpack.patch
    - patches/0015-Cast-linear_sum_assignment-to-PyCFunction.patch

build:
  cflags: |
    -I$(WASM_LIBRARY_DIR)/CLAPACK/INCLUDE
    -I$(HOSTSITEPACKAGES)/pythran/
    -Wno-return-type
    -DUNDERSCORE_G77
  ldflags: |
    -L$(NUMPY_LIB)/core/lib/
    -L$(NUMPY_LIB)/random/lib/
  # IMPORTANT: Other locations important in scipy build process:
  # There are two files built in the "capture" pass that need patching:
  #    _blas_subroutines.h, and _cython
  # Scipy has a bunch of custom logic implemented in
  # pyodide-build/pyodide_build/_f2c_fixes.py.
  script: |
    set -x
    export PKG_CONFIG_LIBDIR=$WASM_PKG_CONFIG_PATH
    export NPY_BLAS_LIBS="-I$WASM_LIBRARY_DIR/CLAPACK/INCLUDE $WASM_LIBRARY_DIR/CLAPACK/LIB/clapack_all.so"
    export NPY_LAPACK_LIBS="-I$WASM_LIBRARY_DIR/CLAPACK/INCLUDE"

    pip install -t $HOSTSITEPACKAGES pythran
    # We get linker errors because the following 36 functions are missing
    # Copying them from a more recent LAPACK seems to work fine.
    wget https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.10.0.tar.gz
    tar xzf v3.10.0.tar.gz
    cd lapack-3.10.0/SRC

    cat \
      cgemqrt.f cgeqrfp.f cgeqrt.f clahqr.f csyconv.f csyconvf.f csyconvf_rook.f ctpmqrt.f ctpqrt.f cuncsd.f \
      dgemqrt.f dgeqrfp.f dgeqrt.f dlahqr.f dsyconv.f dsyconvf.f dsyconvf_rook.f dtpmqrt.f dtpqrt.f dorcsd.f \
      sgemqrt.f sgeqrfp.f sgeqrt.f slahqr.f ssyconv.f ssyconvf.f ssyconvf_rook.f stpmqrt.f stpqrt.f sorcsd.f \
      zgemqrt.f zgeqrfp.f zgeqrt.f zlahqr.f zsyconv.f zsyconvf.f zsyconvf_rook.f ztpmqrt.f ztpqrt.f zuncsd.f \
    >>  ../../scipy/linalg/lapack_extras.f
    cd ../..
    sed -i 's/CHARACTER/INTEGER/g' scipy/linalg/lapack_extras.f
    sed -i 's/RECURSIVE//g' scipy/linalg/lapack_extras.f
    sed -i 's/recursive //g' scipy/integrate/quadpack/* scipy/interpolate/fitpack/*

    # Change many functions that return void into functions that return int
    find scipy -name "*.c*" -type f | xargs sed -i 's/extern void F_FUNC/extern int F_FUNC/g'

    sed -i 's/void F_FUNC/int F_FUNC/g' scipy/odr/__odrpack.c
    sed -i 's/^void/int/g' scipy/odr/odrpack.h
    sed -i 's/^void/int/g' scipy/odr/__odrpack.c

    sed -i 's/void BLAS_FUNC/int BLAS_FUNC/g' scipy/special/lapack_defs.h
    # sed -i 's/void F_FUNC/int F_FUNC/g' scipy/linalg/_lapack_subroutines.h
    sed -i 's/extern void/extern int/g' scipy/optimize/__minpack.h
    sed -i 's/void/int/g' scipy/linalg/cython_blas_signatures.txt
    sed -i 's/^void/int/g' scipy/interpolate/src/_fitpackmodule.c

    sed -i 's/^void/int/g' scipy/optimize/_trlib/trlib_private.h
    sed -i 's/^void/int/g' scipy/optimize/_trlib/trlib/trlib_private.h
    sed -i 's/, int)/)/g' scipy/optimize/_trlib/trlib_private.h
    sed -i 's/, 1)/)/g' scipy/optimize/_trlib/trlib_private.h

    sed -i 's/^void/int/g' scipy/spatial/qhull_misc.h
    sed -i 's/, size_t)/)/g' scipy/spatial/qhull_misc.h
    sed -i 's/,1)/)/g' scipy/spatial/qhull_misc.h


    # Missing declaration from cython_lapack_signatures.txt
    echo "void ilaenv(int *ispec, char *name, char *opts, int *n1, int *n2, int *n3, int *n4)" \
      >>  scipy/linalg/cython_lapack_signatures.txt

    # sed -i 's/^void/int/g' scipy/linalg/cython_lapack_signatures.txt

    # Input error causes "duplicate symbol" linker errors. Empty out the file.
    echo "" > scipy/sparse/linalg/_dsolve/SuperLU/SRC/input_error.c
  cross-build-env: true
  cross-build-files:
    - scipy/linalg/cython_lapack.pxd
    - scipy/linalg/cython_blas.pxd

requirements:
  host:
    - numpy
    - CLAPACK
  run:
    - numpy
    - CLAPACK

test:
  imports:
    - scipy
    - scipy.cluster
    - scipy.cluster.vq
    - scipy.cluster.hierarchy
    - scipy.constants
    - scipy.fft
    - scipy.fftpack
    - scipy.integrate
    - scipy.interpolate
    - scipy.io
    - scipy.io.arff
    - scipy.io.matlab
    - scipy.io.wavfile
    - scipy.linalg
    - scipy.linalg.blas
    - scipy.linalg.cython_blas
    - scipy.linalg.lapack
    - scipy.linalg.cython_lapack
    - scipy.linalg.interpolative
    - scipy.misc
    - scipy.ndimage
    - scipy.odr
    - scipy.optimize
    - scipy.signal
    - scipy.signal.windows
    - scipy.sparse
    - scipy.sparse.linalg
    - scipy.sparse.csgraph
    - scipy.spatial
    - scipy.spatial.distance
    - scipy.spatial.transform
    - scipy.special
    - scipy.stats
    - scipy.stats.contingency
    - scipy.stats.distributions
    - scipy.stats.mstats
    - scipy.stats.qmc
about:
  home: https://www.scipy.org
  PyPI: https://pypi.org/project/scipy
  summary: "SciPy: Scientific Library for Python"
  license: BSD
