Skip to content

Commit

Permalink
Merge branch 'master' into new_code
Browse files Browse the repository at this point in the history
  • Loading branch information
fchirica committed May 18, 2020
2 parents cf3a938 + d56a7b6 commit 9006920
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 42 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ jobs:
- name: Install cibuildwheel
run: |
python -m pip install --upgrade pip
pip install wheel
pip install cibuildwheel==1.3.0
- name: Lint source with flake8
run: |
pip install flake8
flake8 src
flake8 src setup.py
- name: Lint source with mypy
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CMakeFiles/
Makefile
CMakeCache.txt
cmake_install.cmake
_deps/

# Binary files
src/compile_asm
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/Chia-Network/chiavdf.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Chia-Network/chiavdf/context:python)
[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/Chia-Network/chiavdf.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Chia-Network/chiavdf/context:cpp)

## Building
This component requires cmake, boost and GMP.
## Building a wheel
Compiling chiavdf requires cmake, boost and GMP.
```
pip install wheel setuptools_scm
python3 -m venv venv
source venv/bin/activate
pip install wheel setuptools_scm pybind11
pip wheel .
```

The primary build process for this repository is to use GitHub Actions to
build binary wheels for MacOS, Linux, and Windows and publish them with
a source wheel on PyPi. See `.github/workflows/build.yml`. setup.py adds
a dependency on [pybind11](https://github.com/pybind/pybind11) by invoking git
to check out the pybind submodules. Building is then managed by
a source wheel on PyPi. See `.github/workflows/build.yml`. CMake uses
[FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html)
to download [pybind11](https://github.com/pybind/pybind11).
Building is then managed by
[cibuildwheel](https://github.com/joerick/cibuildwheel). Further installation
is then available via `pip install chiavdf` e.g.

Expand All @@ -37,7 +41,7 @@ To build vdf_client set the environment variable BUILD_VDF_CLIENT to "Y".
Similarly, to build vdf_bench set the environment variable BUILD_VDF_BENCH to
"Y". `export BUILD_VDF_BENCH=Y`.

This is currently automated in the
This is currently automated via pip in the
[install-timelord.sh](https://github.com/Chia-Network/chia-blockchain/blob/master/install-timelord.sh)
script in the
[chia-blockchain repository](https://github.com/Chia-Network/chia-blockchain)
Expand Down
55 changes: 24 additions & 31 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from distutils.command.install import install
from distutils.command.build import build
import os
import re
import shutil
import sys
import platform
import subprocess

from setuptools import Command
from distutils.command.build import build
from distutils.command.install import install
from distutils.version import LooseVersion
from setuptools.command.build_ext import build_ext
from setuptools import setup, setuptools, Extension, Command


BUILD_HOOKS = []
Expand Down Expand Up @@ -46,18 +54,6 @@ class install_hook(HookCommand):
############################################


import os
import re
import shutil
import sys
import platform
import subprocess

from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from distutils.version import LooseVersion


class CMakeExtension(Extension):
def __init__(self, name, sourcedir=''):
Extension.__init__(self, name, sources=['./'])
Expand Down Expand Up @@ -98,14 +94,9 @@ def run(self):
try:
out = subprocess.check_output(['cmake', '--version'])
except OSError:
raise RuntimeError("CMake must be installed to build" +
" the following extensions: " +
", ".join(e.name for e in self.extensions))
"""
Work around pybind11's need to be on the filesystem
"""
if os.path.exists('.gitmodules'):
out = subprocess.run(['git', 'submodule', 'update', '--init', '--recursive'])
raise RuntimeError("CMake must be installed to build"
+ " the following extensions: "
+ ", ".join(e.name for e in self.extensions))

if platform.system() == "Windows":
cmake_version = LooseVersion(
Expand Down Expand Up @@ -136,8 +127,9 @@ def build_extension(self, ext):

env = os.environ.copy()
env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(
env.get('CXXFLAGS', ''),
self.distribution.get_version())
env.get('CXXFLAGS', ''),
self.distribution.get_version()
)
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, env=env)
subprocess.check_call(['cmake', '--build', '.'] + build_args)

Expand All @@ -160,7 +152,7 @@ def __str__(self):
ext_modules = [
Extension(
'chiavdf',
sorted (
sorted(
[
"src/python_bindings/fastvdf.cpp",
"src/refcode/lzcnt.c",
Expand Down Expand Up @@ -203,7 +195,8 @@ def cpp_flag(compiler):
flags = ['-std=c++17', '-std=c++14', '-std=c++11']

for flag in flags:
if has_flag(compiler, flag): return flag
if has_flag(compiler, flag):
return flag

raise RuntimeError('Unsupported compiler -- at least C++11 support '
'is needed!')
Expand All @@ -212,12 +205,12 @@ def cpp_flag(compiler):
class BuildExt(build_ext):
"""A custom build extension for adding compiler-specific options."""
c_opts = {
'msvc': ['/EHsc','/std:c++17'],
'unix': [],
'msvc': ['/EHsc', '/std:c++17'],
'unix': [""],
}
l_opts = {
'msvc': [],
'unix': [],
'msvc': [""],
'unix': [""],
}

if sys.platform == 'darwin':
Expand Down
12 changes: 10 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ include_directories(

set (CMAKE_CXX_FLAGS "-std=c++1z")

add_subdirectory(lib/pybind11)
pybind11_add_module(chiavdf
include(FetchContent)

FetchContent_Declare(
pybind11-src
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.5.0
)
FetchContent_MakeAvailable(pybind11-src)

pybind11_add_module(chiavdf
${CMAKE_CURRENT_SOURCE_DIR}/python_bindings/fastvdf.cpp
${CMAKE_CURRENT_SOURCE_DIR}/refcode/lzcnt.c
)
Expand Down

0 comments on commit 9006920

Please sign in to comment.