Skip to content

Commit

Permalink
Merge pull request #80 from GiacomoPope/flint3
Browse files Browse the repository at this point in the history
Bump to Flint version 3
  • Loading branch information
oscarbenjamin authored Sep 12, 2023
2 parents 243d896 + 1e28c4f commit 22cc77c
Show file tree
Hide file tree
Showing 31 changed files with 232 additions and 148 deletions.
244 changes: 173 additions & 71 deletions bin/build_dependencies_unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,46 @@ set -o errexit
# #
# ------------------------------------------------------------------------- #

SKIP_GMP=no
SKIP_MPFR=no

USE_GMP=gmp
PATCH_GMP_ARM64=no
BUILD_ARB=no

while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
echo "bin/download_dependencies.sh [--gmp gmp|mpir] [--host HOST]"
echo "bin/download_dependencies.sh [options]"
echo
echo "Build local installs of python-flint's dependencies."
echo
echo "Supported options:"
echo " --help - show this help message"
echo " --host <HOST> - set the host (target) for GMP build"
echo " --skip-gmp - skip building GMP"
echo " --skip-mpfr - skip building MPFR"
echo
echo "Legacy options:"
echo " --gmp gmp - build based on GMP (default)"
echo " --gmp mpir - build based on MPIR (no longer works)"
echo " --patch-gmp-arm64 - apply patch to GMP 6.2.1 for OSX arm64"
echo " --arb - build Arb (only needed for flint < 3.0.0)"
echo
exit
;;
--host)
# e.g. --host x86_64-unknown-linux-gnu
# or --host x86_64-apple-darwin
HOST_ARG="$2"
shift
shift
;;
--gmp)
# e.g. --gmp gmp or --gmp mpir
# The mpir build no longer works because the download fails.
USE_GMP="$2"
if [[ "$USE_GMP" != "gmp" && "$USE_GMP" != "mpir" ]]; then
echo "--gmp option should be gmp or mpir"
Expand All @@ -37,14 +64,27 @@ do
shift
shift
;;
--host)
# e.g. --host x86_64-unknown-linux-gnu
# or --host x86_64-apple-darwin
HOST_ARG="$2"
--arb)
# With flint >= 3.0.0 Arb is included so we do not need to build it
# separately. Pass --arb if building for older versions of flint.
BUILD_ARB=yes
shift
;;
--skip-gmp)
# If you already have a local install of GMP you can pass --skip-gmp
# to skip building it.
SKIP_GMP=yes
shift
;;
--skip-mpfr)
# If you already have a local install of MPFR you can pass --skip-mpfr
# to skip building it.
SKIP_MPFR=yes
shift
;;
--patch-gmp-arm64)
# Needed only for GMP 6.2.1 on OSX arm64 (Apple M1) hardware
# As of GMP 6.3.0 this patch is no longer needed
PATCH_GMP_ARM64=yes
shift
;;
Expand Down Expand Up @@ -86,42 +126,60 @@ if [ $USE_GMP = "gmp" ]; then
# #
# ----------------------------------------------------------------------- #

if [ $USE_GMP_GITHUB_MIRROR = "yes" ]; then
# Needed in GitHub Actions because it is blocked from gmplib.org
git clone https://github.com/oscarbenjamin/gmp_mirror.git
cp gmp_mirror/gmp-$GMPVER.tar.xz .
if [ $SKIP_GMP = "yes" ]; then
echo
echo --------------------------------------------
echo " skipping GMP"
echo --------------------------------------------
echo
else
curl -O https://gmplib.org/download/gmp/gmp-$GMPVER.tar.xz
fi
echo
echo --------------------------------------------
echo " building GMP"
echo --------------------------------------------
echo

if [ $USE_GMP_GITHUB_MIRROR = "yes" ]; then
# Needed in GitHub Actions because it is blocked from gmplib.org
git clone https://github.com/oscarbenjamin/gmp_mirror.git
cp gmp_mirror/gmp-$GMPVER.tar.xz .
else
curl -O https://gmplib.org/download/gmp/gmp-$GMPVER.tar.xz
fi

tar xf gmp-$GMPVER.tar.xz
cd gmp-$GMPVER
tar xf gmp-$GMPVER.tar.xz
cd gmp-$GMPVER

