From 8062e6f4018bb7d999b9761c1540991b02447f4c Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Thu, 17 Oct 2019 00:20:03 -0700 Subject: [PATCH] Adding Windows 32-bit and 64-bit builds - Basic tests are working - May need some adjustments to get all tests working - Cleaned up bundling to take Python arch into account when building with multiple architectures --- .github/workflows/pythonpackage.yml | 4 +--- buildutils/build.py | 13 ++++++++++--- buildutils/detect.py | 3 ++- capnp/helpers/checkCompiler.h | 11 ++++------- capnp/includes/capnp_cpp.pxd | 1 - capnp/includes/schema_cpp.pxd | 1 - capnp/lib/capnp.pyx | 1 - capnp/templates/module.pyx | 1 - setup.py | 21 ++++++++++++++++----- 9 files changed, 33 insertions(+), 23 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index daf985d..2fb80b2 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -27,14 +27,12 @@ jobs: pip install -r requirements.txt - name: Build pycapnp and install run: | - python setup.py build # Not necessary, but shows output on stdout + python setup.py build pip install . - name: Lint with flake8 run: | pip install flake8 - # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude benchmark - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude benchmark - name: Test with pytest run: | diff --git a/buildutils/build.py b/buildutils/build.py index b9d6ff1..f355d1c 100644 --- a/buildutils/build.py +++ b/buildutils/build.py @@ -13,7 +13,7 @@ def build_libcapnp(bundle_dir, build_dir): bundle_dir = os.path.abspath(bundle_dir) capnp_dir = os.path.join(bundle_dir, 'capnproto-c++') build_dir = os.path.abspath(build_dir) - tmp_dir = os.path.join(capnp_dir, 'build') + tmp_dir = os.path.join(capnp_dir, 'build{}'.format(8 * struct.calcsize("P"))) # Clean the tmp build directory every time if os.path.exists(tmp_dir): @@ -31,6 +31,7 @@ def build_libcapnp(bundle_dir, build_dir): # Determine python shell architecture python_arch = 8 * struct.calcsize("P") build_arch = [] + build_flags = [] if os.name == 'nt': if python_arch == 64: build_arch_flag = "x64" @@ -39,8 +40,12 @@ def build_libcapnp(bundle_dir, build_dir): else: raise RuntimeError('Unknown windows build arch') build_arch = ['-A', build_arch_flag] + build_flags = ['--config', 'Release'] print('Building module for {}'.format(python_arch)) + if not shutil.which('cmake'): + raise RuntimeError('Could not find cmake in your path!') + args = [ 'cmake', '-DCMAKE_POSITION_INDEPENDENT_CODE=1', @@ -57,13 +62,15 @@ def build_libcapnp(bundle_dir, build_dir): raise RuntimeError('CMake failed {}'.format(returncode)) # Run build through cmake - build = subprocess.Popen([ + args = [ 'cmake', '--build', '.', '--target', 'install', - ], cwd=tmp_dir, stdout=sys.stdout) + ] + args.extend(build_flags) + build = subprocess.Popen(args, cwd=tmp_dir, stdout=sys.stdout) returncode = build.wait() if cxxflags is None: del os.environ['CXXFLAGS'] diff --git a/buildutils/detect.py b/buildutils/detect.py index 4a1c117..b9771f2 100644 --- a/buildutils/detect.py +++ b/buildutils/detect.py @@ -58,7 +58,8 @@ def test_compilation(cfile, compiler=None, **compiler_attrs): else: lpreargs = ['-m64'] extra_compile_args = compiler_attrs.get('extra_compile_args', []) - extra_compile_args += ['--std=c++14'] + if os.name != 'nt': + extra_compile_args += ['--std=c++14'] extra_link_args = compiler_attrs.get('extra_link_args', []) if cc.compiler_type == 'msvc': extra_link_args += ['/MANIFEST'] diff --git a/capnp/helpers/checkCompiler.h b/capnp/helpers/checkCompiler.h index ed8d427..c5e34c1 100644 --- a/capnp/helpers/checkCompiler.h +++ b/capnp/helpers/checkCompiler.h @@ -1,11 +1,8 @@ -#ifdef __GNUC__ - #if __clang__ - #if __cplusplus >= 201103L && !__has_include() - #warning "Your compiler supports C++11 but your C++ standard library does not. If your system has libc++ installed (as should be the case on e.g. Mac OSX), try adding -stdlib=libc++ to your CFLAGS (ignore the other warning that says to use CXXFLAGS)." - #endif - #endif +#ifdef _MSC_VER +#pragma comment(lib, "Ws2_32.lib") +#pragma comment(lib, "advapi32.lib") #endif #include "capnp/dynamic.h" -static_assert(CAPNP_VERSION >= 5000, "Version of Cap'n Proto C++ Library is too old. Please upgrade to a version >= 0.5 and then re-install this python library"); +static_assert(CAPNP_VERSION >= 7000, "Version of Cap'n Proto C++ Library is too old. Please upgrade to a version >= 0.7 and then re-install this python library"); \ No newline at end of file diff --git a/capnp/includes/capnp_cpp.pxd b/capnp/includes/capnp_cpp.pxd index 9e53c51..4ba2fc4 100644 --- a/capnp/includes/capnp_cpp.pxd +++ b/capnp/includes/capnp_cpp.pxd @@ -1,6 +1,5 @@ # schema.capnp.cpp.pyx # distutils: language = c++ -# distutils: extra_compile_args = --std=c++14 cdef extern from "capnp/helpers/checkCompiler.h": pass diff --git a/capnp/includes/schema_cpp.pxd b/capnp/includes/schema_cpp.pxd index c0ba23f..2c6ca2e 100644 --- a/capnp/includes/schema_cpp.pxd +++ b/capnp/includes/schema_cpp.pxd @@ -1,6 +1,5 @@ # schema.capnp.cpp.pyx # distutils: language = c++ -# distutils: extra_compile_args = --std=c++14 from libc.stdint cimport * from capnp_cpp cimport DynamicOrphan diff --git a/capnp/lib/capnp.pyx b/capnp/lib/capnp.pyx index a222e2b..3c2f490 100644 --- a/capnp/lib/capnp.pyx +++ b/capnp/lib/capnp.pyx @@ -1,6 +1,5 @@ # capnp.pyx # distutils: language = c++ -# distutils: extra_compile_args = --std=c++14 # distutils: libraries = capnpc capnp-rpc capnp kj-async kj # distutils: include_dirs = . # cython: c_string_type = str diff --git a/capnp/templates/module.pyx b/capnp/templates/module.pyx index 1dcf7f5..e0ed81c 100644 --- a/capnp/templates/module.pyx +++ b/capnp/templates/module.pyx @@ -1,6 +1,5 @@ # addressbook_fast.pyx # distutils: language = c++ -# distutils: extra_compile_args = --std=c++14 # distutils: include_dirs = {{include_dir}} # distutils: libraries = capnpc capnp capnp-rpc # distutils: sources = {{file.filename}}.cpp diff --git a/setup.py b/setup.py index 5aa9829..db57b62 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ pycapnp-async distutils setup.py from __future__ import print_function import os +import struct import sys from distutils.command.clean import clean as _clean @@ -13,7 +14,7 @@ from distutils.errors import CompileError from distutils.extension import Extension from distutils.spawn import find_executable -from setuptools import setup +from setuptools import setup, find_packages, Extension from buildutils import test_build, fetch_libcapnp, build_libcapnp, info @@ -138,7 +139,7 @@ class build_libcapnp_ext(build_ext_c): bundle_dir = os.path.join(_this_dir, "bundled") if not os.path.exists(bundle_dir): os.mkdir(bundle_dir) - build_dir = os.path.join(_this_dir, "build") + build_dir = os.path.join(_this_dir, "build{}".format(8 * struct.calcsize("P"))) if not os.path.exists(build_dir): os.mkdir(build_dir) @@ -159,10 +160,20 @@ class build_libcapnp_ext(build_ext_c): return build_ext_c.run(self) +extra_compile_args = ['--std=c++14'] +extra_link_args = [] +if os.name == 'nt': + extra_compile_args = ['/std:c++14', '/MD'] + extra_link_args = ['/MANIFEST'] -from Cython.Build import cythonize +import Cython.Build import Cython # noqa: F401 -extensions = cythonize('capnp/lib/*.pyx') +extensions = [Extension( + '*', ['capnp/lib/*.pyx'], + extra_compile_args=extra_compile_args, + extra_link_args=extra_link_args, + language='c++', +)] setup( name="pycapnp-async", @@ -174,7 +185,7 @@ setup( 'includes/*.pxd', 'lib/*.pxd', 'lib/*.py', 'lib/*.pyx', 'templates/*' ] }, - ext_modules=extensions, + ext_modules=Cython.Build.cythonize(extensions), cmdclass={ 'clean': clean, 'build_ext': build_libcapnp_ext