Skip to content

Commit c91ef06

Browse files
Merge branch 'master' of github.com:fredrik-johansson/python-flint
2 parents 6219368 + 1a68cff commit c91ef06

7 files changed

Lines changed: 312 additions & 0 deletions

File tree

.github/workflows/buildwheel.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build_wheels:
7+
name: Build wheels for ${{ matrix.os }}
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
# os: [ubuntu-20.04, windows-2019, macOS-10.15]
12+
os: [ubuntu-20.04, macOS-10.15]
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-python@v2
17+
18+
- name: Install cibuildwheel
19+
run: python -m pip install cibuildwheel==1.10.0
20+
- name: Build wheels
21+
run: python -m cibuildwheel --output-dir wheelhouse
22+
env:
23+
CIBW_BUILD: cp37-* cp38-*
24+
CIBW_BEFORE_ALL_LINUX: bin/cibw_before_build_linux.sh
25+
CIBW_BEFORE_ALL_MACOS: bin/cibw_before_build_macosx.sh
26+
# There are problems with both older and newer cython versions...
27+
CIBW_BEFORE_BUILD: pip install numpy cython==0.27.3
28+
CIBW_ENVIRONMENT: >
29+
C_INCLUDE_PATH=$(pwd)/.local/include/
30+
LIBRARY_PATH=$(pwd)/.local/lib/
31+
LD_LIBRARY_PATH=$(pwd)/.local/lib:$LD_LIBRARY_PATH
32+
- uses: actions/upload-artifact@v2
33+
with:
34+
path: wheelhouse/*.whl

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ dist/*
33
src/*.c
44
doc/build/*
55
fmake*
6+
*.whl
67
MANIFEST
78
.eggs
9+
.local

bin/build_dependencies_unix.sh

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Build local installs of python-flint's dependencies. This should be run
4+
# before attempting to build python-flint itself.
5+
6+
set -o errexit
7+
8+
# ------------------------------------------------------------------------- #
9+
# #
10+
# Supported options: #
11+
# #
12+
# --gmp gmp - build based on GMP (default) #
13+
# --gmp mpir - build based on MPIR (instead of GMP) #
14+
# #
15+
# ------------------------------------------------------------------------- #
16+
17+
USE_GMP=gmp
18+
19+
while [[ $# -gt 0 ]]
20+
do
21+
key="$1"
22+
case $key in
23+
-h|--help)
24+
echo "bin/download_dependencies.sh [--gmp gmp|mpir] [--host HOST]"
25+
exit
26+
;;
27+
--gmp)
28+
# e.g. --gmp gmp or --gmp mpir
29+
USE_GMP="$2"
30+
if [[ "$USE_GMP" != "gmp" && "$USE_GMP" != "mpir" ]]; then
31+
echo "--gmp option should be gmp or mpir"
32+
exit 1
33+
fi
34+
shift
35+
shift
36+
;;
37+
--host)
38+
# e.g. --host x86_64-unknown-linux-gnu
39+
# or --host x86_64-apple-darwin
40+
HOST_ARG="$2"
41+
shift
42+
shift
43+
;;
44+
esac
45+
done
46+
47+
# ------------------------------------------------------------------------- #
48+
# #
49+
# The build_variables.sh script sets variables specifying the versions to #
50+
# use for all dependencies and also the PREFIX variable. #
51+
# #
52+
# ------------------------------------------------------------------------- #
53+
54+
source bin/build_variables.sh
55+
56+
cd $PREFIX
57+
mkdir -p src
58+
cd src
59+
60+
# ------------------------------------------------------------------------- #
61+
# #
62+
# Now build all dependencies. #
63+
# #
64+
# ------------------------------------------------------------------------- #
65+
66+
if [ $USE_GMP = "gmp" ]; then
67+
68+
# ----------------------------------------------------------------------- #
69+
# #
70+
# GMP #
71+
# #
72+
# ----------------------------------------------------------------------- #
73+
74+
curl -O https://gmplib.org/download/gmp/gmp-$GMPVER.tar.xz
75+
tar xf gmp-$GMPVER.tar.xz
76+
cd gmp-$GMPVER
77+
./configure --prefix=$PREFIX\
78+
--enable-fat\
79+
--enable-shared=yes\
80+
--enable-static=no\
81+
--host=$HOSTARG
82+
make -j3
83+
make install
84+
cd ..
85+
86+
FLINTARB_WITHGMP="--with-gmp=$PREFIX"
87+
88+
else
89+
90+
# ----------------------------------------------------------------------- #
91+
# #
92+
# YASM (needed to build MPIR) #
93+
# #
94+
# ----------------------------------------------------------------------- #
95+
96+
curl -O http://www.tortall.net/projects/yasm/releases/yasm-$YASMVER.tar.gz
97+
tar xf yasm-$YASMVER.tar.gz
98+
cd yasm-$YASMVER
99+
./configure --prefix=$PREFIX
100+
make -j3
101+
make install
102+
cd ..
103+
104+
# ----------------------------------------------------------------------- #
105+
# #
106+
# MPIR #
107+
# #
108+
# ----------------------------------------------------------------------- #
109+
110+
curl -O http://mpir.org/mpir-$MPIRVER.tar.bz2
111+
tar xf mpir-$MPIRVER.tar.bz2
112+
cd mpir-$MPIRVER
113+
./configure --prefix=$PREFIX\
114+
--with-yasm=$PREFIX/bin/yasm\
115+
--enable-fat\
116+
--enable-shared=yes\
117+
--enable-static=no\
118+
--enable-gmpcompat
119+
make -j3
120+
make install
121+
cd ..
122+
123+
FLINTARB_WITHGMP="--with-mpir=$PREFIX"
124+
125+
fi
126+
127+
# ------------------------------------------------------------------------- #
128+
# #
129+
# MPFR #
130+
# #
131+
# ------------------------------------------------------------------------- #
132+
133+
curl -O https://www.mpfr.org/mpfr-current/mpfr-$MPFRVER.tar.gz
134+
tar xf mpfr-$MPFRVER.tar.gz
135+
cd mpfr-$MPFRVER
136+
./configure --prefix=$PREFIX\
137+
--with-gmp=$PREFIX\
138+
--enable-shared=yes\
139+
--enable-static=no
140+
make -j3
141+
make install
142+
cd ..
143+
144+
# ------------------------------------------------------------------------- #
145+
# #
146+
# FLINT #
147+
# #
148+
# ------------------------------------------------------------------------- #
149+
150+
curl -O https://www.flintlib.org/flint-$FLINTVER.tar.gz
151+
tar xf flint-$FLINTVER.tar.gz
152+
cd flint-$FLINTVER
153+
./configure --prefix=$PREFIX\
154+
$FLINTARB_WITHGMP\
155+
--with-mpfr=$PREFIX\
156+
--disable-static
157+
make -j3
158+
make install
159+
cd ..
160+
161+
# ------------------------------------------------------------------------- #
162+
# #
163+
# ARB #
164+
# #
165+
# ------------------------------------------------------------------------- #
166+
167+
curl -O -L https://github.com/fredrik-johansson/arb/archive/refs/tags/$ARBVER.tar.gz
168+
mv $ARBVER.tar.gz arb-$ARBVER.tar.gz
169+
tar xf arb-$ARBVER.tar.gz
170+
cd arb-$ARBVER
171+
./configure --prefix=$PREFIX\
172+
--with-flint=$PREFIX\
173+
$FLINTARB_WITHGMP\
174+
--with-mpfr=$PREFIX\
175+
--disable-static
176+
make -j3
177+
make install
178+
cd ..
179+
180+
# ------------------------------------------------------------------------- #
181+
# #
182+
# Done! #
183+
# #
184+
# ------------------------------------------------------------------------- #
185+
186+
echo
187+
echo -----------------------------------------------------------------------
188+
echo
189+
echo Build dependencies for python-flint compiled as shared libraries in:
190+
echo $PREFIX
191+
echo
192+
echo Versions:
193+
if [[ $USE_GMP = "gmp" ]]; then
194+
echo GMP: $GMPVER
195+
else
196+
echo MPIR: $MPIRVER
197+
fi
198+
echo MPFR: $MPFRVER
199+
echo Flint: $FLINTVER
200+
echo Arb: $ARBVER
201+
echo
202+
echo -----------------------------------------------------------------------
203+
echo

bin/build_variables.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Create a local directory .local to be used as --prefix when building
4+
# local installs of python-flint's dependencies. This also sets the PREFIX
5+
# shell variable and environment variables giving the versions to use for each
6+
# dependency. This script should be sourced rather than executed e.g.:
7+
#
8+
# $ source bin/build_variables.sh
9+
#
10+
# This is used implicitly by the other build scripts and does not need to be
11+
# executed directly.
12+
13+
PREFIX=$(pwd)/.local
14+
mkdir -p $PREFIX
15+
16+
GMPVER=6.2.1
17+
YASMVER=1.3.1
18+
MPIRVER=3.0.0
19+
MPFRVER=4.1.0
20+
FLINTVER=2.7.1
21+
ARBVER=2.19.0

bin/build_wheel.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Compile a python-flint wheel using the dependencies built by
4+
# build_dependencies_unix.sh (which should be run first).
5+
6+
set -o errexit
7+
8+
PYTHONFLINTVER=0.3.0
9+
10+
source bin/build_variables.sh
11+
12+
python3 -m venv $PREFIX/venv
13+
source $PREFIX/venv/bin/activate
14+
pip install -U pip wheel delocate
15+
pip install numpy cython==0.27.3
16+
# N.B. bugs in both older and newer Cython versions...
17+
18+
C_INCLUDE_PATH=.local/include/ LIBRARY_PATH=.local/lib/ pip wheel .
19+
20+
wheelfinal=*.whl
21+
22+
# On OSX bundle the dynamic libraries for the dependencies
23+
mkdir -p wheelhouse
24+
delocate-wheel -w wheelhouse $wheelfinal
25+
26+
echo ------------------------------------------
27+
echo
28+
echo Built wheel: wheelhouse/$wheelfinal
29+
echo
30+
echo Link dependencies:
31+
delocate-listdeps wheelhouse/$wheelfinal
32+
echo
33+
pip install wheelhouse/$wheelfinal
34+
echo
35+
echo Demonstration:
36+
echo
37+
python -c 'import flint; print("(3/2)**2 =", flint.fmpq(3, 2)**2)'
38+
echo
39+
echo Done!
40+
echo
41+
echo ------------------------------------------

bin/cibw_before_build_linux.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
yum install -y xz
4+
bin/build_dependencies_unix.sh\
5+
--gmp gmp\
6+
--host x86_64-unknown-linux-gnu

bin/cibw_before_build_macosx.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
bin/build_dependencies_unix.sh\
4+
--gmp gmp\
5+
--host x86_64-apple-darwin

0 commit comments

Comments
 (0)