1 ## Building (on Linux x86_64, with bash)
4 First, make sure a virtual environment is set up with Cython and twine:
8 $ source .env/bin/activate
9 (.env) $ pip install --upgrade -r requirements.txt
15 Compile the Cython extensions to C:
18 (.env) $ cython sfpy/*.pyx
23 The extension module depends on the softposit and softfloat static libraries.
24 They can be built with the following:
27 (.env) $ (cd SoftPosit/build/Linux-x86_64-GCC/; make clean; make)
29 (.env) $ (cd berkeley-softfloat-3/build/Linux-x86_64-GCC/; make clean; make)
34 Note that some changes are needed to the Makefiles so that the libraries are
35 compiled with the correct options. Both libraries need to use -fPIC, and
36 SoftPosit may need -std=c99 to work on older versions of GCC. See the
40 The extension modules can be built in place in the usual way:
43 (.env) $ python setup.py build_ext --inplace
48 A local wheel (compatible with the python version installed in the virtual
49 environment) can be built with the following:
52 (.env) $ python setup.py bdist_wheel
57 The local wheel will be created in the `dist/` directory. This is the recommended
58 way to install the package when building it from source locally:
61 $ pip install dist/sfpy*.whl
64 >>> from sfpy import *
70 ### Building manylinux1 wheels for distribution
71 Widely compatible linux wheels can be built with the help of PyPA's manylinux
72 docker image. This requires that Docker is installed, and that the host can pull
73 the proper docker image.
75 To build the manylinux wheels, run:
78 $ sudo docker run -u $(id -u) --rm -v `pwd`:/io quay.io/pypa/manylinux1_x86_64 /io/docker-build-wheels.sh
83 This will create a set of manylinux1 wheel files in the `wheelhouse/` directory.
85 The docker build will make its own static libraries as part of the build process,
86 and delete any existing static libraries with `make clean`.
88 The wheels can be uploaded to PyPI (if you're the package maintainer) with
91 (.env) $ twine upload --repository-url https://test.pypi.org/legacy/ wheelhouse/*
96 to test on test PyPI, or
99 (.env) $ twine upload wheelhouse/*
106 ### Makefile customizations
107 The Makefiles used to build the static libraries need a few small tweaks to
108 make sure that all the right flags are given to gcc. The changes are shown
109 in the following diffs.
111 `SoftPosit/build/Linux-x86_64/Makefile`
114 diff --git a/build/Linux-x86_64-GCC/Makefile b/build/Linux-x86_64-GCC/Makefile
115 index 4409e43..46bb877 100644
116 --- a/build/Linux-x86_64-GCC/Makefile
117 +++ b/build/Linux-x86_64-GCC/Makefile
118 @@ -60,9 +60,9 @@ LINK_PYTHON = \
121 C_INCLUDES = -I. -I$(SOURCE_DIR)/$(SPECIALIZE_TYPE) -I$(SOURCE_DIR)/include
122 -OPTIMISATION = -march=core-avx2 -O2
123 +OPTIMISATION = -fPIC -O2 ^M
125 - gcc -c -Werror-implicit-function-declaration -DSOFTPOSIT_FAST_INT64 \
126 + gcc -std=c99 -c -Werror-implicit-function-declaration -DSOFTPOSIT_FAST_INT64 \^M
127 $(SOFTPOSIT_OPTS) $(C_INCLUDES) $(OPTIMISATION) \
132 `berkeley-softfloat-3/build/Linux-x86_64/Makefile`
135 diff --git a/build/Linux-x86_64-GCC/Makefile b/build/Linux-x86_64-GCC/Makefile
136 index 2ee5dad..b175964 100644
137 --- a/build/Linux-x86_64-GCC/Makefile
138 +++ b/build/Linux-x86_64-GCC/Makefile
139 @@ -45,7 +45,7 @@ DELETE = rm -f
140 C_INCLUDES = -I. -I$(SOURCE_DIR)/$(SPECIALIZE_TYPE) -I$(SOURCE_DIR)/include
142 gcc -c -Werror-implicit-function-declaration -DSOFTFLOAT_FAST_INT64 \
143 - $(SOFTFLOAT_OPTS) $(C_INCLUDES) -O2 -o $@
144 + $(SOFTFLOAT_OPTS) $(C_INCLUDES) -O2 -fPIC -o $@