Skip to content

Commit 11a7b27

Browse files
committed
setup
1 parent 3f8d0d5 commit 11a7b27

File tree

3 files changed

+156
-43
lines changed

3 files changed

+156
-43
lines changed

.github/workflows/build.yml

+17-42
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build
1+
name: Build
22

33
on: [push, pull_request]
44

@@ -7,86 +7,61 @@ jobs:
77
name: Build wheel on ${{ matrix.os }}
88
runs-on: ${{ matrix.os }}
99
strategy:
10-
fail-fast: false
1110
matrix:
12-
os: [macos-latest, ubuntu-18.04, windows-latest] # windows-latest doesn't work yet
13-
# os: [windows-latest] # windows-latest doesn't work yet
11+
os: [windows-latest]
1412

1513
steps:
1614
- uses: actions/checkout@v1
1715
with:
1816
fetch-depth: 0
1917
# we need fetch-depth 0 so setuptools_scm can resolve tags
20-
- name: Checkout submodules
21-
uses: snickerbockers/submodules-init@v4
2218
- uses: actions/setup-python@v1
23-
if: "!startsWith(matrix.os, 'windows')"
2419
name: Install Python
2520
with:
2621
python-version: '3.7'
2722

2823
- name: Install cibuildwheel
29-
if: "!startsWith(matrix.os, 'windows')"
3024
run: |
3125
python -m pip install cibuildwheel==1.3.0
32-
33-
- name: Prepare Windows Build environment
26+
- name: Install Visual C++ for Python 2.7
3427
if: startsWith(matrix.os, 'windows')
35-
uses: numworks/setup-msys2@v1
36-
with:
37-
update: true
38-
39-
- name: Windows install dependencies and build
40-
if: startsWith(matrix.os, 'windows')
41-
run: |
42-
msys2do pacman -S --noconfirm mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-gmp mingw-w64-x86_64-dlib mingw-w64-x86_64-python-pep517 mingw-w64-x86_64-python-pytest mingw-w64-x86_64-python-pip git
43-
msys2do ./windows-build.sh
44-
45-
- name: Build source distribution with MacOS
46-
if: startsWith(matrix.os, 'mac')
4728
run: |
48-
pip install pep517
49-
python -m pep517.build --source --out-dir dist .
50-
29+
choco install vcpython27 -f -y
5130
- name: Build wheel
52-
if: "!startsWith(matrix.os, 'windows')"
5331
run: |
5432
python -m cibuildwheel --output-dir dist
5533
env:
5634
# build just python 3.7
5735
CIBW_BUILD: cp37-*
58-
# don't build i686 targets, can't seem to find cmake for these
59-
CIBW_SKIP: '*-manylinux_i686'
36+
CIBW_SKIP: '*-win32'
6037
# we need boost
61-
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2010
62-
CIBW_BEFORE_BUILD_LINUX: curl -L https://github.com/Kitware/CMake/releases/download/v3.17.0/cmake-3.17.0-Linux-`uname -m`.sh > cmake.sh && yes | sh cmake.sh | cat && rm -f /usr/bin/cmake && yum -y install boost-devel gmp-devel && python -m pip install --upgrade pip && which cmake && cmake --version
63-
CIBW_BEFORE_BUILD_MACOS: brew install boost && python -m pip install --upgrade pip
64-
#CIBW_BEFORE_BUILD_WINDOWS: python -m pip install --upgrade pip
65-
#CIBW_TEST_REQUIRES: pytest
66-
CIBW_TEST_COMMAND: pip3 install {project} && python3 {project}/python-bindings/test.py
67-
CIBW_ENVIRONMENT_LINUX: "PATH=/project/cmake-3.17.0-Linux-`uname -m`/bin:$PATH BUILD_VDF_CLIENT=N"
68-
38+
# we need pybind11 to be globally available for cibuildwheel
39+
CIBW_BEFORE_BUILD_LINUX: yum -y install boost-devel && python -m pip install --upgrade pip && pip install pybind11
40+
CIBW_BEFORE_BUILD_MACOS: brew install boost && python -m pip install --upgrade pip && pip install pybind11
41+
CIBW_BEFORE_BUILD_WINDOWS: python -m pip install --upgrade pip && pwd && git clone https://github.com/Chia-Network/relic_x64.git && ls -l relic_x64 && git clone https://github.com/Chia-Network/mpir_gc_x64.git && ls -l mpir_gc_x64 && cp setupwin.py setup.py
42+
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "ls -l mpir_gc_x64 && pip uninstall -y delocate && pip install git+https://github.com/Chia-Network/delocate.git && delocate-wheel -v -i mpir_gc_x64/mpir.dll {wheel} && cp {wheel} {dest_dir} && ls -l {dest_dir} && pwd && ls -l dist && rm -fr mpir_gc_x64 && rm -fr relic_x64"
43+
CIBW_TEST_REQUIRES: pytest
44+
CIBW_TEST_COMMAND: py.test -v {project}/tests
6945
- name: Upload artifacts
70-
if: "!startsWith(matrix.os, 'windows')"
7146
uses: actions/upload-artifact@v1
7247
with:
7348
name: wheels
7449
path: ./dist
7550
- name: Install twine
76-
if: "!startsWith(matrix.os, 'windows')"
7751
run: pip install twine
7852
- name: Publish distribution to Test PyPI
79-
if: "!startsWith(matrix.os, 'windows')"
8053
env:
8154
TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/
8255
TWINE_USERNAME: __token__
8356
TWINE_NON_INTERACTIVE: 1
8457
TWINE_PASSWORD: ${{ secrets.test_pypi_password }}
85-
run: twine upload --non-interactive --skip-existing --verbose 'dist/*'
58+
run: twine upload --non-interactive --skip-existing --verbose 'dist/*whl'
8659
- name: Publish distribution to PyPI
87-
if: startsWith(github.event.ref, 'refs/tags') && !startsWith(matrix.os, 'windows')
60+
if: startsWith(github.event.ref, 'refs/tags')
8861
env:
8962
TWINE_USERNAME: __token__
9063
TWINE_NON_INTERACTIVE: 1
9164
TWINE_PASSWORD: ${{ secrets.pypi_password }}
92-
run: twine upload --non-interactive --skip-existing --verbose 'dist/*'
65+
run: twine upload --non-interactive --skip-existing --verbose 'dist/*whl'
66+
67+

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.5.0"]
2+
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.5.0", "pybind11"]
33
build-backend = "setuptools.build_meta"
44

