Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default target Windows version of Python itself #1475

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- buildutils/**
- .github/workflows/wheels.yml
- tools/install_libzmq.sh
- zmq/utils/*.h

env:
cython: "0.29.21"
Expand Down
1 change: 1 addition & 0 deletions buildutils/_cffi.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <string.h>

#include "pyversion_compat.h"
#include "mutex.h"
#include "ipcmaxlen.h"
#include "zmq_compat.h"
Expand Down
12 changes: 12 additions & 0 deletions buildutils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,21 @@ def discover_settings(conf_base=None):
'bundle_msvcp': None,
'build_ext': {},
'bdist_egg': {},
'win_ver': None,
}
if sys.platform.startswith('win'):
settings['have_sys_un_h'] = False
# target Windows version, sets WINVER, _WIN32_WINNT macros
# see https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt for reference
# see https://github.com/python/cpython/blob/v3.9.1/PC/pyconfig.h#L137-L159
# for CPython's own values
if sys.version_info >= (3, 9):
# CPython 3.9 targets Windows 8 (0x0602)
settings["win_ver"] = "0x0602"
else:
# older Python, target Windows 7 (0x0601)
# CPython itself targets Vista (0x0600)
settings["win_ver"] = "0x0601"

if conf_base:
# lowest priority
Expand Down
1 change: 1 addition & 0 deletions buildutils/templates/zmq_constants.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#ifndef _PYZMQ_CONSTANT_DEFS
#define _PYZMQ_CONSTANT_DEFS

Expand Down
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@ def init_settings_from_config(self):
if cfg['have_sys_un_h']:
settings['define_macros'].append(('HAVE_SYS_UN_H', 1))

if cfg['win_ver']:
# set target minimum Windows version
settings['define_macros'].extend([
('WINVER', cfg['win_ver']),
('_WIN32_WINNT', cfg['win_ver']),
])

if cfg.get('zmq_draft_api'):
settings['define_macros'].append(('ZMQ_BUILD_DRAFT_API', 1))

Expand Down
4 changes: 3 additions & 1 deletion zmq/backend/cffi/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def _buffer_from_zmq_msg(self):
for Frames created by recv
"""
if self._data is None:
self._data = ffi.buffer(C.zmq_msg_data(self.zmq_msg), C.zmq_msg_size(self.zmq_msg))
self._data = ffi.buffer(
C.zmq_msg_data(self.zmq_msg), C.zmq_msg_size(self.zmq_msg)
)
if self._buffer is None:
self._buffer = memoryview(self._data)

Expand Down
5 changes: 5 additions & 0 deletions zmq/backend/cython/libzmq.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
# Import the C header files
#-----------------------------------------------------------------------------

# common includes, such as zmq compat, pyversion_compat
# make sure we load pyversion compat in every Cython module
cdef extern from "pyversion_compat.h":
pass

# were it not for Windows,
# we could cimport these from libc.stdint
cdef extern from "zmq_compat.h":
Expand Down
1 change: 1 addition & 0 deletions zmq/utils/getpid_compat.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#ifdef _WIN32
#include <process.h>
#define getpid _getpid
Expand Down
2 changes: 2 additions & 0 deletions zmq/utils/ipcmaxlen.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Distributed under the terms of the New BSD License. The full license is in
the file COPYING.BSD, distributed as part of this software.
*/

#pragma once

#if defined(HAVE_SYS_UN_H)
#include "sys/un.h"
int get_ipc_path_max_len(void) {
Expand Down
12 changes: 12 additions & 0 deletions zmq/utils/pyversion_compat.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#include "Python.h"

// default to Python's own target Windows version(s)
// override by setting WINVER, _WIN32_WINNT, (maybe also NTDDI_VERSION?) macros
#ifdef Py_WINVER
#ifndef WINVER
#define WINVER Py_WINVER
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT Py_WINVER
#endif
#endif


#if PY_VERSION_HEX < 0x02070000
#define PyMemoryView_FromBuffer(info) (PyErr_SetString(PyExc_NotImplementedError, \
"new buffer interface is not available"), (PyObject *)NULL)
Expand Down
3 changes: 2 additions & 1 deletion zmq/utils/zmq_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// the file COPYING.BSD, distributed as part of this software.
//-----------------------------------------------------------------------------

#pragma once

#if defined(_MSC_VER)
#define pyzmq_int64_t __int64
#define pyzmq_uint32_t unsigned __int32
Expand Down Expand Up @@ -110,4 +112,3 @@
#define zmq_socket_monitor(s, addr, flags) _missing

#endif

1 change: 1 addition & 0 deletions zmq/utils/zmq_constants.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#ifndef _PYZMQ_CONSTANT_DEFS
#define _PYZMQ_CONSTANT_DEFS

Expand Down