diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index c739033..75b781f 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -2,26 +2,34 @@ name: Wheels on: push: + branches: + - 'main' tags: - - '*' + - '*' + paths-ignore: + - '*.md' + pull_request: + branches: + - 'main' + paths-ignore: + - '*.md' jobs: build_sdist: name: Build SDist runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - name: Build SDist - run: pipx run build --sdist + - uses: actions/checkout@v2 - - name: Check metadata - run: pipx run twine check dist/* + - name: Build SDist + run: pipx run build --sdist - - uses: actions/upload-artifact@v2 - with: - path: dist/*.tar.gz + - name: Check metadata + run: pipx run twine check dist/* + - uses: actions/upload-artifact@v2 + with: + path: dist/*.tar.gz build_wheels: name: Wheels on ${{ matrix.os }} @@ -32,16 +40,43 @@ jobs: os: - ubuntu-latest - macos-latest - # - windows-latest + - windows-latest steps: - uses: actions/checkout@v2 with: submodules: recursive + - name: Cache Conan + id: cache-conan + uses: actions/cache@v2 + if: matrix.os == 'windows-latest' + with: + path: | + conan_build + conan_data + key: conan-${{ matrix.os }}-${{ hashFiles('conanfile.txt') }} + + - name: Set up Windows Python ${{ matrix.python_version }} + uses: actions/setup-python@v2 + if: matrix.os == 'windows-latest' && steps.cache-conan.outputs.cache-hit != 'true' + with: + python-version: '3.x' + + - name: Install conan for Windows + if: matrix.os == 'windows-latest' && steps.cache-conan.outputs.cache-hit != 'true' + run: | + pip install pip --upgrade + pip install conan + conan profile new default --detect + conan profile update "settings.compiler=Visual Studio" default + conan profile update "settings.compiler.version=16" default + conan config set "storage.path=$env:GITHUB_WORKSPACE/conan_data" + conan install --build=openssl --install-folder conan_build . + - uses: pypa/cibuildwheel@v2.3.1 env: - MACOSX_DEPLOYMENT_TARGET: 10.15 + MACOSX_DEPLOYMENT_TARGET: 10.14 - name: Verify clean directory run: git diff --exit-code @@ -52,9 +87,9 @@ jobs: with: path: wheelhouse/*.whl - upload_all: name: Upload if release + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') needs: [build_wheels, build_sdist] runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index b6e4761..b7366db 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ __pycache__/ # Distribution / packaging .Python -build/ +*build/ develop-eggs/ dist/ downloads/ @@ -117,6 +117,9 @@ venv.bak/ # Rope project settings .ropeproject +# pycharm project settings +.idea + # mkdocs documentation /site diff --git a/README.md b/README.md index 664459f..1f9cd68 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ VROOM can also solve any mix of the above problem types. ## Installation -Pyvroom currently makes binaries for on MacOS and Linux. +Pyvroom currently makes binaries for on MacOS and Linux (Windows is WIP). Installation should be as simple as: @@ -27,6 +27,17 @@ Installation should be as simple as: pip install pyvroom ``` +## Building + +Building the source distributions on another OS requires: +- the `./build-requirements.txt` Python dependencies +- `asio` headers installed +- `openssl` & `crypto` libraries & headers installed + +Optionally the C++ dependencies can be installed with [`conan`](https://github.com/conan-io/conan): +```shell script +conan install --build=openssl --install-folder conan_build . +``` ## Basic usage ```python diff --git a/build-requirements.txt b/build-requirements.txt new file mode 100644 index 0000000..937e889 --- /dev/null +++ b/build-requirements.txt @@ -0,0 +1,5 @@ +setuptools>=45 +wheel +setuptools_scm>=6.2 +setuptools_scm_git_archive +pybind11>=2.8.0 diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 0000000..72a05a6 --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,6 @@ +[requires] +openssl/1.1.1m +asio/1.21.0 + +[generators] +json diff --git a/pyproject.toml b/pyproject.toml index 49f811a..dd703e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,8 +46,3 @@ apk add openssl-dev before-all = """ brew install asio """ - -[tool.cibuildwheel.windows] -before-all = """ -choco install -y openssl -""" diff --git a/setup.py b/setup.py index b867313..55313cb 100644 --- a/setup.py +++ b/setup.py @@ -1,34 +1,63 @@ +import json +import logging import os import platform +from pathlib import Path from setuptools import setup from pybind11.setup_helpers import Pybind11Extension, build_ext -extra_compile_args = [ - "-MMD", - "-MP", - "-Wextra", - "-Wpedantic", - "-Wall", - "-O3", - "-DASIO_STANDALONE", - "-DNDEBUG", -] extra_link_args = [ "-lpthread", "-lssl", "-lcrypto", ] +extra_compile_args = [ + "-MMD", + "-MP", + "-Wextra", + "-Wpedantic", + "-Wall", + "-O3", + "-DASIO_STANDALONE", + "-DNDEBUG", + ] include_dirs = [os.path.join("vroom", "src")] +libraries = [] +library_dirs = [] + +# try conan dependency resolution +conanfile = tuple(Path(__file__).parent.resolve().rglob('conanbuildinfo.json')) +if conanfile: + logging.info("Using conan to resolve dependencies.") + with conanfile[0].open() as f: + conan_deps = json.load(f)['dependencies'] + for dep in conan_deps: + include_dirs.extend(dep['include_paths']) + libraries.extend(dep['libs']) + libraries.extend(dep['system_libs']) + library_dirs.extend(dep['lib_paths']) +else: + logging.warning('Conan not installed and/or no conan build detected. Assuming dependencies are installed.') if platform.system() == "Darwin": # Homebrew puts include folders in weird places. include_dirs.append("/usr/local/opt/openssl@1.1/include") extra_link_args.insert(0, "-L/usr/local/opt/openssl@1.1/lib") +elif platform.system() == "Windows": + extra_compile_args = [ + "-DNOGDI", + "-DNOMINMAX", + "-DWIN32_LEAN_AND_MEAN", + "-DASIO_STANDALONE" + ] + extra_link_args = [] ext_modules = [ Pybind11Extension( "_vroom", [os.path.join("src", "_vroom.cpp")], + library_dirs=library_dirs, + libraries=libraries, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args, ),