55
[tool.setuptools_scm]

setupwin.py

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# based on
2+
# https://github.com/pybind/python_example/blob/master/setup.py
3+
4+
from setuptools import setup, Extension
5+
from setuptools.command.build_ext import build_ext
6+
import sys
7+
import setuptools
8+
9+
10+
class get_pybind_include(object):
11+
"""Helper class to determine the pybind11 include path
12+
13+
The purpose of this class is to postpone importing pybind11
14+
until it is actually installed, so that the ``get_include()``
15+
method can be invoked. """
16+
17+
def __init__(self, user=False):
18+
import subprocess
19+
try:
20+
import pybind11
21+
except ImportError:
22+
if subprocess.call([sys.executable, '-m', 'pip', 'install', 'pybind11']):
23+
raise RuntimeError('pybind11 install failed.')
24+
self.user = user
25+
26+
def __str__(self):
27+
import pybind11
28+
return pybind11.get_include(self.user)
29+
30+
31+
ext_modules = [
32+
Extension(
33+
'blspy',
34+
[
35+
'src/chaincode.cpp',
36+
'src/extendedpublickey.cpp',
37+
'src/extendedprivatekey.cpp',
38+
'src/chaincode.cpp',
39+
'src/signature.cpp',
40+
'src/publickey.cpp',
41+
'src/privatekey.cpp',
42+
'src/bls.cpp',
43+
'src/aggregationinfo.cpp',
44+
'src/threshold.cpp',
45+
],
46+
include_dirs=[
47+
# Path to pybind11 headers
48+
get_pybind_include(),
49+
get_pybind_include(user=True),
50+
'mpir_gc_x64',
51+
'relic_x64/include',
52+
'contrib/relic/include',
53+
'contrib/catch',
54+
],
55+
library_dirs=['mpir_gc_x64','relic_x64/lib'],
56+
libraries=['mpir'],
57+
language='c++'
58+
),
59+
]
60+
61+
62+
# As of Python 3.6, CCompiler has a `has_flag` method.
63+
# cf http://bugs.python.org/issue26689
64+
def has_flag(compiler, flagname):
65+
"""Return a boolean indicating whether a flag name is supported on
66+
the specified compiler.
67+
"""
68+
import tempfile
69+
with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f:
70+
f.write('int main (int argc, char **argv) { return 0; }')
71+
try:
72+
compiler.compile([f.name], extra_postargs=[flagname])
73+
except setuptools.distutils.errors.CompileError:
74+
return False
75+
return True
76+
77+
78+
def cpp_flag(compiler):
79+
"""Return the -std=c++[11/14/17] compiler flag.
80+
81+
The newer version is prefered over c++11 (when it is available).
82+
"""
83+
flags = ['-std=c++17', '-std=c++14', '-std=c++11']
84+
85+
for flag in flags:
86+
if has_flag(compiler, flag): return flag
87+
88+
raise RuntimeError('Unsupported compiler -- at least C++11 support '
89+
'is needed!')
90+
91+
92+
class BuildExt(build_ext):
93+
"""A custom build extension for adding compiler-specific options."""
94+
c_opts = {
95+
'msvc': ['/EHsc','/std:c++17'],
96+
'unix': [],
97+
}
98+
l_opts = {
99+
'msvc': [],
100+
'unix': [],
101+
}
102+
103+
if sys.platform == 'darwin':
104+
darwin_opts = ['-stdlib=libc++', '-mmacosx-version-min=10.14']
105+
c_opts['unix'] += darwin_opts
106+
l_opts['unix'] += darwin_opts
107+
108+
def build_extensions(self):
109+
ct = self.compiler.compiler_type
110+
opts = self.c_opts.get(ct, [])
111+
link_opts = self.l_opts.get(ct, [])
112+
if ct == 'unix':
113+
opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version())
114+
opts.append(cpp_flag(self.compiler))
115+
if has_flag(self.compiler, '-fvisibility=hidden'):
116+
opts.append('-fvisibility=hidden')
117+
elif ct == 'msvc':
118+
opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version())
119+
for ext in self.extensions:
120+
ext.extra_compile_args = opts
121+
ext.extra_link_args = link_opts
122+
build_ext.build_extensions(self)
123+
124+
setup(
125+
name='blspy',
126+
author='Mariano Sorgente',
127+
author_email='[email protected]',
128+
description='BLS signatures in c++ (python bindings)',
129+
long_description='BLS signatures with aggregation. Uses fast c++ implementation. See https://github.com/Chia-Network/bls-signatures for more details',
130+
license='Apache License',
131+
python_requires='>=3.7',
132+
setup_requires=['pybind11>=2.4'],
133+
install_requires=['pybind11>=2.4'],
134+
build_requires=["pybind11>=2.4"],
135+
ext_modules=ext_modules,
136+
cmdclass={'build_ext': BuildExt},
137+
zip_safe=False,
138+
)

0 commit comments

Comments
 (0)