Skip to content

Commit ebb581e

Browse files
committed
Build binary wheels for Windows using Appveyor.
1 parent a6d24e5 commit ebb581e

File tree

5 files changed

+117
-18
lines changed

5 files changed

+117
-18
lines changed

_nanomsg_cpy/wrapper.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,19 +391,22 @@ _nanomsg_cpy_nn_poll(PyObject *self, PyObject *args)
391391
PyObject *socket_event_dict, *sockets;
392392
Py_ssize_t socket_count;
393393
struct nn_pollfd *fds;
394-
394+
Py_ssize_t pos;
395+
int i;
396+
PyObject *key, *value;
397+
PyObject *code;
398+
PyObject *result;
395399
if (!PyArg_ParseTuple(args, "O!i", &PyDict_Type, &socket_event_dict, &timeout_ms)) {
396400
return NULL;
397401
}
398402

399-
sockets = PyDict_New();
403+
sockets = PyDict_New();
400404
socket_count = PyDict_Size(socket_event_dict);
401405
fds = malloc(sizeof(struct nn_pollfd)*socket_count);
402406

403407
// build up fds array
404-
Py_ssize_t pos = 0;
405-
int i = 0;
406-
PyObject *key, *value;
408+
pos = 0;
409+
i = 0;
407410
while (PyDict_Next(socket_event_dict, &pos, &key, &value)) {
408411
fds[i].fd = (int)PyLong_AsLong(key);
409412
fds[i].events = (short)PyLong_AsLong(value);
@@ -426,8 +429,8 @@ _nanomsg_cpy_nn_poll(PyObject *self, PyObject *args)
426429

427430
free(fds);
428431

429-
PyObject *code = PyLong_FromUnsignedLong(res);
430-
PyObject *result = PyTuple_Pack(2, code, sockets);
432+
code = PyLong_FromUnsignedLong(res);
433+
result = PyTuple_Pack(2, code, sockets);
431434

432435
return result;
433436
}

appveyor.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# The template for this file was from https://packaging.python.org/appveyor/
2+
3+
environment:
4+
matrix:
5+
# For Python versions available on Appveyor, see
6+
# http://www.appveyor.com/docs/installed-software#python
7+
- PYTHON: "C:\\Python27"
8+
CMAKE_GENERATOR: "Visual Studio 9 2008"
9+
- PYTHON: "C:\\Python34"
10+
CMAKE_GENERATOR: "Visual Studio 10 2010"
11+
- PYTHON: "C:\\Python35"
12+
CMAKE_GENERATOR: "Visual Studio 14 2015"
13+
- PYTHON: "C:\\Python34-x64"
14+
CMAKE_GENERATOR: "Visual Studio 10 2010 Win64"
15+
DISTUTILS_USE_SDK: "1"
16+
- PYTHON: "C:\\Python35-x64"
17+
CMAKE_GENERATOR: "Visual Studio 14 2015 Win64"
18+
19+
install:
20+
# We need wheel installed to build wheels
21+
- "%PYTHON%\\python.exe -m pip install wheel"
22+
# Visual Studio 9 2008 does not come with stdint.h, so we'll copy over a
23+
# different version. We only need to do it whenever we're building with
24+
# 2008, but it doesn't hurt to copy it unconditionally. The first copy is to
25+
# build nanomsg, the second is to build the extension.
26+
- ps: cp "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\include\\stdint.h"
27+
"C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\include\\stdint.h"
28+
- ps: cp "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\include\\stdint.h"
29+
"C:\\Users\\appveyor\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\include\\stdint.h"
30+
- git clone https://github.com/nanomsg/nanomsg.git nanomsg-src
31+
- pwd
32+
- ps: pushd nanomsg-src
33+
- git checkout 1.0.0
34+
- ps: mkdir build
35+
- ps: cd build
36+
- cmake -DNN_STATIC_LIB=ON -G"%CMAKE_GENERATOR%" ..
37+
- cmake --build .
38+
- cmake --build . --target install
39+
- ps: cp Debug\nanomsg.lib ..\..
40+
- ps: popd
41+
- pwd
42+
43+
build_script:
44+
- "%PYTHON%\\python.exe setup.py install"
45+
46+
test_script:
47+
- "build.cmd %PYTHON%\\python.exe setup.py test"
48+
49+
after_test:
50+
# build the wheel.
51+
# build.cmd sets up necessary variables for 64-bit builds
52+
- "build.cmd %PYTHON%\\python.exe setup.py bdist_wheel"
53+
54+
artifacts:
55+
# bdist_wheel puts your built wheel in the dist directory
56+
- path: dist\*
57+
58+
#on_success:
59+
# You can use this step to upload your artifacts to a public website.
60+
# See Appveyor's documentation for more details. Or you can simply
61+
# access your wheels from the Appveyor "artifacts" tab for your build.

