Skip to content

Commit

Permalink
Build binary wheels for Windows using Appveyor.
Browse files Browse the repository at this point in the history
  • Loading branch information
codypiersall committed Sep 21, 2016
1 parent a6d24e5 commit ebb581e
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 18 deletions.
17 changes: 10 additions & 7 deletions _nanomsg_cpy/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,19 +391,22 @@ _nanomsg_cpy_nn_poll(PyObject *self, PyObject *args)
PyObject *socket_event_dict, *sockets;
Py_ssize_t socket_count;
struct nn_pollfd *fds;

Py_ssize_t pos;
int i;
PyObject *key, *value;
PyObject *code;
PyObject *result;
if (!PyArg_ParseTuple(args, "O!i", &PyDict_Type, &socket_event_dict, &timeout_ms)) {
return NULL;
}

sockets = PyDict_New();
sockets = PyDict_New();
socket_count = PyDict_Size(socket_event_dict);
fds = malloc(sizeof(struct nn_pollfd)*socket_count);

// build up fds array
Py_ssize_t pos = 0;
int i = 0;
PyObject *key, *value;
pos = 0;
i = 0;
while (PyDict_Next(socket_event_dict, &pos, &key, &value)) {
fds[i].fd = (int)PyLong_AsLong(key);
fds[i].events = (short)PyLong_AsLong(value);
Expand All @@ -426,8 +429,8 @@ _nanomsg_cpy_nn_poll(PyObject *self, PyObject *args)

free(fds);

PyObject *code = PyLong_FromUnsignedLong(res);
PyObject *result = PyTuple_Pack(2, code, sockets);
code = PyLong_FromUnsignedLong(res);
result = PyTuple_Pack(2, code, sockets);

return result;
}
Expand Down
61 changes: 61 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# The template for this file was from https://packaging.python.org/appveyor/

environment:
matrix:
# For Python versions available on Appveyor, see
# http://www.appveyor.com/docs/installed-software#python
- PYTHON: "C:\\Python27"
CMAKE_GENERATOR: "Visual Studio 9 2008"
- PYTHON: "C:\\Python34"
CMAKE_GENERATOR: "Visual Studio 10 2010"
- PYTHON: "C:\\Python35"
CMAKE_GENERATOR: "Visual Studio 14 2015"
- PYTHON: "C:\\Python34-x64"
CMAKE_GENERATOR: "Visual Studio 10 2010 Win64"
DISTUTILS_USE_SDK: "1"
- PYTHON: "C:\\Python35-x64"
CMAKE_GENERATOR: "Visual Studio 14 2015 Win64"

install:
# We need wheel installed to build wheels
- "%PYTHON%\\python.exe -m pip install wheel"
# Visual Studio 9 2008 does not come with stdint.h, so we'll copy over a
# different version. We only need to do it whenever we're building with
# 2008, but it doesn't hurt to copy it unconditionally. The first copy is to
# build nanomsg, the second is to build the extension.
- ps: cp "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\include\\stdint.h"
"C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\include\\stdint.h"
- ps: cp "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\include\\stdint.h"
"C:\\Users\\appveyor\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\include\\stdint.h"
- git clone https://github.com/nanomsg/nanomsg.git nanomsg-src
- pwd
- ps: pushd nanomsg-src
- git checkout 1.0.0
- ps: mkdir build
- ps: cd build
- cmake -DNN_STATIC_LIB=ON -G"%CMAKE_GENERATOR%" ..
- cmake --build .
- cmake --build . --target install
- ps: cp Debug\nanomsg.lib ..\..
- ps: popd
- pwd

build_script:
- "%PYTHON%\\python.exe setup.py install"

test_script:
- "build.cmd %PYTHON%\\python.exe setup.py test"

after_test:
# build the wheel.
# build.cmd sets up necessary variables for 64-bit builds
- "build.cmd %PYTHON%\\python.exe setup.py bdist_wheel"

artifacts:
# bdist_wheel puts your built wheel in the dist directory
- path: dist\*

#on_success:
# You can use this step to upload your artifacts to a public website.
# See Appveyor's documentation for more details. Or you can simply
# access your wheels from the Appveyor "artifacts" tab for your build.
21 changes: 21 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@echo off
:: To build extensions for 64 bit Python 3, we need to configure environment
:: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of:
:: MS Windows SDK for Windows 7 and .NET Framework 4
::
:: More details at:
:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows

IF "%DISTUTILS_USE_SDK%"=="1" (
ECHO Configuring environment to build with MSVC on a 64bit architecture
ECHO Using Windows SDK 7.1
"C:\Program Files\Microsoft SDKs\Windows\v7.1\Setup\WindowsSdkVer.exe" -q -version:v7.1
CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 /release
SET MSSdk=1
REM Need the following to allow tox to see the SDK compiler
SET TOX_TESTENV_PASSENV=DISTUTILS_USE_SDK MSSdk INCLUDE LIB
) ELSE (
ECHO Using default MSVC build environment
)

CALL %*
34 changes: 24 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
unicode_literals

import os
import platform
import sys
try:
from setuptools import setup
Expand Down Expand Up @@ -37,6 +38,18 @@ def run(self):
print("=" * 79)
print()

libraries = [str('nanomsg')]
# add additional necessary library/include path info if we're on Windows
if sys.platform in ("win32", "cygwin"):
libraries.extend([str('ws2_32'), str('advapi32'), str('mswsock')])
# nanomsg installs to different directory based on architecture
arch = platform.architecture()[0]
if arch == "64bit":
include_dirs=[r'C:\Program Files\nanomsg\include',]
else:
include_dirs=[r'C:\Program Files (x86)\nanomsg\include',]
else:
include_dirs = None
try:
import ctypes
if sys.platform in ('win32', 'cygwin'):
Expand All @@ -46,18 +59,19 @@ def run(self):
else:
_lib = ctypes.cdll.LoadLibrary('libnanoconfig.so')
except OSError:
# Building without nanoconfig
cpy_extension = Extension(str('_nanomsg_cpy'),
sources=[str('_nanomsg_cpy/wrapper.c')],
libraries=[str('nanomsg')],
)
# Building without nanoconfig; need to turn NN_STATIC_LIB on
define_macros = [('NN_STATIC_LIB','ON')]
else:
# Building with nanoconfig
cpy_extension = Extension(str('_nanomsg_cpy'),
define_macros=[('WITH_NANOCONFIG', '1')],
sources=[str('_nanomsg_cpy/wrapper.c')],
libraries=[str('nanomsg'), str('nanoconfig')],
)
libraries.append(str('nanoconfig'))
define_macros = [('WITH_NANOCONFIG', '1')]

cpy_extension = Extension(str('_nanomsg_cpy'),
define_macros=define_macros,
sources=[str('_nanomsg_cpy/wrapper.c')],
libraries=libraries,
include_dirs=include_dirs,
)
install_requires = []

try:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_poll_timeout(self):
timeout = .05
r, _ = poll([s1, s2], [], timeout)
end_time = time.time()
self.assertTrue(end_time-start_time-timeout < .010)
self.assertTrue(end_time-start_time-timeout < .030)
self.assertEqual(0, len(r), "No sockets to read")


Expand Down

0 comments on commit ebb581e

Please sign in to comment.