Merge pull request #108 from kivy/support-numpy

Numpy support / recipe
This commit is contained in:
Mathieu Virbel 2014-11-24 03:31:02 +01:00
commit a96f38ea77
7 changed files with 142 additions and 3 deletions

1
.gitignore vendored
View file

@ -13,5 +13,4 @@ app-*
src/ios/build/
src/ios/iosbuild/
src/ios/ios.c
*.DS_Store*

56
src/numpy-1.9.1.patch Normal file
View file

@ -0,0 +1,56 @@
diff -Naur numpy-1.9.1.orig/numpy/core/include/numpy/npy_endian.h numpy-1.9.1.ios/numpy/core/include/numpy/npy_endian.h
--- numpy-1.9.1.orig/numpy/core/include/numpy/npy_endian.h 2014-10-26 15:36:14.000000000 +0100
+++ numpy-1.9.1.ios/numpy/core/include/numpy/npy_endian.h 2014-11-24 01:59:52.000000000 +0100
@@ -6,7 +6,10 @@
* endian.h
*/
-#ifdef NPY_HAVE_ENDIAN_H
+
+//#ifdef NPY_HAVE_ENDIAN_H
+//XXX iOS fix, it detects endian.h, but weird detection happen during the compilation
+#if 0
/* Use endian.h if available */
#include <endian.h>
diff -Naur numpy-1.9.1.orig/numpy/core/setup.py numpy-1.9.1.ios/numpy/core/setup.py
--- numpy-1.9.1.orig/numpy/core/setup.py 2014-10-26 17:22:33.000000000 +0100
+++ numpy-1.9.1.ios/numpy/core/setup.py 2014-11-24 01:58:43.000000000 +0100
@@ -951,6 +951,9 @@
blas_info = get_info('blas_opt', 0)
#blas_info = {}
def get_dotblas_sources(ext, build_dir):
+ # XXX no blas for iOS, maybe it's not needed anymore as our recipe do
+ # BLAS=None
+ return None
if blas_info:
if ('NO_ATLAS_INFO', 1) in blas_info.get('define_macros', []):
return None # dotblas needs ATLAS, Fortran compiled blas will not be sufficient.
diff -Naur numpy-1.9.1.orig/numpy/linalg/setup.py numpy-1.9.1.ios/numpy/linalg/setup.py
--- numpy-1.9.1.orig/numpy/linalg/setup.py 2014-10-26 15:36:15.000000000 +0100
+++ numpy-1.9.1.ios/numpy/linalg/setup.py 2014-11-24 01:57:48.000000000 +0100
@@ -34,8 +34,14 @@
return ext.depends[:1]
return ext.depends[:2]
+ def get_lapack_lite_sources_ios(ext, build_dir):
+ return ext.depends[:-1]
+
+ def get_umath_linalg_ios(ext, build_dir):
+ return ext.depends[:1]
+
config.add_extension('lapack_lite',
- sources = [get_lapack_lite_sources],
+ sources = [get_lapack_lite_sources_ios],
depends = ['lapack_litemodule.c'] + lapack_lite_src,
extra_info = lapack_info
)
@@ -43,7 +49,7 @@
# umath_linalg module
config.add_extension('_umath_linalg',
- sources = [get_lapack_lite_sources],
+ sources = [get_umath_linalg_ios],
depends = ['umath_linalg.c.src'] + lapack_lite_src,
extra_info = lapack_info,
libraries = ['npymath'],

View file

@ -47,3 +47,6 @@ _sqlite3 -DSQLITE_OMIT_LOAD_EXTENSION _sqlite/cache.c _sqlite/microprotocols.c _
# Include expat
pyexpat expat/xmlparse.c expat/xmlrole.c expat/xmltok.c pyexpat.c -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI
# Future (used by numpy)
future_builtins future_builtins.c

71
tools/build-numpy.sh Executable file
View file

@ -0,0 +1,71 @@
#!/bin/bash
. $(dirname $0)/environment.sh
if [ ! -f $CACHEROOT/numpy-$NUMPY_VERSION.tar.gz ] ; then
try curl -L http://pypi.python.org/packages/source/n/numpy/numpy-$NUMPY_VERSION.tar.gz > $CACHEROOT/numpy-$NUMPY_VERSION.tar.gz
fi
if [ ! -d $TMPROOT/numpy-$NUMPY_VERSION ]; then
cd $TMPROOT
try tar -xvf $CACHEROOT/numpy-$NUMPY_VERSION.tar.gz
try cd numpy-$NUMPY_VERSION
try patch -p1 < $KIVYIOSROOT/src/numpy-$NUMPY_VERSION.patch
try cd ../..
fi
# Save current flags
OLD_CC="$CC"
OLD_CFLAGS="$CFLAGS"
OLD_LDFLAGS="$LDFLAGS"
OLD_LDSHARED="$LDSHARED"
export CC="$ARM_CC -I$BUILDROOT/include"
export CFLAGS="$ARM_CFLAGS"
export LDFLAGS="$ARM_LDFLAGS"
export LDSHARED="$KIVYIOSROOT/tools/liblink"
# CC must have the CFLAGS with arm arch, because numpy tries first to compile
# and execute an empty C to see if the compiler works. This is obviously not
# working when crosscompiling
export CC="$ARM_CC $CFLAGS"
# Numpy configuration. Don't try to compile anything related to it, we're
# going to use the Accelerate framework
NPYCONFIG="env BLAS=None LAPACK=None ATLAS=None"
try pushd $TMPROOT/numpy-$NUMPY_VERSION
try $NPYCONFIG $HOSTPYTHON setup.py build_ext -v
try $NPYCONFIG $HOSTPYTHON setup.py install -O2 --root iosbuild
try find iosbuild | grep -E '.*\.(py|pyc|so\.o|so\.a|so\.libs)$$' | xargs rm
try rm -rf iosbuild/usr/local/lib/python2.7/site-packages/numpy/core/include
try rm -rf iosbuild/usr/local/lib/python2.7/site-packages/numpy/core/tests
try rm -rf iosbuild/usr/local/lib/python2.7/site-packages/numpy/distutils
try rm -rf iosbuild/usr/local/lib/python2.7/site-packages/numpy/doc
try rm -rf iosbuild/usr/local/lib/python2.7/site-packages/numpy/f2py/tests
try rm -rf iosbuild/usr/local/lib/python2.7/site-packages/numpy/fft/tests
try rm -rf iosbuild/usr/local/lib/python2.7/site-packages/numpy/lib/tests
try rm -rf iosbuild/usr/local/lib/python2.7/site-packages/numpy/ma/tests
try rm -rf iosbuild/usr/local/lib/python2.7/site-packages/numpy/matrixlib/tests
try rm -rf iosbuild/usr/local/lib/python2.7/site-packages/numpy/polynomial/tests
try rm -rf iosbuild/usr/local/lib/python2.7/site-packages/numpy/random/tests
try rm -rf iosbuild/usr/local/lib/python2.7/site-packages/numpy/tests
if [ -d "$BUILDROOT/python/lib/python2.7/site-packages/numpy" ]; then
rm -rf $BUILDROOT/python/lib/python2.7/site-packages
fi
try cp -a iosbuild/usr/local/lib/python2.7/site-packages/numpy "$BUILDROOT/python/lib/python2.7/site-packages/"
popd
# Restore the old compilation flags
export CC="$OLD_CC"
export CFLAGS="$OLD_CFLAGS"
export LDFLAGS="$OLD_LDFLAGS"
export LDSHARED="$OLD_LDSHARED"
# Create the static library
bd=$TMPROOT/numpy-$NUMPY_VERSION/build/lib.macosx-*/numpy
rm -f $BUILDROOT/lib/libnumpy.a
try $KIVYIOSROOT/tools/biglink $BUILDROOT/lib/libnumpy.a \
$bd/core $bd/lib $bd/fft $bd/linalg $bd/random
deduplicate \
$BUILDROOT/lib/libnumpy.a \
$TMPROOT/numpy-$NUMPY_VERSION/build/temp.macosx-*/libnpymath.a \
$TMPROOT/numpy-$NUMPY_VERSION/build/temp.macosx-*/libnpysort.a

View file

@ -38,6 +38,7 @@ export XML2_VERSION=2.7.8
export XSLT_VERSION=1.1.26
export LXML_VERSION=2.3.1
export FFI_VERSION=3.0.13
export NUMPY_VERSION=1.9.1
# where the build will be located
export KIVYIOSROOT="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
@ -118,10 +119,16 @@ function deduplicate() {
echo "== Trying to remove duplicate symbol in $1"
try mkdir ddp
try cd ddp
try ar x $1
for var in "$@"; do
echo " - extracting $var"
try ar x $var
done
echo " - create the archive"
try ar rc $fn *.o
echo " - finalize the archive"
try ranlib $fn
try mv -f $fn $1
try cd ..
try rm -rf ddp
echo " - done: $1 updated"
}

View file

@ -52,6 +52,9 @@ while i < len(sys.argv):
if opt.startswith('-arch'):
continue
if opt.startswith("-Wl,"):
continue
if opt.startswith("-"):
print(sys.argv)
print("Unknown option: ", opt)

View file

@ -17,7 +17,7 @@ try cd $BUILDROOT/python/lib/python2.7
find . -iname '*.pyc' | xargs rm
find . -iname '*.py' | xargs rm
find . -iname 'test*' | xargs rm -rf
rm -rf *test* lib* wsgiref bsddb curses idlelib hotshot || true
rm -rf lib* wsgiref bsddb curses idlelib hotshot || true
try cd ..
rm -rf pkgconfig || true