build.cmd

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@echo off
2+
:: To build extensions for 64 bit Python 3, we need to configure environment
3+
:: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of:
4+
:: MS Windows SDK for Windows 7 and .NET Framework 4
5+
::
6+
:: More details at:
7+
:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows
8+
9+
IF "%DISTUTILS_USE_SDK%"=="1" (
10+
ECHO Configuring environment to build with MSVC on a 64bit architecture
11+
ECHO Using Windows SDK 7.1
12+
"C:\Program Files\Microsoft SDKs\Windows\v7.1\Setup\WindowsSdkVer.exe" -q -version:v7.1
13+
CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 /release
14+
SET MSSdk=1
15+
REM Need the following to allow tox to see the SDK compiler
16+
SET TOX_TESTENV_PASSENV=DISTUTILS_USE_SDK MSSdk INCLUDE LIB
17+
) ELSE (
18+
ECHO Using default MSVC build environment
19+
)
20+
21+
CALL %*

setup.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
unicode_literals
33

44
import os
5+
import platform
56
import sys
67
try:
78
from setuptools import setup
@@ -37,6 +38,18 @@ def run(self):
3738
print("=" * 79)
3839
print()
3940

41+
libraries = [str('nanomsg')]
42+
# add additional necessary library/include path info if we're on Windows
43+
if sys.platform in ("win32", "cygwin"):
44+
libraries.extend([str('ws2_32'), str('advapi32'), str('mswsock')])
45+
# nanomsg installs to different directory based on architecture
46+
arch = platform.architecture()[0]
47+
if arch == "64bit":
48+
include_dirs=[r'C:\Program Files\nanomsg\include',]
49+
else:
50+
include_dirs=[r'C:\Program Files (x86)\nanomsg\include',]
51+
else:
52+
include_dirs = None
4053
try:
4154
import ctypes
4255
if sys.platform in ('win32', 'cygwin'):
@@ -46,18 +59,19 @@ def run(self):
4659
else:
4760
_lib = ctypes.cdll.LoadLibrary('libnanoconfig.so')
4861
except OSError:
49-
# Building without nanoconfig
50-
cpy_extension = Extension(str('_nanomsg_cpy'),
51-
sources=[str('_nanomsg_cpy/wrapper.c')],
52-
libraries=[str('nanomsg')],
53-
)
62+
# Building without nanoconfig; need to turn NN_STATIC_LIB on
63+
define_macros = [('NN_STATIC_LIB','ON')]
5464
else:
5565
# Building with nanoconfig
56-
cpy_extension = Extension(str('_nanomsg_cpy'),
57-
define_macros=[('WITH_NANOCONFIG', '1')],
58-
sources=[str('_nanomsg_cpy/wrapper.c')],
59-
libraries=[str('nanomsg'), str('nanoconfig')],
60-
)
66+
libraries.append(str('nanoconfig'))
67+
define_macros = [('WITH_NANOCONFIG', '1')]
68+
69+
cpy_extension = Extension(str('_nanomsg_cpy'),
70+
define_macros=define_macros,
71+
sources=[str('_nanomsg_cpy/wrapper.c')],
72+
libraries=libraries,
73+
include_dirs=include_dirs,
74+
)
6175
install_requires = []
6276

6377
try:

tests/test_poll.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_poll_timeout(self):
6868
timeout = .05
6969
r, _ = poll([s1, s2], [], timeout)
7070
end_time = time.time()
71-
self.assertTrue(end_time-start_time-timeout < .010)
71+
self.assertTrue(end_time-start_time-timeout < .030)
7272
self.assertEqual(0, len(r), "No sockets to read")
7373

7474

0 commit comments

Comments
 (0)