forked from beeware/Python-Apple-support
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add matplotlib #4
Comments
Step A Build Freetype
#!/bin/sh
# based on https://gist.github.com/ayansg/066f3ad7c84f9fd5f61651fc0d099bc3
PROJECT_DIR=$(pwd)
APP_PKGS=$PROJECT_DIR/dist/iOS/app_packages
PYTHON_VERSION=3.7.0
PYTHON_VER=3.7
CFLAGS_iOS=-mios-version-min=8.2
CFLAGS_iphoneos_arm64=-fembed-bitcode
CFLAGS_iphonesimulator_x86_64=-fembed-bitcode
FREETYPE_VERSION=2.9.1
BUILD_DIR=$PROJECT_DIR/build/iOS/freetype-$FREETYPE_VERSION
mkdir -p ${BUILD_DIR}
cd $BUILD_DIR
# Download original freetype source code archive.
if [ ! -e $PROJECT_DIR/downloads/freetype-$FREETYPE_VERSION.tgz ]; then curl --fail -L http://savannah.spinellicreations.com/freetype/freetype-$FREETYPE_VERSION.tar.gz -o $PROJECT_DIR/downloads/freetype-$FREETYPE_VERSION.tgz; fi
# unpack
mkdir -p $BUILD_DIR
tar zxf $PROJECT_DIR/downloads/freetype-$FREETYPE_VERSION.tgz --strip-components 1 -C $BUILD_DIR
cd $BUILD_DIR
echo $(pwd)
XCODE_ROOT=$(xcode-select -print-path)
red=$'\e[1;31m'
grn=$'\e[1;32m'
yel=$'\e[1;33m'
blu=$'\e[1;34m'
mag=$'\e[1;35m'
cyn=$'\e[1;36m'
end=$'\e[0m'
set -e
# do not increase this version number.
iphoneos="8.2"
# do not increase this version number.
ARCH="arm64"
printf "%s\n" "${blu}building iphoneos arm64${end}"
export CC=$(xcrun -sdk iphoneos -find clang)
export CFLAGS="-arch ${ARCH} -pipe -fembed-bitcode -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=$iphoneos -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
export AR="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar"
export LDFLAGS="-arch ${ARCH} -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -miphoneos-version-min=$iphoneos"
./configure --without-harfbuzz --host="aarch64-apple-darwin" --enable-static=yes --enable-shared=no
make clean
make
cp objs/.libs/libfreetype.a "${BUILD_DIR}/libfreetype-${ARCH}.a"
ARCH="x86_64"
printf "%s\n" "${blu}building iphonesimulator x86_64${end}"
export CC=$(xcrun -sdk iphonesimulator -find clang)
export CFLAGS="-arch ${ARCH} -pipe -fembed-bitcode=marker -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=$iphoneos -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
export LDFLAGS="-arch ${ARCH} -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk -miphoneos-version-min=$iphoneos"
./configure --without-harfbuzz --disable-shared --enable-static --host="${ARCH}-apple-darwin"
make clean
make
cp objs/.libs/libfreetype.a "${BUILD_DIR}/libfreetype-${ARCH}.a"
printf "%s\n" "${blu}building fatlib${end}"
OUT_A=$PROJECT_DIR/dist/iOS/libfreetype.a
lipo -create "${BUILD_DIR}/libfreetype-arm64.a" "${BUILD_DIR}/libfreetype-x86_64.a" -output $OUT_A
printf "%s\n" "${grn}$(lipo -info $OUT_A)${end}" Step B Build libpng
#!/bin/sh
PROJECT_DIR=$(pwd)
APP_PKGS=$PROJECT_DIR/dist/iOS/app_packages
MACOSX_DEPLOYMENT_TARGET=10.14
PYTHON_VERSION=3.7.0
PYTHON_VER=3.7
CFLAGS_iOS=-mios-version-min=11.0
CFLAGS_iphoneos_arm64=-fembed-bitcode
CFLAGS_iphonesimulator_x86_64=-fembed-bitcode
PYTHON_DIR_macOS=build/macOS/Python-$PYTHON_VERSION-macosx.x86_64
PYTHON_HOST=$PYTHON_DIR_macOS/dist/lib/libpython$PYTHON_VERm.a
LPNG_VERSION=1.6.37
XCODE_ROOT=$(xcode-select -print-path)
mkdir -p $PROJECT_DIR/dist/iOS/
#### KIND OF RESET BUILD ENVIRONMENT, BY CHANGING DIR BACK TO ORIGIN
cd $PROJECT_DIR
#### KIND OF RESET BUILD ENVIRONMENT, BY CHANGING DIR BACK TO ORIGIN
# Download original libpng source code archive.
if [ ! -e downloads/libpng-$LPNG_VERSION.tgz ]; then curl --fail -L https://sourceforge.net/projects/libpng/files/libpng16/$LPNG_VERSION/libpng-$LPNG_VERSION.tar.gz/download -o downloads/libpng-$LPNG_VERSION.tgz; fi
# unpack
mkdir -p build/iOS/libpng-$LPNG_VERSION
tar zxf downloads/libpng-$LPNG_VERSION.tgz --strip-components 1 -C build/iOS/libpng-$LPNG_VERSION
# configure and build arm64 iphoneos
echo "building iphoneos arm64"
export CC=$(xcrun -sdk iphoneos -find clang)
export SDKROOT=$(xcrun --sdk iphoneos --show-sdk-path)
export CFLAGS="-O3 -Qunused-arguments -arch arm64 -pipe -no-cpp-precomp -isysroot $SDKROOT $CFLAGS_iOS $CFLAGS_iphoneos_arm64"
export CPPFLAGS=$CFLAGS
export CXXFLAGS="$CFLAGS -Wno-deprecated-register"
mkdir -p $PROJECT_DIR/build/iOS/libpng-$LPNG_VERSION/iphoneos
cd $PROJECT_DIR/build/iOS/libpng-$LPNG_VERSION/iphoneos
../configure --host=arm-apple-darwin64 --enable-shared=no --prefix=$PROJECT_DIR/build/iOS/libpng-$LPNG_VERSION/iphoneos/ios-arm64
make -sj8
make install
make distclean
# configure and build x86_64 iphonesimulator
echo "building iphonesimulator x86_64"
export CC=$(xcrun -sdk iphonesimulator -find clang)
export SDKROOT=$(xcrun --sdk iphonesimulator --show-sdk-path)
export CFLAGS="-O3 -Qunused-arguments -arch x86_64 -pipe -no-cpp-precomp -isysroot $SDKROOT $CFLAGS_iOS $CFLAGS_iphonesimulator_x86_64"
export CPPFLAGS=$CFLAGS
export CXXFLAGS="$CFLAGS -Wno-deprecated-register"
mkdir -p $PROJECT_DIR/build/iOS/libpng-$LPNG_VERSION/iphoneos
cd $PROJECT_DIR/build/iOS/libpng-$LPNG_VERSION/iphoneos
../configure --host x86_64-apple-darwin --enable-shared=no -prefix=$PROJECT_DIR/build/iOS/libpng-$LPNG_VERSION/iphoneos/simulator-x86_64
make -sj8
make install
make distclean
# make fatlib
OUT_A=$PROJECT_DIR/dist/iOS/libpng.a
xcrun lipo $PROJECT_DIR/build/iOS/libpng-$LPNG_VERSION/iphoneos/ios-arm64/lib/libpng.a $PROJECT_DIR/build/iOS/libpng-$LPNG_VERSION/iphoneos/simulator-x86_64/lib/libpng.a -create -output $OUT_A Step C build kiwisolver#!/bin/sh
PROJECT_DIR=$(pwd)
APP_PKGS=$PROJECT_DIR/dist/iOS/app_packages
MACOSX_DEPLOYMENT_TARGET=10.14
PYTHON_VERSION=3.7.0
PYTHON_VER=3.7
CFLAGS_iOS=-mios-version-min=12.2
CFLAGS_iphoneos_arm64=-fembed-bitcode
CFLAGS_iphonesimulator_x86_64=-fembed-bitcode
# override machine types for arm64
MACHINE_DETAILED_arm64=aarch64
MACHINE_SIMPLE_arm64=arm
PYTHON_DIR_macOS=$PROJECT_DIR/build/macOS/Python-$PYTHON_VERSION-macosx.x86_64
PYTHON_HOST=$PYTHON_DIR_macOS/dist/lib/libpython$PYTHON_VERm.a
KIWI_VERSION=1.1.0
XCODE_ROOT=$(xcode-select -print-path)
export CC=$XCODE_ROOT/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
HOST_PYTHON=$PROJECT_DIR/build/macOS/python/bin/python3
HOST_PIP=$PROJECT_DIR/build/macOS/python/bin/pip3
red=$'\e[1;31m'
grn=$'\e[1;32m'
yel=$'\e[1;33m'
blu=$'\e[1;34m'
mag=$'\e[1;35m'
cyn=$'\e[1;36m'
end=$'\e[0m'
BUILD_DIR=$PROJECT_DIR/build/iOS/kiwi-$KIWI_VERSION
# Download original kiwisikver source code archive.
if [ ! -e $PROJECT_DIR/downloads/kiwi-$KIWI_VERSION.tgz ]; then curl --fail -L https://github.com/nucleic/kiwi/archive/$KIWI_VERSION.tar.gz -o $PROJECT_DIR/downloads/kiwi-$KIWI_VERSION.tgz; fi
# unpack
mkdir -p $BUILD_DIR
tar zxf $PROJECT_DIR/downloads/kiwi-$KIWI_VERSION.tgz --strip-components 1 -C $BUILD_DIR
cd $BUILD_DIR
echo $(pwd)
# Now builds
# Help on compiler flags https://towardsdatascience.com/how-to-shrink-numpy-scipy-pandas-and-matplotlib-for-your-data-product-4ec8d7e86ee4
printf "%s\n" "${blu}building iphoneos arm64${end}"
export CC=$(xcrun -sdk iphoneos -find clang)
export AR=$(xcrun -sdk iphoneos -find ar)
export SDKROOT=$(xcrun --sdk iphoneos --show-sdk-path)
export CFLAGS="-arch arm64 -isysroot $SDKROOT $CFLAGS_iOS -g0 -O2 -I$SDKROOT -I$PROJECT_DIR/build/iOS/libpng-1.6.37/ -I$PROJECT_DIR/build/iOS/freetype-2.9.1/include -I$PROJECT_DIR/build/iOS/packages/numpy/numpy/core/inlcude/numpy -Wall"
export LDFLAGS="-arch arm64 -L$PROJECT_DIR/dist/iOS/ -isysroot $SDKROOT $CFLAGS_iOS -Wall -v -r"
cd $PROJECT_DIR/build/iOS/kiwi-$KIWI_VERSION
$HOST_PYTHON setup.py build_ext
find . -name "*.o" | xargs $AR -q libkiwisolver-arm64.a
# RESET THE BUILD OUTCOME FOR NEW BUILD
rm -rf $BUILD_DIR/build/
# RESET THE BUILD OUTCOME FOR NEW BUILD
printf "%s\n" "${blu}building iphonesimulator x86_64${end}"
export CC=$(xcrun -sdk iphonesimulator -find clang)
export AR=$(xcrun -sdk iphonesimulator -find ar)
export SDKROOT=$(xcrun --sdk iphonesimulator --show-sdk-path)
export CFLAGS="-arch x86_64 -isysroot $SDKROOT $CFLAGS_iOS -g0 -O2 -I$SDKROOT -I$PROJECT_DIR/build/iOS/libpng-1.6.37/ -I$PROJECT_DIR/build/iOS/freetype-2.9.1/include -I$PROJECT_DIR/build/iOS/packages/numpy/numpy/core/inlcude/numpy -Wall"
export LDFLAGS="-arch x86_64 -L$PROJECT_DIR/dist/iOS/ -isysroot $SDKROOT $CFLAGS_iOS -Wall -v -r"
cd $PROJECT_DIR/build/iOS/kiwi-$KIWI_VERSION
$HOST_PYTHON setup.py build_ext
find . -name "*.o" | xargs $AR -q libkiwisolver-x86_64.a
cd $PROJECT_DIR/build/iOS/kiwi-$KIWI_VERSION
$HOST_PYTHON setup.py install
## copy from site-package folder
# make fatlib
echo "making fat lib"
OUT_A=$PROJECT_DIR/dist/iOS/libkiwisolver.a
xcrun lipo $PROJECT_DIR/dist/iOS/libkiwisolver-arm64.a $PROJECT_DIR/dist/iOS/libkiwisolver-x86_64.a -create -output $OUT_A Step D build matplolib
#!/bin/sh
###########################################################################
# Matplotlib
# Matplotlib requires the following dependencies:
# via Python-Apple-Support:
# - `Python <https://www.python.org/downloads/>`_ (>= 3.5)
# - `NumPy <http://www.numpy.org>`_ (>= |minimum_numpy_version|)
# - `setuptools <https://setuptools.readthedocs.io/en/latest/>`_
# compile:
# - `FreeType <https://www.freetype.org/>`_ (>= 2.3)
# - `libpng <http://www.libpng.org>`_ (>= 1.2)
# pure-python:
# - `cycler <http://matplotlib.org/cycler/>`_ (>= 0.10.0)
# - `dateutil <https://pypi.python.org/pypi/python-dateutil>`_ (>= 2.1)
# - `kiwisolver <https://github.com/nucleic/kiwi>`_ (>= 1.0.0)
# - `pyparsing <https://pyparsing.wikispaces.com/>`_
##########################################################################
PROJECT_DIR=$(pwd)
APP_PKGS=$PROJECT_DIR/dist/iOS/app_packages
MACOSX_DEPLOYMENT_TARGET=10.14
PYTHON_VERSION=3.7.0
PYTHON_VER=3.7
CFLAGS_iOS=-mios-version-min=11.0
CFLAGS_iphoneos_arm64=-fembed-bitcode
CFLAGS_iphonesimulator_x86_64=-fembed-bitcode
# override machine types for arm64
MACHINE_DETAILED_arm64=aarch64
MACHINE_SIMPLE_arm64=arm
PYTHON_DIR_macOS=build/macOS/Python-$PYTHON_VERSION-macosx.x86_64
PYTHON_HOST=$PYTHON_DIR_macOS/dist/lib/libpython$PYTHON_VERm.a
MPL_VERSION=3.0.2
LPNG_VERSION=1.6.37
FREETYPE_VERSION=2.10.0
XCODE_ROOT=$(xcode-select -print-path)
export CC=$XCODE_ROOT/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
###########################################################################
# Compile all supporting libs that need to be provided.
###########################################################################
###########################################################################
# a) libpng
###########################################################################
#"$PROJECT_DIR/build_libpng.sh"
###########################################################################
# b) freetype
###########################################################################
# "$PROJECT_DIR/build_freetype.sh"
# skipped for now. results of https://gist.github.com/ayansg/066f3ad7c84f9fd5f61651fc0d099bc3
# were placed at PROJECT_DIR=$(pwd)/dist/iOS
###########################################################################
# Install all python dependencies.
###########################################################################
HOST_PYTHON=$PROJECT_DIR/build/macOS/python/bin/python3
HOST_PIP=$PROJECT_DIR/build/macOS/python/bin/pip3
$HOST_PIP install cycler python-dateutil kiwisolver pyparsing
# Download original matplotlib source code archive.
if [ ! -e downloads/matplotlib-$MPL_VERSION.tgz ]; then curl --fail -L https://github.com/matplotlib/matplotlib/archive/v$MPL_VERSION.tar.gz -o downloads/matplotlib-$MPL_VERSION.tgz; fi
# unpack
mkdir -p build/iOS/matplotlib-$MPL_VERSION
tar zxf downloads/matplotlib-$MPL_VERSION.tgz --strip-components 1 -C build/iOS/matplotlib-$MPL_VERSION
# Apply patch
cd $PROJECT_DIR/build/iOS/matplotlib-$MPL_VERSION && patch -p1 -i $PROJECT_DIR/patch/matplotlib/matplotlib.patch
# Now build
# Help on compiler flags https://towardsdatascience.com/how-to-shrink-numpy-scipy-pandas-and-matplotlib-for-your-data-product-4ec8d7e86ee4
export CC=$(xcrun -sdk iphonesimulator -find clang)
export AR=$XCODE_ROOT/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar
export SDKROOT=$(xcrun --sdk iphonesimulator --show-sdk-path)
export CFLAGS="-arch x86_64 -isysroot $SDKROOT $CFLAGS_iOS -g0 -O2 -I$SDKROOT -I$PROJECT_DIR/build/iOS/libpng-1.6.37/ -I$PROJECT_DIR/build/iOS/freetype-2.9.1/include -I$PROJECT_DIR/build/iOS/packages/numpy/numpy/core/inlcude/numpy -Wall"
export LDFLAGS="-arch x86_64 -L$PROJECT_DIR/dist/iOS/ -isysroot $SDKROOT $CFLAGS_iOS -Wall -v -r"
BUILDDIR=$PROJECT_DIR/build/iOS/matplotlib-$MPL_VERSION/build
mkdir -p $BUILDDIR
DISTDIR=$PROJECT_DIR/dist/iOS/app_packages
mkdir -p $DISTDIR
cd $PROJECT_DIR/build/iOS/matplotlib-$MPL_VERSION
$HOST_PYTHON setup.py build_ext -I$BUILDDIR
cd $BUILDDIR
find . -name "*.o" | xargs $AR -q libmatplotlib.a
cd $PROJECT_DIR/build/iOS/matplotlib-$MPL_VERSION
$HOST_PYTHON setup.py install
## copy from site-package folder
Step E include matplotlib
Add libpng.a/libfreetype.a/libmatplotlib.a and libc++1.tbd to XCode-Project
|
I was interested on working on this. Has anything else been done with it? |
Hi, no there is no off-the-shelve solution, yet. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Similar to the numpy module, we try to add matplotlib with python bindings as a module, so that it can be used in iOS.
This is an experiment.
The text was updated successfully, but these errors were encountered: