Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 def run(self):
     # fetch sources for libzmq extension:
     bundledir = "bundled"
     if not os.path.exists(bundledir):
         os.makedirs(bundledir)
     fetch_libzmq(bundledir)
     for tarball in glob(pjoin(bundledir, '*.tar.gz')):
         os.remove(tarball)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
 def run(self):
     # fetch sources for libzmq extension:
     bundledir = "bundled"
     if not os.path.exists(bundledir):
         os.makedirs(bundledir)
     fetch_uuid(bundledir)
     fetch_libzmq(bundledir)
     for tarball in glob(pjoin(bundledir, '*.tar.gz')):
         os.remove(tarball)
Exemplo n.º 5
0
 def fetch_libzmq_src(self):
     bundledir = "bundled"
     if os.path.exists(bundledir):
         info("Scrubbing directory: %s" % bundledir)
         shutil.rmtree(bundledir)
     if not os.path.exists(bundledir):
         os.makedirs(bundledir)
     fetch_libzmq(bundledir)
     for tarball in glob(pjoin(bundledir, '*.tar.gz')):
         os.remove(tarball)
 def run(self):
     # fetch sources for libzmq extension:
     bundledir = "bundled"
     if os.path.exists(bundledir):
         info("Scrubbing directory: %s" % bundledir)
         shutil.rmtree(bundledir)
     if not os.path.exists(bundledir):
         os.makedirs(bundledir)
     fetch_libzmq(bundledir)
     for tarball in glob(pjoin(bundledir, '*.tar.gz')):
         os.remove(tarball)
Exemplo n.º 7
0
 def run(self):
     # fetch sources for libzmq extension:
     bundledir = "bundled"
     if os.path.exists(bundledir):
         info("Scrubbing directory: %s" % bundledir)
         shutil.rmtree(bundledir)
     if not os.path.exists(bundledir):
         os.makedirs(bundledir)
     fetch_libsodium(bundledir)
     fetch_libzmq(bundledir)
     for tarball in glob(pjoin(bundledir, '*.tar.gz')):
         os.remove(tarball)
Exemplo n.º 8
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'))

        # 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)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
Arquivo: setup.py Projeto: fwph/pyzmq
    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)
Exemplo n.º 12
0
Arquivo: setup.py Projeto: chizu/pyzmq
    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)
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
    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)
Exemplo n.º 15
0
Arquivo: setup.py Projeto: dln/pyzmq
    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)
Exemplo n.º 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"))

        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)
Exemplo n.º 17
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)
Exemplo n.º 18
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(('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)
Exemplo n.º 19
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(('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)
Exemplo n.º 20
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', 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)