Skip to content

Commit

Permalink
playing with gfortran static build
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoli committed May 22, 2020
1 parent d8cb40a commit 5af2cff
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 40 deletions.
36 changes: 36 additions & 0 deletions packaging/conda/VS2019_gfortran8_build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Building with VS 2019-C++ and MINGW64-gfortran 8.1

* It appears that for newer Pythons one should use Visual C++ as a compiler, rather than MINGW64-GCC.
* For newer versions of numpy, you apparently need a recent version of MINGW64-gfortran. The one that comes with Anaconda (as part of the mingw package) is 4.7.0 which does not work!

Here is how I have managed to build a wheel for Python 3.7 that seems to work:

* I have Visual Studio 2017 installed for C++ stuff, however, the VS build tools are available for free. Try here for download details: https://wiki.python.org/moin/WindowsCompilers>
** Anaconda might also have the VC build tools (package vc) but I have never used it.
* Create a conda environment: conda create -n "pscbuild" python=3.7 ipython pip wheel numpy scipy matplotlib
** Alternatively, if using an existing environment, make sure the Anaconda mingw package is not installed (remove it now)
* I unpacked MINGW64 that I obtained here (https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z/download) based on the information I found here (https://stackoverflow.com/questions/48826283/compile-fortran-module-with-f2py-and-python-3-6-on-windows-10)
* In a terminal I then activated the conda environment and added the new GCC to the path (making sure there was no existing gcc)
** conda activate pscbuild
** path=c:\tools\mingw64\bin;%path%
* Build/install PySCeS with python setup.py build --compiler=msvc --fcompiler=gfortran install bdist_wheel

For conda build we need the following:

* Open a VS2015 terminal (v10) and change to your build directory
** path=c:\tools\mingw64\bin;%path%
** path="c:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64";%path%
* 3.6 <= Python < 3.8
** conda build --python 3.6 --numpy 1.15 .
** conda build --python 3.7 --numpy 1.15 .
* Python >= 3.8
** conda build --python 3.8 --numpy 1.18 .

* cleanup and upload
** conda build purge
** conda clean --all
** anaconda upload -u pysces-builds\*



Brett 2020
6 changes: 3 additions & 3 deletions packaging/conda/bld.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
copy ..\_h_env\libs\libpython27.dll.a ..\_h_env\libs\libpython27.a
copy ..\_h_env\libs\libmsvcr90.dll.a ..\_h_env\libs\libmsvcr90.a
"%PYTHON%" setup.py build --compiler=mingw32 install --record=record.txt
::copy ..\_h_env\libs\libpython27.dll.a ..\_h_env\libs\libpython27.a
::copy ..\_h_env\libs\libmsvcr90.dll.a ..\_h_env\libs\libmsvcr90.a
"%PYTHON%" setup.py build --compiler=msvc --fcompiler=gfortran install --record=record.txt
if errorlevel 1 exit 1
26 changes: 9 additions & 17 deletions packaging/conda/conda_build.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
Open an anaconda prompt
Open a VS2015 build prompt

cd to conda build files
path=c:\tools\mingw64\bin;%path%
path="c:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64";%path%

Optional: update build version and SVN information in meta.yaml
conda update conda
conda update conda-build
Run to build
conda build -c sbmlteam --python 3.6 --numpy 1.15 .
conda build -c sbmlteam --python 3.7 --numpy 1.15 .

Run to build (note the upload command path e.g. anaconda upload C:\Anaconda\conda-bld\win-64\pysces-0.9.5-py27hd5793fb_1.tar.bz2):
conda build -c sbmlteam .

New hacks to workaround conda-build enhancements in 2019.1
conda update conda-build
conda clean --all
conda build --numpy 1.15 --python 2.7 -c sbmlteam .
conda build --numpy 1.15 --python 3.6 -c sbmlteam .
conda build --numpy 1.15 --python 3.7 -c sbmlteam .
conda clean --all
conda build purge

anaconda upload -u pysces C:\Anaconda\conda-bld\win-64\pysces-0.9.7-py27_2.tar.bz2
anaconda upload -u pysces C:\Anaconda\conda-bld\win-64\pysces-0.9.7-py36_2.tar.bz2
anaconda upload -u pysces C:\Anaconda\conda-bld\win-64\pysces-0.9.7-py37_2.tar.bz2
anaconda upload -u pysces
anaconda upload -u pysces c:\Anaconda3\conda-bld\win-64\pysces-0.9.8-py37h6ebd63d_1.tar.bz2



NOTES:
Expand Down
11 changes: 4 additions & 7 deletions packaging/conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package:

source:
git_url: https://github.com/PySCeS/pysces.git
# path: pysces-src

build:
number: 1
Expand All @@ -13,24 +14,20 @@ requirements:
build:
- python
- setuptools
- numpy=1.15
- numpy
- libpython
- mingw
- scipy
- matplotlib
- nose
run:
- python
- setuptools
- numpy>=1.15
- numpy
- libpython
- scipy
- matplotlib
- nose
- python-libsbml

- nose


about:
home: http://pysces.sourceforge.net
license: BSD
Expand Down
45 changes: 32 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
from __future__ import absolute_import

__doc__ = "PySCeS: the Python Simulator for Cellular Systems setup file"
__version__ = '0.9.8post1'
__version__ = '0.9.8'

import os, re
import sysconfig

import fileinput
import shutil
try:
Expand Down Expand Up @@ -176,10 +178,26 @@ def writeConfig(local_path, config={}):
#PySCeS modules
mymodules = []

# extra compile args for FORTRAN code that should meand that gfortran libraries are statically compiled into the pyd
if os.sys.platform == 'win32':
#extra_f77_compile_args = ["-static-libgcc", "-static-libgfortran"]
extra_f77_compile_args = ["-static", "-static-libgcc", "-static-libgfortran"]
else:
extra_f77_compile_args = []

print('extra_f77_compile_args: ', extra_f77_compile_args)


if pitcon:
print('\nBuilding pitcon')
extpath = os.path.join('pysces', 'pitcon')
pitcon = Extension('pysces.pitcon.pitcon',[os.path.join(extpath,'pitcon.pyf'),os.path.join(extpath,'pcon61subd.f'),os.path.join(extpath,'dpcon61.f'),os.path.join(extpath,'dpcon61w.f')])
pitcon = Extension('pysces.pitcon.pitcon', sources=[os.path.join(extpath,'pitcon.pyf'),
os.path.join(extpath,'pcon61subd.f'),
os.path.join(extpath,'dpcon61.f'),
os.path.join(extpath,'dpcon61w.f')],
extra_f77_compile_args=extra_f77_compile_args

)
mymodules.append(pitcon)
#mydata_files.append((os.path.join('pysces','pitcon'), [os.path.join(local_path, 'pysces', 'pitcon','readme.txt'), os.path.join(local_path, 'pysces', 'pitcon','readme.txt')]))
else:
Expand All @@ -198,11 +216,13 @@ def writeConfig(local_path, config={}):
## elif os.sys.byteorder == 'big':
## shutil.copyfile(os.path.join(extpath,'nleq2_big.f'), os.path.join(extpath,'nleq2.f'))
extpath = os.path.join('pysces', 'nleq2')
nleq2 = Extension('pysces.nleq2.nleq2',[os.path.join(extpath,'nleq2.pyf'),\
os.path.join(extpath,'nleq2.f'), os.path.join(extpath,'linalg_nleq2.f'),\
os.path.join(extpath,'zibmon.f'), os.path.join(extpath,'zibsec.f'),\
os.path.join(extpath,'zibconst.f'), os.path.join(extpath,'wnorm.f')
])
nleq2 = Extension('pysces.nleq2.nleq2', sources=[os.path.join(extpath,'nleq2.pyf'),
os.path.join(extpath,'nleq2.f'),
os.path.join(extpath,'linalg_nleq2.f'),
os.path.join(extpath,'zibmon.f'), os.path.join(extpath,'zibsec.f'),
os.path.join(extpath,'zibconst.f'), os.path.join(extpath,'wnorm.f')],
extra_f77_compile_args=extra_f77_compile_args
)
mymodules.append(nleq2)
mypackages.append('pysces.nleq2')
else:
Expand All @@ -215,9 +235,9 @@ def writeConfig(local_path, config={}):
# Data files to copy
mydata_files.append((os.path.join('pysces'), [os.path.join('pysces','pyscfg.ini')]))
mydata_files.append(('',[os.path.join('pysces','pysces.pth')]))
mydata_files.append((os.path.join('pysces','docs'), [os.path.join('pysces','docs','userguide.pdf')]))
#mydata_files.append((os.path.join('pysces','docs'), [os.path.join('pysces','docs','userguide.pdf')])) # bgoli2020: does not exist anymore
mydata_files.append((os.path.join('pysces','examples'), [os.path.join('pysces','examples',examplefile) for examplefile in os.listdir(os.path.join(local_path,'pysces','examples'))]))
##not sure if this is necessary anymore, removed to test
## not sure if this is necessary anymore now that I am using static gfortran linking
if os.sys.platform == 'win32':
mydata_files.append((os.path.join('pysces','win32'), [os.path.join('pysces','win32','libquadmath-0.dll'), os.path.join('pysces','win32','libgfortran-3.dll'),\
os.path.join('pysces','win32','libgcc_s_seh-1.dll'), os.path.join('pysces','win32','libwinpthread-1.dll')]))
Expand Down Expand Up @@ -248,13 +268,12 @@ def writeConfig(local_path, config={}):
maintainer = "Brett G. Olivier",
maintainer_email = "bgoli@users.sourceforge.net",
url = "http://pysces.sourceforge.net",
download_url = "http://pysces.sourceforge.net/download.html",
download_url = "https://pypi.org/project/pysces/#files",
license = "New BSD style",
keywords = "computational systems biology, modelling, simulation, systems biology" ,
zip_safe = False,
#requires = ['numpy','scipy','matplotlib'],
install_requires = ['numpy','scipy','matplotlib','python-libsbml','nose'],
platforms = ["Windows", "Linux", "macOS"],
install_requires = ['numpy','scipy','matplotlib','nose'],
platforms = ["Windows", "POSIX", "Max OSX"],
classifiers = [
'Development Status :: 5 - Production/Stable',
'Development Status :: 6 - Mature',
Expand Down

0 comments on commit 5af2cff

Please sign in to comment.