#
# See https://github.com/aleaxit/gmpy/issues/350
#
# We need to patch GMP for OSX arm64 (Apple M1) hardware. This patch is
# from the GMP repo but was applied after the release of GMP 6.2.1.
# This patch is no longer needed for GMP 6.3.0.
#
if [ $PATCH_GMP_ARM64 = "yes" ]; then
echo
echo --------------------------------------------
echo " patching GMP"
echo --------------------------------------------
patch -N -Z -p0 < ../../../bin/patch-arm64.diff
fi

#
# See https://github.com/aleaxit/gmpy/issues/350
#
# We need to patch GMP for OSX arm64 (Apple M1) hardware for GMP 6.2.1.
# Now with GMP 6.3.0 this should not be needed any more.
#
if [ $PATCH_GMP_ARM64 = "yes" ]; then
echo
echo --------------------------------------------
echo " patching GMP"
echo --------------------------------------------
patch -N -Z -p0 < ../../../bin/patch-arm64.diff
fi
# Show the output of configfsf.guess
chmod +x configfsf.guess
./configfsf.guess

# Show the output of configfsf.guess
chmod +x configfsf.guess
./configfsf.guess
./configure --prefix=$PREFIX\
--enable-fat\
--enable-shared=yes\
--enable-static=no\
--host=$HOST_ARG
make -j3
make install
cd ..
./configure --prefix=$PREFIX\
--enable-fat\
--enable-shared=yes\
--enable-static=no\
--host=$HOST_ARG
make -j3
make install

cd ..

fi

FLINTARB_WITHGMP="--with-gmp=$PREFIX"

Expand Down Expand Up @@ -182,26 +240,47 @@ fi
# #
# ------------------------------------------------------------------------- #

curl -O https://ftp.gnu.org/gnu/mpfr/mpfr-$MPFRVER.tar.gz
tar xf mpfr-$MPFRVER.tar.gz
cd mpfr-$MPFRVER
./configure --prefix=$PREFIX\
--with-gmp=$PREFIX\
--enable-shared=yes\
--enable-static=no
make -j3
make install
cd ..
if [ $SKIP_MPFR = "yes" ]; then
echo
echo --------------------------------------------
echo " skipping MPFR"
echo --------------------------------------------
echo
else
echo
echo --------------------------------------------
echo " building MPFR"
echo --------------------------------------------
echo

curl -O https://ftp.gnu.org/gnu/mpfr/mpfr-$MPFRVER.tar.gz
tar xf mpfr-$MPFRVER.tar.gz
cd mpfr-$MPFRVER
./configure --prefix=$PREFIX\
--with-gmp=$PREFIX\
--enable-shared=yes\
--enable-static=no
make -j3
make install
cd ..
fi

# ------------------------------------------------------------------------- #
# #
# FLINT #
# #
# ------------------------------------------------------------------------- #

echo
echo --------------------------------------------
echo " building Flint"
echo --------------------------------------------
echo

curl -O -L https://www.flintlib.org/flint-$FLINTVER.tar.gz
tar xf flint-$FLINTVER.tar.gz
cd flint-$FLINTVER
./bootstrap.sh
./configure --prefix=$PREFIX\
$FLINTARB_WITHGMP\
--with-mpfr=$PREFIX\
Expand All @@ -216,25 +295,34 @@ cd ..
# #
# ------------------------------------------------------------------------- #

curl -O -L https://github.com/fredrik-johansson/arb/archive/refs/tags/$ARBVER.tar.gz
mv $ARBVER.tar.gz arb-$ARBVER.tar.gz
tar xf arb-$ARBVER.tar.gz
cd arb-$ARBVER
./configure --prefix=$PREFIX\
--with-flint=$PREFIX\
$FLINTARB_WITHGMP\
--with-mpfr=$PREFIX\
--disable-static
make -j3
make install
#
# Set PATH so that DLLs are picked up on Windows.
#
PATH=$PATH:$PREFIX/lib:$PREFIX/bin \
ARB_TEST_MULTIPLIER=0.1 \
# Skip Arb tests now because they are slow.
# make check
cd ..
if [ $BUILD_ARB = "yes" ]; then

echo
echo --------------------------------------------
echo " building Arb"
echo --------------------------------------------
echo

