Exemple #1
0
 def run(self):
     libzmq = 'libzmq'+lib_ext
     # copy libzmq into zmq for bdist
     try:
         shutil.copy(pjoin(ZMQ, 'lib', libzmq), localpath('zmq',libzmq))
     except Exception:
         if not os.path.exists(localpath('zmq',libzmq)):
             raise IOError("Could not copy libzmq into zmq/, which is necessary for bdist."
             "Please specify zmq prefix via configure --zmq=/path/to/zmq or copy "
             "libzmq into zmq/ manually.")
     
     bdist.run(self)
Exemple #2
0
    def run(self):
        libzmq = 'libzmq' + lib_ext
        # copy libzmq into zmq for bdist
        try:
            shutil.copy(pjoin(ZMQ, 'lib', libzmq), localpath('zmq', libzmq))
        except Exception:
            if not os.path.exists(localpath('zmq', libzmq)):
                raise IOError(
                    "Could not copy libzmq into zmq/, which is necessary for bdist."
                    "Please specify zmq prefix via configure --zmq=/path/to/zmq or copy "
                    "libzmq into zmq/ manually.")

        bdist.run(self)
Exemple #3
0
    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/libzmq'"
                )
Exemple #4
0
    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."
                    )
Exemple #5
0
    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.")
Exemple #6
0
    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.")
Exemple #7
0
    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.")
Exemple #8
0
    def check_zmq_version(self):
        zmq = ZMQ
        if zmq is not None and not os.path.isdir(zmq):
            fatal('Custom zmq directory "%s" does not exist' % zmq)

        config = self.getcached()
        if config is None or config["options"] != COMPILER_SETTINGS:
            self.run()
            config = self.config
        else:
            self.config = config

        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)
            print("*" * 42)
        elif vs > "3.0":
            warn("Detected ZMQ version: %s. pyzmq's 3.0 support is experimental." % vs)
            print("*" * 42)

        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."
                    )
Exemple #9
0
    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.")
Exemple #10
0
    def check_zmq_version(self):
        zmq = self.zmq
        if zmq is not None and not os.path.isdir(zmq):
            fatal("Custom zmq directory \"%s\" does not exist" % zmq)

        config = self.getcached()
        if config is None or config['options'] != self.settings:
            self.run()
            config = self.config
        else:
            self.config = config

        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)
            print('*'*42)
        elif vs >= '3.0':
            warn("Detected ZMQ version: %s. pyzmq's support for libzmq-dev is experimental."%vs)
            print('*'*42)

        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.")
Exemple #11
0
    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."
                    )
Exemple #12
0
    def check_zmq_version(self):
        zmq = ZMQ
        if zmq is not None and not os.path.isdir(zmq):
            fatal("Custom zmq directory \"%s\" does not exist" % zmq)

        config = self.getcached()
        if config is None or config['options'] != COMPILER_SETTINGS:
            self.run()
            config = self.config

        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 is based on zmq %s." %
                 (vs, pyzmq_version))
            warn("Some features may be missing or broken.")
            print('*' * 42)

        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.")
Exemple #13
0
    def check_zmq_version(self):
        zmq = ZMQ
        if zmq is not None and not os.path.isdir(zmq):
            fatal("Custom zmq directory \"%s\" does not exist" % zmq)

        config = self.getcached()
        if config is None or config['options'] != COMPILER_SETTINGS:
            self.run()
            config = self.config

        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 is based on zmq %s."%(
                    vs, pyzmq_version))
            warn("Some features may be missing or broken.")
            print('*'*42)

        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.")
Exemple #14
0
    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)
Exemple #15
0
    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', 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'])

            # 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++")

        # update other extensions, with bundled settings
        self.config['libzmq_extension'] = True
        self.init_settings_from_config()
        self.save_config('config', self.config)
Exemple #16
0
    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)