diff --git a/ext/build.sh b/ext/build.sh index 2c22393..b9994db 100644 --- a/ext/build.sh +++ b/ext/build.sh @@ -5,7 +5,7 @@ set -euo pipefail echo "=== Building C libraries ===" # Adapted from https://github.com/fredrik-johansson/python-flint/blob/00699afa47aaa4c56e42cb98a1f8231e9000eddd/bin/build_dependencies_unix.sh -PREFIX=$(pwd)/tmlt/core/ext +PREFIX=$(pwd)/src/tmlt/core/ext echo $PREFIX mkdir -p $PREFIX/src source ext/dependency_versions.sh @@ -18,68 +18,49 @@ case "$(uname)" in *) nproc=$(getconf _NPROCESSORS_ONLN) || nproc=2 esac -if [[ "$(uname)" = "Darwin" ]]; then - FLINTARB_WITHGMP="--with-gmp=$PREFIX" - - # GMP - if [[ ! -f $PREFIX/lib/GMPVER || "$(cat $PREFIX/lib/GMPVER)" != "$GMPVER" ]]; then - curl -O https://gmplib.org/download/gmp/gmp-$GMPVER.tar.xz - tar xf gmp-$GMPVER.tar.xz - pushd gmp-$GMPVER - # Show the output of configfsf.guess - ./configfsf.guess - ./configure --prefix=$PREFIX --enable-fat --enable-shared=yes --enable-static=no --host=x86_64-apple-darwin - make -j $nproc - make install - echo "$GMPVER" > $PREFIX/lib/GMPVER - rm -f $PREFIX/lib/MPFRVER - popd - else - echo "Using existing GMP..." - fi -else - if ! (command -v make && command -v curl && command -v bzip2 && command -v m4) >/dev/null - then - echo "make, curl, bzip2, and m4 are required to build dependencies from source." - exit 1 - fi - - FLINTARB_WITHGMP="--with-mpir=$PREFIX" +if ! (command -v make && command -v curl && command -v m4) >/dev/null +then + echo "make, curl, and m4 are required to build dependencies from source." + exit 1 +fi - # YASM (dependency of MPIR) - if [[ ! -f $PREFIX/lib/YASMVER || "$(cat $PREFIX/lib/YASMVER)" != "$YASMVER" ]]; then - curl -L -O https://github.com/yasm/yasm/releases/download/v$YASMVER/yasm-$YASMVER.tar.gz - tar xf yasm-$YASMVER.tar.gz - pushd yasm-$YASMVER - ./configure --prefix=$PREFIX - make -j $nproc - make install - echo "$YASMVER" > $PREFIX/lib/YASMVER - rm -f $PREFIX/lib/MPIRVER - popd - else - echo "Using existing YASM..." +# On Linux, cibuildwheel compiles the dependencies and builds platform-specific wheels on a Docker +# container. Since the dependencies built when running `poetry install` are not compatible with the +# Docker container, we need to rebuild them here. We use AUDITWHEEL_PLAT to determine whether the +# dependencies need to be rebuilt. +AUDITWHEEL_PLAT=${AUDITWHEEL_PLAT-} +if [[ "$(uname)" = "Linux" ]]; then + if [[ ! -f $PREFIX/lib/AUDITWHEEL_PLAT || "$(cat $PREFIX/lib/AUDITWHEEL_PLAT)" != "$AUDITWHEEL_PLAT" ]]; then + echo "Rebuilding dependencies because $PREFIX/lib/AUDITWHEEL_PLAT does not match $AUDITWHEEL_PLAT." + rm -f $PREFIX/lib/GMPVER $PREFIX/lib/MPFRVER $PREFIX/lib/FLINTVER $PREFIX/lib/ARBVER fi +fi - # MPIR - if [[ ! -f $PREFIX/lib/MPIRVER || "$(cat $PREFIX/lib/MPIRVER)" != "$MPIRVER" ]]; then - curl -O https://mpir.org/mpir-$MPIRVER.tar.bz2 - tar xf mpir-$MPIRVER.tar.bz2 - pushd mpir-$MPIRVER - ./configure --prefix=$PREFIX --with-yasm=$PREFIX/bin/yasm --enable-fat --enable-shared=yes --enable-static=no --enable-gmpcompat - make -j $nproc - make install - echo "$MPIRVER" > $PREFIX/lib/MPIRVER - rm -f $PREFIX/lib/MPFRVER - popd - else - echo "Using existing MPIR..." +# GMP +if [[ ! -f $PREFIX/lib/GMPVER || "$(cat $PREFIX/lib/GMPVER)" != "$GMPVER" ]]; then + configure_args="--prefix=$PREFIX --enable-fat --enable-shared=yes --enable-static=no" + if [[ "$(uname)" = "Darwin" ]]; then + configure_args="$configure_args --host=x86_64-apple-darwin" fi + curl -OLf https://gmplib.org/download/gmp/gmp-$GMPVER.tar.xz + tar xf gmp-$GMPVER.tar.xz + pushd gmp-$GMPVER + # Show the output of configfsf.guess + ./configfsf.guess + ./configure $configure_args + make -j $nproc + make check + make install + echo "$GMPVER" > $PREFIX/lib/GMPVER + rm -f $PREFIX/lib/MPFRVER + popd +else + echo "Using existing GMP..." fi # MPFR if [[ ! -f $PREFIX/lib/MPFRVER || "$(cat $PREFIX/lib/MPFRVER)" != "$MPFRVER" ]]; then - curl -O https://ftp.gnu.org/gnu/mpfr/mpfr-$MPFRVER.tar.gz + curl -OLf https://ftp.gnu.org/gnu/mpfr/mpfr-$MPFRVER.tar.gz tar xf mpfr-$MPFRVER.tar.gz pushd mpfr-$MPFRVER ./configure --prefix=$PREFIX --with-gmp=$PREFIX --enable-shared=yes --enable-static=no @@ -94,10 +75,10 @@ fi # FLINT if [[ ! -f $PREFIX/lib/FLINTVER || "$(cat $PREFIX/lib/FLINTVER)" != "$FLINTVER" ]]; then - curl -O https://www.flintlib.org/flint-$FLINTVER.tar.gz + curl -OLf https://www.flintlib.org/flint-$FLINTVER.tar.gz tar xf flint-$FLINTVER.tar.gz pushd flint-$FLINTVER - ./configure --prefix=$PREFIX $FLINTARB_WITHGMP --with-mpfr=$PREFIX --disable-static + ./configure --prefix=$PREFIX --with-gmp=$PREFIX --with-mpfr=$PREFIX --disable-static make -j $nproc make install echo "$FLINTVER" > $PREFIX/lib/FLINTVER @@ -109,11 +90,11 @@ fi # Arb if [[ ! -f $PREFIX/lib/ARBVER || "$(cat $PREFIX/lib/ARBVER)" != "$ARBVER" ]]; then - curl -O -L https://github.com/fredrik-johansson/arb/archive/refs/tags/$ARBVER.tar.gz + curl -OLf 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 pushd arb-$ARBVER - ./configure --prefix=$PREFIX --with-flint=$PREFIX $FLINTARB_WITHGMP --with-mpfr=$PREFIX --disable-static + ./configure --prefix=$PREFIX --with-flint=$PREFIX --with-gmp=$PREFIX --with-mpfr=$PREFIX --disable-static make -j $nproc make install echo "$ARBVER" > $PREFIX/lib/ARBVER @@ -122,6 +103,8 @@ else echo "Using existing Arb..." fi +echo "$AUDITWHEEL_PLAT" > $PREFIX/lib/AUDITWHEEL_PLAT + # The source archives for some of these libraries include Python files, which # can be spuriously picked up by our linters when run locally. There's no reason # to keep the sources around, so just delete them to get around this problem. diff --git a/ext/dependency_versions.sh b/ext/dependency_versions.sh index 8dd2d10..157408a 100644 --- a/ext/dependency_versions.sh +++ b/ext/dependency_versions.sh @@ -3,8 +3,6 @@ # This file lists the versions of C libraries required for tmlt.core.utils.arb. GMPVER=6.2.1 -YASMVER=1.3.0 -MPIRVER=3.0.0 MPFRVER=4.1.0 FLINTVER=2.9.0 ARBVER=2.23.0