curl -O -L https://github.com/fredrik-johansson/arb/archive/refs/tags/$ARBVER.tar.gz
mv $ARBVER.tar.gz arb-$ARBVER.tar.gz
tar xf arb-$ARBVER.tar.gz
cd arb-$ARBVER
./configure --prefix=$PREFIX\
--with-flint=$PREFIX\
$FLINTARB_WITHGMP\
--with-mpfr=$PREFIX\
--disable-static
make -j3
make install
#
# Set PATH so that DLLs are picked up on Windows.
#
PATH=$PATH:$PREFIX/lib:$PREFIX/bin \
ARB_TEST_MULTIPLIER=0.1 \
# Skip Arb tests now because they are slow.
# make check
cd ..
fi

# ------------------------------------------------------------------------- #
# #
Expand All @@ -249,14 +337,28 @@ echo Build dependencies for python-flint compiled as shared libraries in:
echo $PREFIX
echo
echo Versions:
if [[ $USE_GMP = "gmp" ]]; then
echo GMP: $GMPVER

if [ $SKIP_GMP = "yes" ]; then
echo GMP: skipped
else
echo MPIR: $MPIRVER
if [[ $USE_GMP = "gmp" ]]; then
echo GMP: $GMPVER
else
echo MPIR: $MPIRVER
fi
fi
echo MPFR: $MPFRVER

if [ $SKIP_MPFR = "yes" ]; then
echo MPFR: skipped
else
echo MPFR: $MPFRVER
fi

echo Flint: $FLINTVER
echo Arb: $ARBVER

if [ $BUILD_ARB = "yes" ]; then
echo Arb: $ARBVER
fi
echo
echo -----------------------------------------------------------------------
echo
11 changes: 7 additions & 4 deletions bin/build_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
PREFIX=$(pwd)/.local
mkdir -p $PREFIX

ARBVER=2.23.0 # Not needed with flint >= 3.0.0 (Arb is included in flint)

YASMVER=1.3.0 # Only needed for MPIR
MPIRVER=3.0.0 # MPIR build no longer works (not clear where to download from)

# These are the actual dependencies used (at least by default):
GMPVER=6.3.0
YASMVER=1.3.0
MPIRVER=3.0.0
MPFRVER=4.1.0
FLINTVER=2.9.0
ARBVER=2.23.0
FLINTVER=3.0.0-alpha1
2 changes: 2 additions & 0 deletions bin/cibw_before_all_macosx_arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
export CPPFLAGS=" --target=arm64-apple-macos11"
export LDFLAGS=" -arch arm64"

brew install automake libtool

bin/build_dependencies_unix.sh\
--gmp gmp\
--host aarch64-apple-darwin\
Expand Down
2 changes: 2 additions & 0 deletions bin/cibw_before_all_macosx_x86_64.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

brew install automake libtool

bin/build_dependencies_unix.sh\
--gmp gmp\
--host x86_64-apple-darwin\
Expand Down
13 changes: 11 additions & 2 deletions bin/cibw_before_all_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@ echo '[build]' > setup.cfg
echo 'compiler = mingw32' >> setup.cfg
cat setup.cfg

# Install the mingw-w64 toolchain
pacman -S --noconfirm mingw-w64-x86_64-gcc m4 make mingw-w64-x86_64-tools-git
# Install the mingw-w64 toolchain and build tools
pacman -S --noconfirm \
mingw-w64-x86_64-gcc\
mingw-w64-x86_64-tools-git\
m4\
make\
base-devel\
autoconf-wrapper\
automake-wrapper\
libtool\
#

# This takes ~30mins
bin/build_dependencies_unix.sh --use-gmp-github-mirror
9 changes: 6 additions & 3 deletions bin/cibw_repair_wheel_command_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ wheeldir=$(dirname $WHEELNAME)
echo $wheeldir

# delvewheel requires DLLs created by mingw64 to be stripped. This strips the
# DLLs for GMP etc that will have been build previously.
strip .local/bin/*.dll .local/lib/*.dll
# DLLs for GMP etc that will have been built in the CIBW_BEFORE_ALL step.
#
# Previously the Arb DLLs would have been placed in .local/lib, but as of
# flint 3.0.0 all DLLs aRe in .local/bin.
strip .local/bin/*.dll

# Make sure to leave the wheel in the same directory
wheeldir=$(dirname $WHEELNAME)
Expand All @@ -47,4 +50,4 @@ popd
# .pyd files that are needed for the wheel.
delvewheel repair $WHEELNAME \
-w $WHEELHOUSE \
--add-path .local/bin:.local/lib/
--add-path .local/bin
Loading

0 comments on commit 22cc77c

Please sign in to comment.