def test_build(self, prefix, settings): """do a test build ob libzmq""" self.create_tempdir() settings = settings.copy() if self.bundle_libzmq_dylib and not sys.platform.startswith('win'): # rpath slightly differently here, because libzmq not in .. but ../zmq: settings['library_dirs'] = ['zmq'] if sys.platform == 'darwin': pass # unused rpath args for OS X: # settings['extra_link_args'] = ['-Wl,-rpath','-Wl,$ORIGIN/../zmq'] else: settings['runtime_library_dirs'] = [ os.path.abspath(pjoin('.', 'zmq')) ] line() info("Configure: Autodetecting ZMQ settings...") info(" Custom ZMQ dir: %s" % prefix) try: detected = detect_zmq(self.tempdir, compiler=self.compiler_type, **settings) finally: self.erase_tempdir() info(" ZMQ version detected: %s" % v_str(detected['vers'])) return detected
def fallback_on_bundled(self): """Couldn't build, fallback after waiting a while""" line() warn( "\n".join( [ "Failed to build or run libzmq detection test.", "", "If you expected pyzmq to link against an installed libzmq, please check to make sure:", "", " * You have a C compiler installed", " * A development version of Python is installed (including headers)", " * A development version of ZMQ >= %s is installed (including headers)" % v_str(min_zmq), " * If ZMQ is not in a default location, supply the argument --zmq=<path>", " * If you did recently install ZMQ to a default location,", " try rebuilding the ld cache with `sudo ldconfig`", " or specify zmq's location with `--zmq=/usr/local`", "", ] ) ) # ultra-lazy pip detection: if "pip" in " ".join(sys.argv): info( "\n".join( [ "If you expected to get a binary install (egg), we have those for", "current Pythons on OS X and Windows. These can be installed with", "easy_install, but PIP DOES NOT SUPPORT EGGS.", "", ] ) ) info( "\n".join( [ "You can skip all this detection/waiting nonsense if you know", "you want pyzmq to bundle libzmq as an extension by passing:", "", " `--zmq=bundled`", "", "I will now try to build libzmq as a Python extension", "unless you interrupt me (^C) in the next 10 seconds...", "", ] ) ) for i in range(10, 0, -1): sys.stdout.write("\r%2i..." % i) sys.stdout.flush() time.sleep(1) info("") return self.bundle_libzmq_extension()
def bundle_libzmq_extension(self): bundledir = "bundled" if "PyPy" in sys.version: fatal("Can't bundle libzmq as an Extension in PyPy (yet!)") ext_modules = self.distribution.ext_modules if ext_modules and ext_modules[0].name == "zmq.libzmq": # I've already been run return line() print("Using bundled libzmq") # fetch sources for libzmq extension: if not os.path.exists(bundledir): os.makedirs(bundledir) fetch_libzmq(bundledir) stage_platform_hpp(pjoin(bundledir, "zeromq")) # construct the Extension: ext = Extension( "zmq.libzmq", sources=[pjoin("buildutils", "initlibzmq.c")] + glob(pjoin(bundledir, "zeromq", "src", "*.cpp")), include_dirs=[pjoin(bundledir, "zeromq", "include")], ) if sys.platform.startswith("win"): # include defines from zeromq msvc project: ext.define_macros.append(("FD_SETSIZE", 1024)) ext.define_macros.append(("DLL_EXPORT", 1)) # When compiling the C++ code inside of libzmq itself, we want to # avoid "warning C4530: C++ exception handler used, but unwind # semantics are not enabled. Specify /EHsc". if self.compiler_type == "msvc": ext.extra_compile_args.append("/EHsc") elif self.compiler_type == "mingw32": ext.define_macros.append(("ZMQ_HAVE_MINGW32", 1)) # And things like sockets come from libraries that must be named. ext.libraries.extend(["rpcrt4", "ws2_32", "advapi32"]) elif not sys.platform.startswith(("darwin", "freebsd")): ext.include_dirs.append(bundledir) # check if we need to link against Realtime Extensions library cc = new_compiler(compiler=self.compiler_type) if not cc.has_function("timer_create"): ext.libraries.append("rt") # insert the extension: self.distribution.ext_modules.insert(0, ext) # update other extensions, with bundled settings self.config["libzmq_extension"] = True self.init_settings_from_config() self.save_config("config", self.config)
def bundle_libzmq_extension(self): bundledir = "bundled" if "PyPy" in sys.version: fatal("Can't bundle libzmq as an Extension in PyPy (yet!)") ext_modules = self.distribution.ext_modules if ext_modules and ext_modules[0].name == 'zmq.libzmq': # I've already been run return line() print ("Using bundled libzmq") # fetch sources for libzmq extension: if not os.path.exists(bundledir): os.makedirs(bundledir) fetch_libzmq(bundledir) stage_platform_hpp(pjoin(bundledir, 'zeromq')) # construct the Extension: ext = Extension( 'zmq.libzmq', sources = [pjoin('buildutils', 'initlibzmq.c')] + glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')), include_dirs = [ pjoin(bundledir, 'zeromq', 'include'), ], ) if sys.platform.startswith('win'): # include defines from zeromq msvc project: ext.define_macros.append(('FD_SETSIZE', 1024)) # When compiling the C++ code inside of libzmq itself, we want to # avoid "warning C4530: C++ exception handler used, but unwind # semantics are not enabled. Specify /EHsc". if self.compiler_type == 'msvc': ext.extra_compile_args.append('/EHsc') elif self.compiler_type == 'mingw32': ext.define_macros.append(('ZMQ_HAVE_MINGW32', 1)) # And things like sockets come from libraries that must be named. ext.libraries.extend(['rpcrt4', 'ws2_32', 'advapi32']) elif not sys.platform.startswith(('darwin', 'freebsd')): ext.include_dirs.append(bundledir) ext.libraries.append('rt') # insert the extension: self.distribution.ext_modules.insert(0, ext) # update other extensions, with bundled settings self.config['libzmq_extension'] = True self.init_settings_from_config() self.save_config('config', self.config)
def run(self): if self.zmq == "bundled": self.config = self.bundle_libzmq_extension() line() return config = None # When cross-compiling and zmq is given explicitly, we can't testbuild # (as we can't testrun the binary), we assume things are allright. if CROSSCOMPILE: self.config = dict(vers=ZMQVER) return # There is no available default on Windows, so start with fallback unless # zmq was given explicitly. if self.zmq is None and sys.platform.startswith("win"): config = self.fallback_on_bundled() self.zmq = "bundled" if config is None: # first try with given config or defaults try: config = self.test_build(self.zmq, self.settings) except Exception: etype, evalue, tb = sys.exc_info() # print the error as distutils would if we let it raise: print ("\nerror: %s\n" % evalue) # try fallback on /usr/local on *ix if config is None and self.zmq is None and not sys.platform.startswith('win'): print ("Failed with default libzmq, trying again with /usr/local") time.sleep(1) zmq = '/usr/local' settings = init_settings(zmq) try: config = self.test_build(zmq, settings) except Exception: etype, evalue, tb = sys.exc_info() # print the error as distutils would if we let it raise: print ("\nerror: %s\n" % evalue) else: # if we get here the second run succeeded, so we need to update compiler # settings for the extensions with /usr/local prefix self.zmq = zmq for ext in self.distribution.ext_modules: for attr,value in settings.items(): setattr(ext, attr, value) # finally, fallback on bundled if config is None and self.zmq is None: config = self.fallback_on_bundled() self.zmq = "bundled" save_config('configure', config) self.config = config line()
def check_zmq_version(self): """check the zmq version""" cfg = self.config # build test program zmq_prefix = cfg["zmq_prefix"] detected = self.test_build(zmq_prefix, self.compiler_settings) # now check the libzmq version vers = tuple(detected["vers"]) vs = v_str(vers) if cfg["allow_legacy_libzmq"]: min_zmq = min_legacy_zmq else: min_zmq = min_good_zmq if vers < min_zmq: msg = ["Detected ZMQ version: %s, but require ZMQ >= %s" % (vs, v_str(min_zmq))] if zmq_prefix: msg.append(" ZMQ_PREFIX=%s" % zmq_prefix) if vers >= min_legacy_zmq: msg.append(" Explicitly allow legacy zmq by specifying `--zmq=/zmq/prefix`") raise LibZMQVersionError("\n".join(msg)) if vers < min_good_zmq: msg = [ "Detected legacy ZMQ version: %s. It is STRONGLY recommended to use ZMQ >= %s" % (vs, v_str(min_good_zmq)) ] if zmq_prefix: msg.append(" ZMQ_PREFIX=%s" % zmq_prefix) warn("\n".join(msg)) elif vers < target_zmq: warn("Detected ZMQ version: %s, but pyzmq targets ZMQ %s." % (vs, v_str(target_zmq))) warn("libzmq features and fixes introduced after %s will be unavailable." % vs) line() elif vers >= dev_zmq: warn("Detected ZMQ version: %s. Some new features in libzmq may not be exposed by pyzmq." % vs) line() if sys.platform.startswith("win"): # fetch libzmq.dll into local dir local_dll = localpath("zmq", "libzmq.dll") if not zmq_prefix and not os.path.exists(local_dll): fatal( "ZMQ directory must be specified on Windows via setup.cfg or 'python setup.py configure --zmq=/path/to/zeromq2'" ) try: shutil.copy(pjoin(zmq_prefix, "lib", "libzmq.dll"), local_dll) except Exception: if not os.path.exists(local_dll): warn( "Could not copy libzmq into zmq/, which is usually necessary on Windows." "Please specify zmq prefix via configure --zmq=/path/to/zmq or copy " "libzmq into zmq/ manually." )
def bundle_libsodium_extension(self, libzmq): bundledir = "bundled" if "PyPy" in sys.version: fatal("Can't bundle libsodium as an Extension in PyPy (yet!)") ext_modules = self.distribution.ext_modules if ext_modules and any(m.name == 'zmq.libsodium' for m in ext_modules): # I've already been run return if not os.path.exists(bundledir): os.makedirs(bundledir) line() info("Using bundled libsodium") # fetch sources for libsodium fetch_libsodium(bundledir) # stage headers stage_libsodium_headers(pjoin(bundledir, 'libsodium')) # construct the Extension libsodium_src = pjoin(bundledir, 'libsodium', 'src', 'libsodium') exclude = pjoin(libsodium_src, 'crypto_stream', 'salsa20', 'amd64_xmm6') # or ref? exclude = pjoin(libsodium_src, 'crypto_scalarmult', 'curve25519', 'donna_c64') # or ref? libsodium_sources = [pjoin('buildutils', 'initlibsodium.c')] for dir,subdirs,files in os.walk(libsodium_src): if dir.startswith(exclude): continue for f in files: if f.endswith('.c'): libsodium_sources.append(pjoin(dir, f)) libsodium = Extension( 'zmq.libsodium', sources = libsodium_sources, include_dirs = [ pjoin(libsodium_src, 'include'), pjoin(libsodium_src, 'include', 'sodium'), ], ) # register the Extension self.distribution.ext_modules.insert(0, libsodium) if sys.byteorder == 'little': libsodium.define_macros.append(("NATIVE_LITTLE_ENDIAN", 1)) else: libsodium.define_macros.append(("NATIVE_BIG_ENDIAN", 1)) # tell libzmq about libsodium libzmq.define_macros.append(("HAVE_LIBSODIUM", 1)) libzmq.include_dirs.extend(libsodium.include_dirs)
def fallback_on_bundled(self): """Couldn't build, fallback after waiting a while""" line() warn( "\n".join( [ "Couldn't find an acceptable libzmq on the system.", "", "If you expected pyzmq to link against an installed libzmq, please check to make sure:", "", " * You have a C compiler installed", " * A development version of Python is installed (including headers)", " * A development version of ZMQ >= %s is installed (including headers)" % v_str(min_good_zmq), " * If ZMQ is not in a default location, supply the argument --zmq=<path>", " * If you did recently install ZMQ to a default location,", " try rebuilding the ld cache with `sudo ldconfig`", " or specify zmq's location with `--zmq=/usr/local`", "", ] ) ) info( "\n".join( [ "You can skip all this detection/waiting nonsense if you know", "you want pyzmq to bundle libzmq as an extension by passing:", "", " `--zmq=bundled`", "", "I will now try to build libzmq as a Python extension", "unless you interrupt me (^C) in the next 10 seconds...", "", ] ) ) for i in range(10, 0, -1): sys.stdout.write("\r%2i..." % i) sys.stdout.flush() time.sleep(1) info("") return self.bundle_libzmq_extension()
def test_build(self, prefix, settings): """do a test build ob libzmq""" self.create_tempdir() settings = settings.copy() if self.bundle_libzmq_dylib and not sys.platform.startswith('win'): # rpath slightly differently here, because libzmq not in .. but ../zmq: settings['library_dirs'] = ['zmq'] _add_rpath(settings, os.path.abspath(pjoin('.', 'zmq'))) line() info("Configure: Autodetecting ZMQ settings...") info(" Custom ZMQ dir: %s" % prefix) try: detected = detect_zmq(self.tempdir, compiler=self.compiler_type, **settings) finally: self.erase_tempdir() info(" ZMQ version detected: %s" % v_str(detected['vers'])) return detected
def check_zmq_version(self): """check the zmq version""" cfg = self.config # build test program zmq_prefix = self.config["zmq_prefix"] detected = self.test_build(zmq_prefix, self.compiler_settings) # now check the libzmq version vers = tuple(detected["vers"]) vs = v_str(vers) if vers < min_zmq: fatal( "Detected ZMQ version: %s, but depend on zmq >= %s" % (vs, v_str(min_zmq)) + "\n Using ZMQ=%s" % (zmq_prefix or "unspecified") ) if vers < target_zmq: warn("Detected ZMQ version: %s, but pyzmq targets ZMQ %s." % (vs, v_str(target_zmq))) warn("libzmq features and fixes introduced after %s will be unavailable." % vs) line() elif vers >= dev_zmq: warn("Detected ZMQ version: %s. pyzmq's support for libzmq-dev is experimental." % vs) line() if sys.platform.startswith("win"): # fetch libzmq.dll into local dir local_dll = localpath("zmq", "libzmq.dll") if not zmq_prefix and not os.path.exists(local_dll): fatal( "ZMQ directory must be specified on Windows via setup.cfg or 'python setup.py configure --zmq=/path/to/zeromq2'" ) try: shutil.copy(pjoin(zmq_prefix, "lib", "libzmq.dll"), local_dll) except Exception: if not os.path.exists(local_dll): warn( "Could not copy libzmq into zmq/, which is usually necessary on Windows." "Please specify zmq prefix via configure --zmq=/path/to/zmq or copy " "libzmq into zmq/ manually." )
def fallback_on_bundled(self): """Couldn't build, fallback after waiting a while""" line() warn('\n'.join([ "Couldn't find an acceptable libzmq on the system.", "", "If you expected pyzmq to link against an installed libzmq, please check to make sure:", "", " * You have a C compiler installed", " * A development version of Python is installed (including headers)", " * A development version of ZMQ >= %s is installed (including headers)" % v_str(min_good_zmq), " * If ZMQ is not in a default location, supply the argument --zmq=<path>", " * If you did recently install ZMQ to a default location,", " try rebuilding the ld cache with `sudo ldconfig`", " or specify zmq's location with `--zmq=/usr/local`", "", ])) info('\n'.join([ "You can skip all this detection/waiting nonsense if you know", "you want pyzmq to bundle libzmq as an extension by passing:", "", " `--zmq=bundled`", "", "I will now try to build libzmq as a Python extension", "unless you interrupt me (^C) in the next 10 seconds...", "", ])) for i in range(10, 0, -1): sys.stdout.write('\r%2i...' % i) sys.stdout.flush() time.sleep(1) info("") return self.bundle_libzmq_extension()
def check_zmq_version(self): """check the zmq version""" cfg = self.config # build test program zmq_prefix = self.config['zmq_prefix'] detected = self.test_build(zmq_prefix, self.compiler_settings) # now check the libzmq version vers = tuple(detected['vers']) vs = v_str(vers) if vers < min_zmq: fatal("Detected ZMQ version: %s, but depend on ZMQ >= %s"%( vs, v_str(min_zmq)) +'\n Using ZMQ=%s' % (zmq_prefix or 'unspecified')) if vers < target_zmq: warn("Detected ZMQ version: %s, but pyzmq targets ZMQ %s." % ( vs, v_str(target_zmq)) ) warn("libzmq features and fixes introduced after %s will be unavailable." % vs) line() elif vers >= dev_zmq: warn("Detected ZMQ version: %s. Some new features in libzmq may not be exposed by pyzmq." % vs) line() if sys.platform.startswith('win'): # fetch libzmq.dll into local dir local_dll = localpath('zmq','libzmq.dll') if not zmq_prefix and not os.path.exists(local_dll): fatal("ZMQ directory must be specified on Windows via setup.cfg or 'python setup.py configure --zmq=/path/to/zeromq2'") try: shutil.copy(pjoin(zmq_prefix, 'lib', 'libzmq.dll'), local_dll) except Exception: if not os.path.exists(local_dll): warn("Could not copy libzmq into zmq/, which is usually necessary on Windows." "Please specify zmq prefix via configure --zmq=/path/to/zmq or copy " "libzmq into zmq/ manually.")
def test_build(self, zmq, settings): self.create_tempdir() if bundle_libzmq_dylib and not sys.platform.startswith('win'): # rpath slightly differently here, because libzmq not in .. but ../zmq: settings['library_dirs'] = ['zmq'] if sys.platform == 'darwin': pass # unused rpath args for OSX: # settings['extra_link_args'] = ['-Wl,-rpath','-Wl,$ORIGIN/../zmq'] else: settings['runtime_library_dirs'] = ['$ORIGIN/../zmq'] line() print ("Configure: Autodetecting ZMQ settings...") print (" Custom ZMQ dir: %s" % zmq) try: config = detect_zmq(self.tempdir, **settings) finally: self.erase_tempdir() print (" ZMQ version detected: %s" % v_str(config['vers'])) return config
def test_build(self, zmq, settings): self.create_tempdir() if bundle_libzmq_dylib and not sys.platform.startswith('win'): # rpath slightly differently here, because libzmq not in .. but ../zmq: settings['library_dirs'] = ['zmq'] if sys.platform == 'darwin': pass # unused rpath args for OSX: # settings['extra_link_args'] = ['-Wl,-rpath','-Wl,$ORIGIN/../zmq'] else: settings['runtime_library_dirs'] = ['$ORIGIN/../zmq'] line() print ("Configure: Autodetecting ZMQ settings...") print (" Custom ZMQ dir: %s" % zmq) try: config = detect_zmq(self.tempdir, compiler=self.compiler_type, **settings) finally: self.erase_tempdir() print (" ZMQ version detected: %s" % v_str(config['vers'])) return config
def check_zmq_version(self): zmq = CONFIG['zmq_prefix'] if zmq and not os.path.exists(zmq) and \ not CONFIG['libzmq_extension']: fatal("Custom zmq directory \"%s\" does not exist" % zmq) config = self.getcached() if not config or config.get('settings') != self.settings: self.run() config = self.config else: if CONFIG['libzmq_extension']: config = self.bundle_libzmq_extension() self.config = config line() if CONFIG['libzmq_extension'] or CONFIG['skip_check_zmq'] or CROSSCOMPILE: return # now check the libzmq version vers = tuple(config['vers']) vs = v_str(vers) if vers < min_zmq: fatal("Detected ZMQ version: %s, but depend on zmq >= %s"%( vs, v_str(min_zmq)) +'\n Using ZMQ=%s'%(zmq or 'unspecified')) if vers < target_zmq: warn("Detected ZMQ version: %s, but pyzmq targets ZMQ %s." % ( vs, v_str(target_zmq)) ) warn("libzmq features and fixes introduced after %s will be unavailable." % vs) line() elif vers >= dev_zmq: warn("Detected ZMQ version: %s. pyzmq's support for libzmq-dev is experimental." % vs) line() if sys.platform.startswith('win'): # fetch libzmq.dll into local dir local_dll = localpath('zmq','libzmq.dll') if not zmq and not os.path.exists(local_dll): fatal("ZMQ directory must be specified on Windows via setup.cfg or 'python setup.py configure --zmq=/path/to/zeromq2'") try: shutil.copy(pjoin(zmq, 'lib', 'libzmq.dll'), local_dll) except Exception: if not os.path.exists(local_dll): warn("Could not copy libzmq into zmq/, which is usually necessary on Windows." "Please specify zmq prefix via configure --zmq=/path/to/zmq or copy " "libzmq into zmq/ manually.")
def check_zmq_version(self): zmq = self.zmq if zmq is not None and zmq is not "bundled" and not os.path.isdir(zmq): fatal("Custom zmq directory \"%s\" does not exist" % zmq) config = self.getcached() if not config or config.get('settings') != self.settings: self.run() config = self.config else: self.config = config line() if self.zmq == "bundled": return vers = config['vers'] vs = v_str(vers) if vers < min_zmq: fatal("Detected ZMQ version: %s, but depend on zmq >= %s" % (vs, v_str(min_zmq)) + '\n Using ZMQ=%s' % (zmq or 'unspecified')) pyzmq_version = extract_version().strip('abcdefghijklmnopqrstuvwxyz') if vs < pyzmq_version: warn("Detected ZMQ version: %s, but pyzmq targets zmq %s." % (vs, pyzmq_version)) warn( "libzmq features and fixes introduced after %s will be unavailable." % vs) line() elif vs >= '3.0': warn( "Detected ZMQ version: %s. pyzmq's support for libzmq-dev is experimental." % vs) line() if sys.platform.startswith('win'): # fetch libzmq.dll into local dir local_dll = localpath('zmq', 'libzmq.dll') if zmq is None and not os.path.exists(local_dll): fatal( "ZMQ directory must be specified on Windows via setup.cfg or 'python setup.py configure --zmq=/path/to/zeromq2'" ) try: shutil.copy(pjoin(zmq, 'lib', 'libzmq.dll'), local_dll) except Exception: if not os.path.exists(local_dll): warn( "Could not copy libzmq into zmq/, which is usually necessary on Windows." "Please specify zmq prefix via configure --zmq=/path/to/zmq or copy " "libzmq into zmq/ manually.")
def check_zmq_version(self): zmq = self.zmq if zmq is not None and zmq is not "bundled" and not os.path.isdir(zmq): fatal("Custom zmq directory \"%s\" does not exist" % zmq) config = self.getcached() if not config or config.get('settings') != self.settings: self.run() config = self.config else: self.config = config line() if self.zmq == "bundled": return vers = tuple(config['vers']) vs = v_str(vers) if vers < min_zmq: fatal("Detected ZMQ version: %s, but depend on zmq >= %s"%( vs, v_str(min_zmq)) +'\n Using ZMQ=%s'%(zmq or 'unspecified')) pyzmq_vs = extract_version() pyzmq_version = tuple(int(d) for d in re.findall(r'\d+', pyzmq_vs)) if vers < pyzmq_version[:len(vers)]: warn("Detected ZMQ version: %s, but pyzmq targets zmq %s."%( vs, pyzmq_version)) warn("libzmq features and fixes introduced after %s will be unavailable."%vs) line() elif vers >= (3,0,0): warn("Detected ZMQ version: %s. pyzmq's support for libzmq-dev is experimental."%vs) line() if sys.platform.startswith('win'): # fetch libzmq.dll into local dir local_dll = localpath('zmq','libzmq.dll') if zmq is None and not os.path.exists(local_dll): fatal("ZMQ directory must be specified on Windows via setup.cfg or 'python setup.py configure --zmq=/path/to/zeromq2'") try: shutil.copy(pjoin(zmq, 'lib', 'libzmq.dll'), local_dll) except Exception: if not os.path.exists(local_dll): warn("Could not copy libzmq into zmq/, which is usually necessary on Windows." "Please specify zmq prefix via configure --zmq=/path/to/zmq or copy " "libzmq into zmq/ manually.")
def bundle_libzmq_extension(self): bundledir = "bundled" if self.distribution.ext_modules[0].name == 'zmq.libzmq': # I've already been run return line() print ("Using bundled libzmq") # fetch sources for libzmq extension: if not os.path.exists(bundledir): os.makedirs(bundledir) if not sys.platform.startswith(('darwin', 'freebsd', 'win')): fetch_uuid(bundledir) fetch_libzmq(bundledir) stage_platform_hpp(pjoin(bundledir, 'zeromq')) # construct the Extension: ext = Extension( 'zmq.libzmq', sources = [pjoin('buildutils', 'initlibzmq.c')] + glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')), include_dirs = [ pjoin(bundledir, 'zeromq', 'include'), ], ) if sys.platform.startswith('win'): # include defines from zeromq msvc project: ext.define_macros.append(('FD_SETSIZE', 1024)) # When compiling the C++ code inside of libzmq itself, we want to # avoid "warning C4530: C++ exception handler used, but unwind # semantics are not enabled. Specify /EHsc". ext.extra_compile_args.append('/EHsc') # And things like sockets come from libraries that must be named. ext.libraries.append('rpcrt4') ext.libraries.append('ws2_32') elif not sys.platform.startswith(('darwin', 'freebsd')): # add uuid as both `uuid/uuid.h` and `uuid.h`: ext.include_dirs.append(pjoin(bundledir, 'uuid')) ext.include_dirs.append(bundledir) ext.sources.extend(glob(pjoin(bundledir, 'uuid', '*.c'))) ext.libraries.append('rt') # insert the extension: self.distribution.ext_modules.insert(0, ext) # update other extensions, with bundled settings settings = init_settings("bundled") for ext in self.distribution.ext_modules[1:]: for attr, value in settings.items(): setattr(ext, attr, value) save_config("buildconf", dict(zmq="bundled")) return dict(vers=bundled_version, settings=settings)
def bundle_libzmq_extension(self): bundledir = "bundled" if self.distribution.ext_modules[0].name == 'zmq.libzmq': # I've already been run return line() print ("Using bundled libzmq") # fetch sources for libzmq extension: if not os.path.exists(bundledir): os.makedirs(bundledir) if not sys.platform.startswith(('darwin', 'freebsd', 'win')): fetch_uuid(bundledir) fetch_libzmq(bundledir) stage_platform_hpp(pjoin(bundledir, 'zeromq')) # construct the Extension: ext = Extension( 'zmq.libzmq', sources = [pjoin('buildutils', 'initlibzmq.c')] + glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')), include_dirs = [ pjoin(bundledir, 'zeromq', 'include'), ], ) if sys.platform.startswith('win'): # include defines from zeromq msvc project: ext.define_macros.append(('FD_SETSIZE', 1024)) # When compiling the C++ code inside of libzmq itself, we want to # avoid "warning C4530: C++ exception handler used, but unwind # semantics are not enabled. Specify /EHsc". if self.compiler_type == 'msvc': ext.extra_compile_args.append('/EHsc') elif self.compiler_type == 'mingw32': ext.define_macros.append(('ZMQ_HAVE_MINGW32', 1)) # And things like sockets come from libraries that must be named. ext.libraries.append('rpcrt4') ext.libraries.append('ws2_32') elif not sys.platform.startswith(('darwin', 'freebsd')): # add uuid as both `uuid/uuid.h` and `uuid.h`: ext.include_dirs.append(pjoin(bundledir, 'uuid')) ext.include_dirs.append(bundledir) ext.sources.extend(glob(pjoin(bundledir, 'uuid', '*.c'))) ext.libraries.append('rt') # insert the extension: self.distribution.ext_modules.insert(0, ext) # update other extensions, with bundled settings settings = init_settings("bundled") for ext in self.distribution.ext_modules[1:]: for attr, value in settings.items(): setattr(ext, attr, value) save_config("buildconf", dict(zmq="bundled")) return dict(vers=bundled_version, settings=settings)
def bundle_libzmq_extension(self): bundledir = "bundled" ext_modules = self.distribution.ext_modules if ext_modules and any(m.name == 'zmq.libzmq' for m in ext_modules): # I've already been run return line() info("Using bundled libzmq") # fetch sources for libzmq extension: if not os.path.exists(bundledir): os.makedirs(bundledir) fetch_libzmq(bundledir) stage_platform_hpp(pjoin(bundledir, 'zeromq')) sources = [pjoin('buildutils', 'initlibzmq.c')] sources += glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')) includes = [ pjoin(bundledir, 'zeromq', 'include') ] if bundled_version < (4, 2, 0): tweetnacl = pjoin(bundledir, 'zeromq', 'tweetnacl') tweetnacl_sources = glob(pjoin(tweetnacl, 'src', '*.c')) randombytes = pjoin(tweetnacl, 'contrib', 'randombytes') if sys.platform.startswith('win'): tweetnacl_sources.append(pjoin(randombytes, 'winrandom.c')) else: tweetnacl_sources.append(pjoin(randombytes, 'devurandom.c')) sources += tweetnacl_sources includes.append(pjoin(tweetnacl, 'src')) includes.append(randombytes) else: # >= 4.2 sources += glob(pjoin(bundledir, 'zeromq', 'src', 'tweetnacl.c')) # construct the Extensions: libzmq = Extension( 'zmq.libzmq', sources=sources, include_dirs=includes, ) # register the extension: self.distribution.ext_modules.insert(0, libzmq) # use tweetnacl to provide CURVE support libzmq.define_macros.append(('ZMQ_HAVE_CURVE', 1)) libzmq.define_macros.append(('ZMQ_USE_TWEETNACL', 1)) # select polling subsystem based on platform if sys.platform == 'darwin' or 'bsd' in sys.platform: libzmq.define_macros.append(('ZMQ_USE_KQUEUE', 1)) elif 'linux' in sys.platform: libzmq.define_macros.append(('ZMQ_USE_EPOLL', 1)) elif sys.platform.startswith('win'): libzmq.define_macros.append(('ZMQ_USE_SELECT', 1)) else: # this may not be sufficiently precise libzmq.define_macros.append(('ZMQ_USE_POLL', 1)) if sys.platform.startswith('win'): # include defines from zeromq msvc project: libzmq.define_macros.append(('FD_SETSIZE', 16384)) libzmq.define_macros.append(('DLL_EXPORT', 1)) libzmq.define_macros.append(('_CRT_SECURE_NO_WARNINGS', 1)) # When compiling the C++ code inside of libzmq itself, we want to # avoid "warning C4530: C++ exception handler used, but unwind # semantics are not enabled. Specify /EHsc". if self.compiler_type == 'msvc': libzmq.extra_compile_args.append('/EHsc') elif self.compiler_type == 'mingw32': libzmq.define_macros.append(('ZMQ_HAVE_MINGW32', 1)) # And things like sockets come from libraries that must be named. libzmq.libraries.extend(['rpcrt4', 'ws2_32', 'advapi32']) # bundle MSCVP redist if self.config['bundle_msvcp']: cc = new_compiler(compiler=self.compiler_type) cc.initialize() # get vc_redist location via private API try: cc._vcruntime_redist except AttributeError: # fatal error if env set, warn otherwise msg = fatal if os.environ.get("PYZMQ_BUNDLE_CRT") else warn msg("Failed to get cc._vcruntime via private API, not bundling CRT") if cc._vcruntime_redist: redist_dir, dll = os.path.split(cc._vcruntime_redist) to_bundle = [ pjoin(redist_dir, dll.replace('vcruntime', name)) for name in ('msvcp', 'concrt') ] for src in to_bundle: dest = localpath('zmq', basename(src)) info("Copying %s -> %s" % (src, dest)) # copyfile to avoid permission issues shutil.copyfile(src, dest) else: libzmq.include_dirs.append(bundledir) # check if we need to link against Realtime Extensions library cc = new_compiler(compiler=self.compiler_type) cc.output_dir = self.build_temp if not sys.platform.startswith(('darwin', 'freebsd')): line() info("checking for timer_create") if not cc.has_function('timer_create'): info("no timer_create, linking librt") libzmq.libraries.append('rt') else: info("ok") if pypy: # seem to need explicit libstdc++ on linux + pypy # not sure why libzmq.libraries.append("stdc++") # copy the header files to the source tree. bundledincludedir = pjoin('zmq', 'include') if not os.path.exists(bundledincludedir): os.makedirs(bundledincludedir) if not os.path.exists(pjoin(self.build_lib, bundledincludedir)): os.makedirs(pjoin(self.build_lib, bundledincludedir)) for header in glob(pjoin(bundledir, 'zeromq', 'include', '*.h')): shutil.copyfile(header, pjoin(bundledincludedir, basename(header))) shutil.copyfile(header, pjoin(self.build_lib, bundledincludedir, basename(header))) # update other extensions, with bundled settings self.config['libzmq_extension'] = True self.init_settings_from_config() self.save_config('config', self.config)
def check_zmq_version(self): """check the zmq version""" cfg = self.config # build test program zmq_prefix = cfg['zmq_prefix'] detected = self.test_build(zmq_prefix, self.compiler_settings) # now check the libzmq version vers = tuple(detected['vers']) vs = v_str(vers) if cfg['allow_legacy_libzmq']: min_zmq = min_legacy_zmq else: min_zmq = min_good_zmq if vers < min_zmq: msg = [ "Detected ZMQ version: %s, but require ZMQ >= %s" % (vs, v_str(min_zmq)), ] if zmq_prefix: msg.append(" ZMQ_PREFIX=%s" % zmq_prefix) if vers >= min_legacy_zmq: msg.append( " Explicitly allow legacy zmq by specifying `--zmq=/zmq/prefix`" ) raise LibZMQVersionError('\n'.join(msg)) if vers < min_good_zmq: msg = [ "Detected legacy ZMQ version: %s. It is STRONGLY recommended to use ZMQ >= %s" % (vs, v_str(min_good_zmq)), ] if zmq_prefix: msg.append(" ZMQ_PREFIX=%s" % zmq_prefix) warn('\n'.join(msg)) elif vers < target_zmq: warn("Detected ZMQ version: %s, but pyzmq targets ZMQ %s." % (vs, v_str(target_zmq))) warn( "libzmq features and fixes introduced after %s will be unavailable." % vs) line() elif vers >= dev_zmq: warn( "Detected ZMQ version: %s. Some new features in libzmq may not be exposed by pyzmq." % vs) line() if sys.platform.startswith('win'): # fetch libzmq.dll into local dir local_dll = localpath('zmq', libzmq_name + '.dll') if not zmq_prefix and not os.path.exists(local_dll): fatal( "ZMQ directory must be specified on Windows via setup.cfg or 'python setup.py configure --zmq=/path/to/zeromq2'" ) try: shutil.copy(pjoin(zmq_prefix, 'lib', libzmq_name + '.dll'), local_dll) except Exception: if not os.path.exists(local_dll): warn( "Could not copy " + libzmq_name + " into zmq/, which is usually necessary on Windows." "Please specify zmq prefix via configure --zmq=/path/to/zmq or copy " + libzmq_name + " into zmq/ manually.")
def bundle_libzmq_extension(self): bundledir = "bundled" ext_modules = self.distribution.ext_modules if ext_modules and any(m.name == 'zmq.libzmq' for m in ext_modules): # I've already been run return line() info("Using bundled libzmq") # fetch sources for libzmq extension: if not os.path.exists(bundledir): os.makedirs(bundledir) fetch_libzmq(bundledir) stage_platform_hpp(pjoin(bundledir, 'zeromq')) tweetnacl = pjoin(bundledir, 'zeromq', 'tweetnacl') tweetnacl_sources = glob(pjoin(tweetnacl, 'src', '*.c')) randombytes = pjoin(tweetnacl, 'contrib', 'randombytes') if sys.platform.startswith('win'): tweetnacl_sources.append(pjoin(randombytes, 'winrandom.c')) else: tweetnacl_sources.append(pjoin(randombytes, 'devurandom.c')) # construct the Extensions: libzmq = Extension( 'zmq.libzmq', sources = [pjoin('buildutils', 'initlibzmq.c')] + \ glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')) + \ tweetnacl_sources, include_dirs = [ pjoin(bundledir, 'zeromq', 'include'), pjoin(tweetnacl, 'src'), randombytes, ], ) # register the extension: self.distribution.ext_modules.insert(0, libzmq) # use tweetnacl to provide CURVE support libzmq.define_macros.append(('HAVE_LIBSODIUM', 1)) libzmq.define_macros.append(('HAVE_TWEETNACL', 1)) # select polling subsystem based on platform if sys.platform == 'darwin' or 'bsd' in sys.platform: libzmq.define_macros.append(('ZMQ_USE_KQUEUE', 1)) elif 'linux' in sys.platform: libzmq.define_macros.append(('ZMQ_USE_EPOLL', 1)) elif sys.platform.startswith('win'): libzmq.define_macros.append(('ZMQ_USE_SELECT', 1)) else: # this may not be sufficiently precise libzmq.define_macros.append(('ZMQ_USE_POLL', 1)) if sys.platform.startswith('win'): # include defines from zeromq msvc project: libzmq.define_macros.append(('FD_SETSIZE', 1024)) libzmq.define_macros.append(('DLL_EXPORT', 1)) libzmq.define_macros.append(('_CRT_SECURE_NO_WARNINGS', 1)) # When compiling the C++ code inside of libzmq itself, we want to # avoid "warning C4530: C++ exception handler used, but unwind # semantics are not enabled. Specify /EHsc". if self.compiler_type == 'msvc': libzmq.extra_compile_args.append('/EHsc') elif self.compiler_type == 'mingw32': libzmq.define_macros.append(('ZMQ_HAVE_MINGW32', 1)) # And things like sockets come from libraries that must be named. libzmq.libraries.extend(['rpcrt4', 'ws2_32', 'advapi32']) else: libzmq.include_dirs.append(bundledir) # check if we need to link against Realtime Extensions library cc = new_compiler(compiler=self.compiler_type) cc.output_dir = self.build_temp if not sys.platform.startswith(('darwin', 'freebsd')): line() info("checking for timer_create") if not cc.has_function('timer_create'): info("no timer_create, linking librt") libzmq.libraries.append('rt') else: info("ok") if pypy: # seem to need explicit libstdc++ on linux + pypy # not sure why libzmq.libraries.append("stdc++") # update other extensions, with bundled settings self.config['libzmq_extension'] = True self.init_settings_from_config() self.save_config('config', self.config)
def bundle_libzmq_extension(self): bundledir = "bundled" ext_modules = self.distribution.ext_modules if ext_modules and any(m.name == 'zmq.libzmq' for m in ext_modules): # I've already been run return line() info("Using bundled libzmq") # fetch sources for libzmq extension: if not os.path.exists(bundledir): os.makedirs(bundledir) fetch_libzmq(bundledir) stage_platform_hpp(pjoin(bundledir, 'zeromq')) # construct the Extensions: libzmq = Extension( 'zmq.libzmq', sources = [pjoin('buildutils', 'initlibzmq.c')] + glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')), include_dirs = [ pjoin(bundledir, 'zeromq', 'include'), ], ) # register the extension: self.distribution.ext_modules.insert(0, libzmq) if sys.platform.startswith('win'): # include defines from zeromq msvc project: libzmq.define_macros.append(('FD_SETSIZE', 1024)) libzmq.define_macros.append(('DLL_EXPORT', 1)) # When compiling the C++ code inside of libzmq itself, we want to # avoid "warning C4530: C++ exception handler used, but unwind # semantics are not enabled. Specify /EHsc". if self.compiler_type == 'msvc': libzmq.extra_compile_args.append('/EHsc') elif self.compiler_type == 'mingw32': libzmq.define_macros.append(('ZMQ_HAVE_MINGW32', 1)) # And things like sockets come from libraries that must be named. libzmq.libraries.extend(['rpcrt4', 'ws2_32', 'advapi32']) else: libzmq.include_dirs.append(bundledir) # check if we need to link against Realtime Extensions library cc = new_compiler(compiler=self.compiler_type) cc.output_dir = self.build_temp if not sys.platform.startswith(('darwin', 'freebsd')): line() info("checking for timer_create") if not cc.has_function('timer_create'): info("no timer_create, linking librt") libzmq.libraries.append('rt') else: info("ok") if pypy: # seem to need explicit libstdc++ on linux + pypy # not sure why libzmq.libraries.append("stdc++") # On non-Windows, also bundle libsodium: self.bundle_libsodium_extension(libzmq) # update other extensions, with bundled settings self.config['libzmq_extension'] = True self.init_settings_from_config() self.save_config('config', self.config)
def bundle_libzmq_extension(self): bundledir = "bundled" ext_modules = self.distribution.ext_modules if ext_modules and any(m.name == "zmq.libzmq" for m in ext_modules): # I've already been run return line() info("Using bundled libzmq") # fetch sources for libzmq extension: if not os.path.exists(bundledir): os.makedirs(bundledir) fetch_libzmq(bundledir) stage_platform_hpp(pjoin(bundledir, "zeromq")) tweetnacl = pjoin(bundledir, "zeromq", "tweetnacl") tweetnacl_sources = glob(pjoin(tweetnacl, "src", "*.c")) randombytes = pjoin(tweetnacl, "contrib", "randombytes") if sys.platform.startswith("win"): tweetnacl_sources.append(pjoin(randombytes, "winrandom.c")) else: tweetnacl_sources.append(pjoin(randombytes, "devurandom.c")) # construct the Extensions: libzmq = Extension( "zmq.libzmq", sources=[pjoin("buildutils", "initlibzmq.c")] + glob(pjoin(bundledir, "zeromq", "src", "*.cpp")) + tweetnacl_sources, include_dirs=[pjoin(bundledir, "zeromq", "include"), pjoin(tweetnacl, "src"), randombytes], ) # register the extension: self.distribution.ext_modules.insert(0, libzmq) # use tweetnacl to provide CURVE support libzmq.define_macros.append(("HAVE_LIBSODIUM", 1)) libzmq.define_macros.append(("HAVE_TWEETNACL", 1)) # select polling subsystem based on platform if sys.platform == "darwin" or "bsd" in sys.platform: libzmq.define_macros.append(("ZMQ_USE_KQUEUE", 1)) elif "linux" in sys.platform: libzmq.define_macros.append(("ZMQ_USE_EPOLL", 1)) elif sys.platform.startswith("win"): libzmq.define_macros.append(("ZMQ_USE_SELECT", 1)) else: # this may not be sufficiently precise libzmq.define_macros.append(("ZMQ_USE_POLL", 1)) if sys.platform.startswith("win"): # include defines from zeromq msvc project: libzmq.define_macros.append(("FD_SETSIZE", 1024)) libzmq.define_macros.append(("DLL_EXPORT", 1)) libzmq.define_macros.append(("_CRT_SECURE_NO_WARNINGS", 1)) # When compiling the C++ code inside of libzmq itself, we want to # avoid "warning C4530: C++ exception handler used, but unwind # semantics are not enabled. Specify /EHsc". if self.compiler_type == "msvc": libzmq.extra_compile_args.append("/EHsc") elif self.compiler_type == "mingw32": libzmq.define_macros.append(("ZMQ_HAVE_MINGW32", 1)) # And things like sockets come from libraries that must be named. libzmq.libraries.extend(["rpcrt4", "ws2_32", "advapi32"]) else: libzmq.include_dirs.append(bundledir) # check if we need to link against Realtime Extensions library cc = new_compiler(compiler=self.compiler_type) cc.output_dir = self.build_temp if not sys.platform.startswith(("darwin", "freebsd")): line() info("checking for timer_create") if not cc.has_function("timer_create"): info("no timer_create, linking librt") libzmq.libraries.append("rt") else: info("ok") if pypy: # seem to need explicit libstdc++ on linux + pypy # not sure why libzmq.libraries.append("stdc++") # update other extensions, with bundled settings self.config["libzmq_extension"] = True self.init_settings_from_config() self.save_config("config", self.config)
def bundle_libsodium_extension(self, libzmq): bundledir = "bundled" ext_modules = self.distribution.ext_modules if ext_modules and any(m.name == 'zmq.libsodium' for m in ext_modules): # I've already been run return if not os.path.exists(bundledir): os.makedirs(bundledir) line() info("Using bundled libsodium") # fetch sources for libsodium fetch_libsodium(bundledir) # stage headers stage_libsodium_headers(pjoin(bundledir, 'libsodium')) # construct the Extension libsodium_src = pjoin(bundledir, 'libsodium', 'src', 'libsodium') exclude = pjoin(libsodium_src, 'crypto_stream', 'salsa20', 'amd64_xmm6') # or ref? exclude = pjoin(libsodium_src, 'crypto_scalarmult', 'curve25519', 'donna_c64') # or ref? libsodium_sources = [pjoin('buildutils', 'initlibsodium.c')] for dir,subdirs,files in os.walk(libsodium_src): if dir.startswith(exclude): continue for f in files: if f.endswith('.c'): libsodium_sources.append(pjoin(dir, f)) libsodium = Extension( 'zmq.libsodium', sources = libsodium_sources, include_dirs = [ pjoin(libsodium_src, 'include'), pjoin(libsodium_src, 'include', 'sodium'), ], ) # There are a few extra things we need to do to build libsodium on # Windows: # 1) tell libsodium to export its symbols; # 2) prevent libsodium from defining C99 `static inline` functions # which aren't parsed correctly by VS2008 nor VS2010; # 3) provide an implementation of <stdint.h> which is not provided in # VS2008's "standard" library; # 4) link against Microsoft's s crypto API. if sys.platform.startswith('win'): libsodium.define_macros.append(('SODIUM_DLL_EXPORT', 1)) libsodium.define_macros.append(('inline', '')) if sys.version_info < (3, 3): libsodium.include_dirs.append(pjoin('buildutils', 'include_win32')) libsodium.libraries.append('advapi32') # register the Extension self.distribution.ext_modules.insert(0, libsodium) if sys.byteorder == 'little': libsodium.define_macros.append(("NATIVE_LITTLE_ENDIAN", 1)) else: libsodium.define_macros.append(("NATIVE_BIG_ENDIAN", 1)) # tell libzmq about libsodium libzmq.define_macros.append(("HAVE_LIBSODIUM", 1)) libzmq.include_dirs.extend(libsodium.include_dirs)
def run(self): if CONFIG['libzmq_extension']: self.config = self.bundle_libzmq_extension() save_config('configure', self.config) line() return # When cross-compiling and zmq is given explicitly, we can't testbuild # (as we can't testrun the binary), we assume things are alright. if CONFIG['skip_check_zmq'] or CROSSCOMPILE: warn("Skipping zmq version check") return config = None zmq_prefix = CONFIG['zmq_prefix'] # There is no available default on Windows, so start with fallback unless # zmq was given explicitly, or libzmq extension was explicitly prohibited. if sys.platform.startswith("win") and \ not CONFIG['no_libzmq_extension'] and \ not zmq_prefix: config = self.fallback_on_bundled() if config is None: # first try with given config or defaults try: config = self.test_build(zmq_prefix, self.settings) except Exception: etype, evalue, tb = sys.exc_info() # print the error as distutils would if we let it raise: print ("\nerror: %s\n" % evalue) # try fallback on /usr/local on *ix if config is None and not zmq_prefix and not sys.platform.startswith('win'): print ("Failed with default libzmq, trying again with /usr/local") time.sleep(1) zmq_prefix = CONFIG['zmq_prefix'] = '/usr/local' settings = init_settings(CONFIG) try: config = self.test_build(zmq_prefix, settings) except Exception: etype, evalue, tb = sys.exc_info() # print the error as distutils would if we let it raise: print ("\nerror: %s\n" % evalue) else: # if we get here the second run succeeded, so we need to update compiler # settings for the extensions with /usr/local prefix save_config('buildconf', CONFIG) for ext in self.distribution.ext_modules: for attr,value in settings.items(): setattr(ext, attr, value) # finally, fallback on bundled if config is None and CONFIG['no_libzmq_extension']: fatal("Falling back on bundled libzmq," " but setup.cfg has explicitly prohibited building the libzmq extension." ) if config is None: config = self.fallback_on_bundled() save_config('configure', config) self.config = config line()
def bundle_libsodium_extension(self, libzmq): bundledir = "bundled" ext_modules = self.distribution.ext_modules if ext_modules and any(m.name == 'zmq.libsodium' for m in ext_modules): # I've already been run return if not os.path.exists(bundledir): os.makedirs(bundledir) line() info("Using bundled libsodium") # fetch sources for libsodium fetch_libsodium(bundledir) # stage headers stage_libsodium_headers(pjoin(bundledir, 'libsodium')) # construct the Extension libsodium_src = pjoin(bundledir, 'libsodium', 'src', 'libsodium') exclude = pjoin(libsodium_src, 'crypto_stream', 'salsa20', 'amd64_xmm6') # or ref? exclude = pjoin(libsodium_src, 'crypto_scalarmult', 'curve25519', 'donna_c64') # or ref? libsodium_sources = [pjoin('buildutils', 'initlibsodium.c')] for dir, subdirs, files in os.walk(libsodium_src): if dir.startswith(exclude): continue for f in files: if f.endswith('.c'): libsodium_sources.append(pjoin(dir, f)) libsodium = Extension( 'zmq.libsodium', sources=libsodium_sources, include_dirs=[ pjoin(libsodium_src, 'include'), pjoin(libsodium_src, 'include', 'sodium'), ], ) # There are a few extra things we need to do to build libsodium on # Windows: # 1) tell libsodium to export its symbols; # 2) prevent libsodium from defining C99 `static inline` functions # which aren't parsed correctly by VS2008 nor VS2010; # 3) provide an implementation of <stdint.h> which is not provided in # VS2008's "standard" library; # 4) link against Microsoft's s crypto API. if sys.platform.startswith('win'): libsodium.define_macros.append(('SODIUM_DLL_EXPORT', 1)) libsodium.define_macros.append(('inline', '')) if sys.version_info < (3, 3): libsodium.include_dirs.append( pjoin('buildutils', 'include_win32')) libsodium.libraries.append('advapi32') # register the Extension self.distribution.ext_modules.insert(0, libsodium) if sys.byteorder == 'little': libsodium.define_macros.append(("NATIVE_LITTLE_ENDIAN", 1)) else: libsodium.define_macros.append(("NATIVE_BIG_ENDIAN", 1)) # tell libzmq about libsodium libzmq.define_macros.append(("HAVE_LIBSODIUM", 1)) libzmq.include_dirs.extend(libsodium.include_dirs)
def bundle_libzmq_extension(self): bundledir = "bundled" ext_modules = self.distribution.ext_modules if ext_modules and any(m.name == 'zmq.libzmq' for m in ext_modules): # I've already been run return line() info("Using bundled libzmq") # fetch sources for libzmq extension: if not os.path.exists(bundledir): os.makedirs(bundledir) fetch_libzmq(bundledir) stage_platform_hpp(pjoin(bundledir, 'zeromq')) # construct the Extensions: libzmq = Extension( 'zmq.libzmq', sources=[pjoin('buildutils', 'initlibzmq.c')] + glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')), include_dirs=[ pjoin(bundledir, 'zeromq', 'include'), ], ) # register the extension: self.distribution.ext_modules.insert(0, libzmq) # select polling subsystem based on platform if sys.platform == 'darwin' or 'bsd' in sys.platform: libzmq.define_macros.append(('ZMQ_USE_KQUEUE', 1)) elif 'linux' in sys.platform: libzmq.define_macros.append(('ZMQ_USE_EPOLL', 1)) elif sys.platform.startswith('win'): libzmq.define_macros.append(('ZMQ_USE_SELECT', 1)) else: # this may not be sufficiently precise libzmq.define_macros.append(('ZMQ_USE_POLL', 1)) if sys.platform.startswith('win'): # include defines from zeromq msvc project: libzmq.define_macros.append(('FD_SETSIZE', 1024)) libzmq.define_macros.append(('DLL_EXPORT', 1)) libzmq.define_macros.append(('_CRT_SECURE_NO_WARNINGS', 1)) # When compiling the C++ code inside of libzmq itself, we want to # avoid "warning C4530: C++ exception handler used, but unwind # semantics are not enabled. Specify /EHsc". if self.compiler_type == 'msvc': libzmq.extra_compile_args.append('/EHsc') elif self.compiler_type == 'mingw32': libzmq.define_macros.append(('ZMQ_HAVE_MINGW32', 1)) # And things like sockets come from libraries that must be named. libzmq.libraries.extend(['rpcrt4', 'ws2_32', 'advapi32']) # link against libsodium in build dir: suffix = '' if sys.version_info >= (3, 5): # Python 3.5 adds EXT_SUFFIX to libs ext_suffix = distutils.sysconfig.get_config_var('EXT_SUFFIX') suffix = os.path.splitext(ext_suffix)[0] if self.debug: suffix = '_d' + suffix libzmq.libraries.append('libsodium' + suffix) libzmq.library_dirs.append(pjoin(self.build_temp, 'buildutils')) else: libzmq.include_dirs.append(bundledir) # check if we need to link against Realtime Extensions library cc = new_compiler(compiler=self.compiler_type) cc.output_dir = self.build_temp if not sys.platform.startswith(('darwin', 'freebsd')): line() info("checking for timer_create") if not cc.has_function('timer_create'): info("no timer_create, linking librt") libzmq.libraries.append('rt') else: info("ok") if pypy: # seem to need explicit libstdc++ on linux + pypy # not sure why libzmq.libraries.append("stdc++") # Also bundle libsodium, even on Windows. self.bundle_libsodium_extension(libzmq) # update other extensions, with bundled settings self.config['libzmq_extension'] = True self.init_settings_from_config() self.save_config('config', self.config)
def bundle_libzmq_extension(self): bundledir = "bundled" ext_modules = self.distribution.ext_modules if ext_modules and any(m.name == 'zmq.libzmq' for m in ext_modules): # I've already been run return line() info("Using bundled libzmq") # fetch sources for libzmq extension: if not os.path.exists(bundledir): os.makedirs(bundledir) fetch_libzmq(bundledir) stage_platform_hpp(pjoin(bundledir, 'zeromq')) sources = [pjoin('buildutils', 'initlibzmq.cpp')] sources.extend([ src for src in glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')) # exclude draft ws transport files if not os.path.basename(src).startswith(("ws_", "wss_")) ]) includes = [pjoin(bundledir, 'zeromq', 'include')] if bundled_version < (4, 2, 0): tweetnacl = pjoin(bundledir, 'zeromq', 'tweetnacl') tweetnacl_sources = glob(pjoin(tweetnacl, 'src', '*.c')) randombytes = pjoin(tweetnacl, 'contrib', 'randombytes') if sys.platform.startswith('win'): tweetnacl_sources.append(pjoin(randombytes, 'winrandom.c')) else: tweetnacl_sources.append(pjoin(randombytes, 'devurandom.c')) sources += tweetnacl_sources includes.append(pjoin(tweetnacl, 'src')) includes.append(randombytes) else: # >= 4.2 sources += glob(pjoin(bundledir, 'zeromq', 'src', 'tweetnacl.c')) # construct the Extensions: libzmq = Extension( 'zmq.libzmq', sources=sources, include_dirs=includes, ) # register the extension: # doing this here means we must be run # before finalize_options in build_ext self.distribution.ext_modules.insert(0, libzmq) # use tweetnacl to provide CURVE support libzmq.define_macros.append(('ZMQ_HAVE_CURVE', 1)) libzmq.define_macros.append(('ZMQ_USE_TWEETNACL', 1)) # select polling subsystem based on platform if sys.platform == "darwin" or "bsd" in sys.platform: libzmq.define_macros.append(('ZMQ_USE_KQUEUE', 1)) libzmq.define_macros.append(('ZMQ_IOTHREADS_USE_KQUEUE', 1)) libzmq.define_macros.append(('ZMQ_POLL_BASED_ON_POLL', 1)) elif 'linux' in sys.platform: libzmq.define_macros.append(('ZMQ_USE_EPOLL', 1)) libzmq.define_macros.append(('ZMQ_IOTHREADS_USE_EPOLL', 1)) libzmq.define_macros.append(('ZMQ_POLL_BASED_ON_POLL', 1)) elif sys.platform.startswith('win'): libzmq.define_macros.append(('ZMQ_USE_SELECT', 1)) libzmq.define_macros.append(('ZMQ_IOTHREADS_USE_SELECT', 1)) libzmq.define_macros.append(('ZMQ_POLL_BASED_ON_SELECT', 1)) else: # this may not be sufficiently precise libzmq.define_macros.append(('ZMQ_USE_POLL', 1)) libzmq.define_macros.append(('ZMQ_IOTHREADS_USE_POLL', 1)) libzmq.define_macros.append(('ZMQ_POLL_BASED_ON_POLL', 1)) if sys.platform.startswith('win'): # include defines from zeromq msvc project: libzmq.define_macros.append(('FD_SETSIZE', 16384)) libzmq.define_macros.append(('DLL_EXPORT', 1)) libzmq.define_macros.append(('_CRT_SECURE_NO_WARNINGS', 1)) # When compiling the C++ code inside of libzmq itself, we want to # avoid "warning C4530: C++ exception handler used, but unwind # semantics are not enabled. Specify /EHsc". if self.compiler_type == 'msvc': libzmq.extra_compile_args.append('/EHsc') elif self.compiler_type == 'mingw32': libzmq.define_macros.append(('ZMQ_HAVE_MINGW32', 1)) # And things like sockets come from libraries that must be named. libzmq.libraries.extend( ['rpcrt4', 'ws2_32', 'advapi32', 'iphlpapi']) # bundle MSCVP redist if self.config['bundle_msvcp']: from setuptools import msvc from setuptools._distutils.util import get_platform vcvars = msvc.msvc14_get_vc_env(get_platform()) try: vcruntime = vcvars["py_vcruntime_redist"] except KeyError: warn(f"platform={get_platform()}, vcvars=") pprint(vcvars, stream=sys.stderr) # fatal error if env set, warn otherwise msg = fatal if os.environ.get("PYZMQ_BUNDLE_CRT") else warn msg("Failed to get py_vcruntime_redist via vcvars, not bundling MSVCP" ) redist_dir, dll = os.path.split(vcruntime) to_bundle = [ pjoin(redist_dir, dll.replace('vcruntime', name)) for name in ('msvcp', 'concrt') ] for src in to_bundle: dest = localpath('zmq', basename(src)) info("Copying %s -> %s" % (src, dest)) # copyfile to avoid permission issues shutil.copyfile(src, dest) else: libzmq.include_dirs.append(bundledir) # check if we need to link against Realtime Extensions library cc = new_compiler(compiler=self.compiler_type) customize_compiler(cc) cc.output_dir = self.build_temp if not sys.platform.startswith(('darwin', 'freebsd')): line() info("checking for timer_create") if not cc.has_function('timer_create'): info("no timer_create, linking librt") libzmq.libraries.append('rt') else: info("ok") # copy the header files to the source tree. bundledincludedir = pjoin('zmq', 'include') if not os.path.exists(bundledincludedir): os.makedirs(bundledincludedir) if not os.path.exists(pjoin(self.build_lib, bundledincludedir)): os.makedirs(pjoin(self.build_lib, bundledincludedir)) for header in glob(pjoin(bundledir, 'zeromq', 'include', '*.h')): shutil.copyfile(header, pjoin(bundledincludedir, basename(header))) shutil.copyfile( header, pjoin(self.build_lib, bundledincludedir, basename(header))) # update other extensions, with bundled settings self.config['libzmq_extension'] = True self.init_settings_from_config() self.save_config('config', self.config)
def finish_run(self): self.save_config("config", self.config) line()
def finish_run(self): self.save_config('config', self.config) line()
def bundle_libzmq_extension(self): bundledir = "bundled" if "PyPy" in sys.version: fatal("Can't bundle libzmq as an Extension in PyPy (yet!)") ext_modules = self.distribution.ext_modules if ext_modules and ext_modules[0].name == 'zmq.libzmq': # I've already been run return line() info("Using bundled libzmq") # fetch sources for libzmq extension: if not os.path.exists(bundledir): os.makedirs(bundledir) fetch_libzmq(bundledir) stage_platform_hpp(pjoin(bundledir, 'zeromq')) # construct the Extension: ext = Extension( 'zmq.libzmq', sources = [pjoin('buildutils', 'initlibzmq.c')] + glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')), include_dirs = [ pjoin(bundledir, 'zeromq', 'include'), ], ) if sys.platform.startswith('win'): # include defines from zeromq msvc project: ext.define_macros.append(('FD_SETSIZE', 1024)) ext.define_macros.append(('DLL_EXPORT', 1)) # When compiling the C++ code inside of libzmq itself, we want to # avoid "warning C4530: C++ exception handler used, but unwind # semantics are not enabled. Specify /EHsc". if self.compiler_type == 'msvc': ext.extra_compile_args.append('/EHsc') elif self.compiler_type == 'mingw32': ext.define_macros.append(('ZMQ_HAVE_MINGW32', 1)) # And things like sockets come from libraries that must be named. ext.libraries.extend(['rpcrt4', 'ws2_32', 'advapi32']) else: ext.include_dirs.append(bundledir) # check if we need to link against Realtime Extensions library cc = new_compiler(compiler=self.compiler_type) cc.output_dir = self.build_temp if not sys.platform.startswith(('darwin', 'freebsd')) \ and not cc.has_function('timer_create'): ext.libraries.append('rt') # check if we *can* link libsodium if cc.has_function('crypto_box_keypair', libraries=ext.libraries + ['sodium']): ext.libraries.append('sodium') ext.define_macros.append(("HAVE_LIBSODIUM", 1)) else: warn("libsodium not found, zmq.CURVE security will be unavailable") # insert the extension: self.distribution.ext_modules.insert(0, ext) # update other extensions, with bundled settings self.config['libzmq_extension'] = True self.init_settings_from_config() self.save_config('config', self.config)
def bundle_libzmq_extension(self): bundledir = "bundled" ext_modules = self.distribution.ext_modules if ext_modules and any(m.name == 'zmq.libzmq' for m in ext_modules): # I've already been run return line() info("Using bundled libzmq") # fetch sources for libzmq extension: if not os.path.exists(bundledir): os.makedirs(bundledir) fetch_libzmq(bundledir) stage_platform_hpp(pjoin(bundledir, 'zeromq')) # construct the Extensions: libzmq = Extension( 'zmq.libzmq', sources = [pjoin('buildutils', 'initlibzmq.c')] + glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')), include_dirs = [ pjoin(bundledir, 'zeromq', 'include'), ], ) # register the extension: self.distribution.ext_modules.insert(0, libzmq) # select polling subsystem based on platform if sys.platform == 'darwin' or 'bsd' in sys.platform: libzmq.define_macros.append(('ZMQ_USE_KQUEUE', 1)) elif 'linux' in sys.platform: libzmq.define_macros.append(('ZMQ_USE_EPOLL', 1)) elif sys.platform.startswith('win'): libzmq.define_macros.append(('ZMQ_USE_SELECT', 1)) else: # this may not be sufficiently precise libzmq.define_macros.append(('ZMQ_USE_POLL', 1)) if sys.platform.startswith('win'): # include defines from zeromq msvc project: libzmq.define_macros.append(('FD_SETSIZE', 1024)) libzmq.define_macros.append(('DLL_EXPORT', 1)) libzmq.define_macros.append(('_CRT_SECURE_NO_WARNINGS', 1)) # When compiling the C++ code inside of libzmq itself, we want to # avoid "warning C4530: C++ exception handler used, but unwind # semantics are not enabled. Specify /EHsc". if self.compiler_type == 'msvc': libzmq.extra_compile_args.append('/EHsc') elif self.compiler_type == 'mingw32': libzmq.define_macros.append(('ZMQ_HAVE_MINGW32', 1)) # And things like sockets come from libraries that must be named. libzmq.libraries.extend(['rpcrt4', 'ws2_32', 'advapi32']) # link against libsodium in build dir: suffix = '' if sys.version_info >= (3,5): # Python 3.5 adds EXT_SUFFIX to libs ext_suffix = distutils.sysconfig.get_config_var('EXT_SUFFIX') suffix = os.path.splitext(ext_suffix)[0] if self.debug: suffix = '_d' + suffix libzmq.libraries.append('libsodium' + suffix) libzmq.library_dirs.append(pjoin(self.build_temp, 'buildutils')) else: libzmq.include_dirs.append(bundledir) # check if we need to link against Realtime Extensions library cc = new_compiler(compiler=self.compiler_type) cc.output_dir = self.build_temp if not sys.platform.startswith(('darwin', 'freebsd')): line() info("checking for timer_create") if not cc.has_function('timer_create'): info("no timer_create, linking librt") libzmq.libraries.append('rt') else: info("ok") if pypy: # seem to need explicit libstdc++ on linux + pypy # not sure why libzmq.libraries.append("stdc++") # Also bundle libsodium, even on Windows. self.bundle_libsodium_extension(libzmq) # update other extensions, with bundled settings self.config['libzmq_extension'] = True self.init_settings_from_config() self.save_config('config', self.config)
def bundle_libzmq_extension(self): bundledir = "bundled" if "PyPy" in sys.version: fatal("Can't bundle libzmq as an Extension in PyPy (yet!)") ext_modules = self.distribution.ext_modules if ext_modules and ext_modules[0].name == 'zmq.libzmq': # I've already been run return line() info("Using bundled libzmq") # fetch sources for libzmq extension: if not os.path.exists(bundledir): os.makedirs(bundledir) fetch_libzmq(bundledir) stage_platform_hpp(pjoin(bundledir, 'zeromq')) # construct the Extension: ext = Extension( 'zmq.libzmq', sources=[pjoin('buildutils', 'initlibzmq.c')] + glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')), include_dirs=[ pjoin(bundledir, 'zeromq', 'include'), ], ) if sys.platform.startswith('win'): # include defines from zeromq msvc project: ext.define_macros.append(('FD_SETSIZE', 1024)) ext.define_macros.append(('DLL_EXPORT', 1)) # When compiling the C++ code inside of libzmq itself, we want to # avoid "warning C4530: C++ exception handler used, but unwind # semantics are not enabled. Specify /EHsc". if self.compiler_type == 'msvc': ext.extra_compile_args.append('/EHsc') elif self.compiler_type == 'mingw32': ext.define_macros.append(('ZMQ_HAVE_MINGW32', 1)) # And things like sockets come from libraries that must be named. ext.libraries.extend(['rpcrt4', 'ws2_32', 'advapi32']) else: ext.include_dirs.append(bundledir) # check if we need to link against Realtime Extensions library cc = new_compiler(compiler=self.compiler_type) cc.output_dir = self.build_temp if not sys.platform.startswith(('darwin', 'freebsd')) \ and not cc.has_function('timer_create'): ext.libraries.append('rt') # check if we *can* link libsodium if cc.has_function('crypto_box_keypair', libraries=ext.libraries + ['sodium']): ext.libraries.append('sodium') ext.define_macros.append(("HAVE_LIBSODIUM", 1)) else: warn( "libsodium not found, zmq.CURVE security will be unavailable" ) # insert the extension: self.distribution.ext_modules.insert(0, ext) # update other extensions, with bundled settings self.config['libzmq_extension'] = True self.init_settings_from_config() self.save_config('config', self.config)
def bundle_libzmq_extension(self): bundledir = "bundled" ext_modules = self.distribution.ext_modules if ext_modules and any(m.name == 'zmq.libzmq' for m in ext_modules): # I've already been run return line() info("Using bundled libzmq") # fetch sources for libzmq extension: if not os.path.exists(bundledir): os.makedirs(bundledir) fetch_libzmq(bundledir) stage_platform_hpp(pjoin(bundledir, 'zeromq')) tweetnacl = pjoin(bundledir, 'zeromq', 'tweetnacl') tweetnacl_sources = glob(pjoin(tweetnacl, 'src', '*.c')) randombytes = pjoin(tweetnacl, 'contrib', 'randombytes') if sys.platform.startswith('win'): tweetnacl_sources.append(pjoin(randombytes, 'winrandom.c')) else: tweetnacl_sources.append(pjoin(randombytes, 'devurandom.c')) # construct the Extensions: libzmq = Extension( 'zmq.libzmq', sources = [pjoin('buildutils', 'initlibzmq.c')] + \ glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')) + \ tweetnacl_sources, include_dirs = [ pjoin(bundledir, 'zeromq', 'include'), pjoin(tweetnacl, 'src'), randombytes, ], ) # register the extension: self.distribution.ext_modules.insert(0, libzmq) # use tweetnacl to provide CURVE support libzmq.define_macros.append(('ZMQ_HAVE_CURVE', 1)) libzmq.define_macros.append(('ZMQ_USE_TWEETNACL', 1)) # select polling subsystem based on platform if sys.platform == 'darwin' or 'bsd' in sys.platform: libzmq.define_macros.append(('ZMQ_USE_KQUEUE', 1)) elif 'linux' in sys.platform: libzmq.define_macros.append(('ZMQ_USE_EPOLL', 1)) elif sys.platform.startswith('win'): libzmq.define_macros.append(('ZMQ_USE_SELECT', 1)) else: # this may not be sufficiently precise libzmq.define_macros.append(('ZMQ_USE_POLL', 1)) if sys.platform.startswith('win'): # include defines from zeromq msvc project: libzmq.define_macros.append(('FD_SETSIZE', 16384)) libzmq.define_macros.append(('DLL_EXPORT', 1)) libzmq.define_macros.append(('_CRT_SECURE_NO_WARNINGS', 1)) # When compiling the C++ code inside of libzmq itself, we want to # avoid "warning C4530: C++ exception handler used, but unwind # semantics are not enabled. Specify /EHsc". if self.compiler_type == 'msvc': libzmq.extra_compile_args.append('/EHsc') elif self.compiler_type == 'mingw32': libzmq.define_macros.append(('ZMQ_HAVE_MINGW32', 1)) # And things like sockets come from libraries that must be named. libzmq.libraries.extend(['rpcrt4', 'ws2_32', 'advapi32']) # bundle MSCVP redist if self.config['bundle_msvcp']: cc = new_compiler(compiler=self.compiler_type) cc.initialize() # get vc_redist location via private API try: cc._vcruntime_redist except AttributeError: # fatal error if env set, warn otherwise msg = fatal if os.environ.get("PYZMQ_BUNDLE_CRT") else warn msg("Failed to get cc._vcruntime via private API, not bundling CRT" ) if cc._vcruntime_redist: redist_dir, dll = os.path.split(cc._vcruntime_redist) to_bundle = [ pjoin(redist_dir, dll.replace('vcruntime', name)) for name in ('msvcp', 'concrt') ] for src in to_bundle: dest = localpath('zmq', basename(src)) info("Copying %s -> %s" % (src, dest)) # copyfile to avoid permission issues shutil.copyfile(src, dest) else: libzmq.include_dirs.append(bundledir) # check if we need to link against Realtime Extensions library cc = new_compiler(compiler=self.compiler_type) cc.output_dir = self.build_temp if not sys.platform.startswith(('darwin', 'freebsd')): line() info("checking for timer_create") if not cc.has_function('timer_create'): info("no timer_create, linking librt") libzmq.libraries.append('rt') else: info("ok") if pypy: # seem to need explicit libstdc++ on linux + pypy # not sure why libzmq.libraries.append("stdc++") # copy the header files to the source tree. bundledincludedir = pjoin('zmq', 'include') if not os.path.exists(bundledincludedir): os.makedirs(bundledincludedir) if not os.path.exists(pjoin(self.build_lib, bundledincludedir)): os.makedirs(pjoin(self.build_lib, bundledincludedir)) for header in glob(pjoin(bundledir, 'zeromq', 'include', '*.h')): shutil.copyfile(header, pjoin(bundledincludedir, basename(header))) shutil.copyfile( header, pjoin(self.build_lib, bundledincludedir, basename(header))) # update other extensions, with bundled settings self.config['libzmq_extension'] = True self.init_settings_from_config() self.save_config('config', self.config)