Ejemplo n.º 1
0
    def run(self):
        """Run the test suite, with nose, or unittest if nose is unavailable"""
        # crude check for inplace build:
        try:
            import zmq
        except ImportError:
            print_exc()
            fatal(
                "\n       ".join(
                    [
                        "Could not import zmq!",
                        "You must build pyzmq with 'python setup.py build_ext --inplace' for 'python setup.py test' to work.",
                        "If you did build pyzmq in-place, then this is a real error.",
                    ]
                )
            )
            sys.exit(1)

        info("Testing pyzmq-%s with libzmq-%s" % (zmq.pyzmq_version(), zmq.zmq_version()))

        if nose is None:
            warn("nose unavailable, falling back on unittest. Skipped tests will appear as ERRORs.")
            return self.run_unittest()
        else:
            return self.run_nose()
 def run(self):
     try:
         p = Popen('git log -1'.split(), stdin=PIPE, stdout=PIPE, stderr=PIPE)
     except IOError:
         warn("No git found, skipping git revision")
         return
     
     if p.wait():
         warn("checking git branch failed")
         info(p.stderr.read())
         return
     
     line = p.stdout.readline().decode().strip()
     if not line.startswith('commit'):
         warn("bad commit line: %r" % line)
         return
     
     rev = line.split()[-1]
     
     # now that we have the git revision, we can apply it to version.py
     with open(self.version_py) as f:
         lines = f.readlines()
     
     for i,line in enumerate(lines):
         if line.startswith('__revision__'):
             lines[i] = "__revision__ = '%s'\n"%rev
             break
     with open(self.version_py, 'w') as f:
         f.writelines(lines)
Ejemplo n.º 3
0
    def run(self):
        build_failed = False
        try:
            test_build()
        except CompileError:
            build_failed = True

        if build_failed and force_system_libcapnp:
            raise RuntimeError("libcapnp C++ library not detected and --force-system-libcapnp was used")
        if build_failed or force_bundled_libcapnp:
            if build_failed:
                info("*WARNING* no libcapnp detected. Will download and build it from source now. If you have C++ Cap'n Proto installed, it may be out of date or is not being detected. Downloading and building libcapnp may take a while.")
            bundle_dir = os.path.join(_this_dir, "bundled")
            if not os.path.exists(bundle_dir):
                os.mkdir(bundle_dir)
            build_dir = os.path.join(_this_dir, "build")
            if not os.path.exists(build_dir):
                os.mkdir(build_dir)
            fetch_libcapnp(bundle_dir)

            build_libcapnp(bundle_dir, build_dir)

            self.include_dirs += [os.path.join(build_dir, 'include')]
            self.library_dirs += [os.path.join(build_dir, 'lib')]

        return build_ext_c.run(self)
Ejemplo n.º 4
0
 def bundle_libsodium_extension(self, libzmq):
     bundledir = "bundled"
     if "PyPy" in sys.version:
         fatal("Can't bundle libsodium as an Extension in PyPy (yet!)")
     ext_modules = self.distribution.ext_modules
     if ext_modules and any(m.name == 'zmq.libsodium' for m in ext_modules):
         # I've already been run
         return
     
     if not os.path.exists(bundledir):
         os.makedirs(bundledir)
     
     line()
     info("Using bundled libsodium")
     
     # fetch sources for libsodium
     fetch_libsodium(bundledir)
     
     # stage headers
     stage_libsodium_headers(pjoin(bundledir, 'libsodium'))
     
     # construct the Extension
     libsodium_src = pjoin(bundledir, 'libsodium', 'src', 'libsodium')
     exclude = pjoin(libsodium_src, 'crypto_stream', 'salsa20', 'amd64_xmm6') # or ref?
     exclude = pjoin(libsodium_src, 'crypto_scalarmult', 'curve25519', 'donna_c64') # or ref?
     
     libsodium_sources = [pjoin('buildutils', 'initlibsodium.c')]
     
     for dir,subdirs,files in os.walk(libsodium_src):
         if dir.startswith(exclude):
             continue
         for f in files:
             if f.endswith('.c'):
                 libsodium_sources.append(pjoin(dir, f))
     
     libsodium = Extension(
         'zmq.libsodium',
         sources = libsodium_sources,
         include_dirs = [
             pjoin(libsodium_src, 'include'),
             pjoin(libsodium_src, 'include', 'sodium'),
         ],
     )
     # register the Extension
     self.distribution.ext_modules.insert(0, libsodium)
     
     if sys.byteorder == 'little':
         libsodium.define_macros.append(("NATIVE_LITTLE_ENDIAN", 1))
     else:
         libsodium.define_macros.append(("NATIVE_BIG_ENDIAN", 1))
     
     # tell libzmq about libsodium
     libzmq.define_macros.append(("HAVE_LIBSODIUM", 1))
     libzmq.include_dirs.extend(libsodium.include_dirs)
 def 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)
Ejemplo n.º 6
0
 def run(self):
     """Run the test suite with py.test"""
     # crude check for inplace build:
     try:
         import zmq
     except ImportError:
         print_exc()
         fatal('\n       '.join(["Could not import zmq!",
         "You must build pyzmq with 'python setup.py build_ext --inplace' for 'python setup.py test' to work.",
         "If you did build pyzmq in-place, then this is a real error."]))
         sys.exit(1)
     
     info("Testing pyzmq-%s with libzmq-%s" % (zmq.pyzmq_version(), zmq.zmq_version()))
     p = Popen([sys.executable, '-m', 'pytest', '-v', os.path.join('zmq', 'tests')])
     p.wait()
     sys.exit(p.returncode)
Ejemplo n.º 7
0
    def fallback_on_bundled(self):
        """Couldn't build, fallback after waiting a while"""

        line()

        warn(
            "\n".join(
                [
                    "Couldn't find an acceptable libzmq on the system.",
                    "",
                    "If you expected pyzmq to link against an installed libzmq, please check to make sure:",
                    "",
                    "    * You have a C compiler installed",
                    "    * A development version of Python is installed (including headers)",
                    "    * A development version of ZMQ >= %s is installed (including headers)" % v_str(min_good_zmq),
                    "    * If ZMQ is not in a default location, supply the argument --zmq=<path>",
                    "    * If you did recently install ZMQ to a default location,",
                    "      try rebuilding the ld cache with `sudo ldconfig`",
                    "      or specify zmq's location with `--zmq=/usr/local`",
                    "",
                ]
            )
        )

        info(
            "\n".join(
                [
                    "You can skip all this detection/waiting nonsense if you know",
                    "you want pyzmq to bundle libzmq as an extension by passing:",
                    "",
                    "    `--zmq=bundled`",
                    "",
                    "I will now try to build libzmq as a Python extension",
                    "unless you interrupt me (^C) in the next 10 seconds...",
                    "",
                ]
            )
        )

        for i in range(10, 0, -1):
            sys.stdout.write("\r%2i..." % i)
            sys.stdout.flush()
            time.sleep(1)

        info("")

        return self.bundle_libzmq_extension()
Ejemplo n.º 8
0
def check_pkgconfig():
    """ pull compile / link flags from pkg-config if present. """
    pcfg = None
    zmq_config = None
    try:
        check_call(['pkg-config', '--exists', 'libzmq'])
        # this would arguably be better with --variable=libdir /
        # --variable=includedir, but would require multiple calls
        pcfg = Popen(['pkg-config', '--libs', '--cflags', 'libzmq'],
                     stdout=subprocess.PIPE)
    except OSError as osexception:
        if osexception.errno == errno.ENOENT:
            info('pkg-config not found')
        else:
            warn("Running pkg-config failed - %s." % osexception)
    except CalledProcessError:
        info("Did not find libzmq via pkg-config.")

    if pcfg is not None:
        output, _ = pcfg.communicate()
        output = output.decode('utf8', 'replace')
        bits = output.strip().split()
        zmq_config = {'library_dirs':[], 'include_dirs':[], 'libraries':[]}
        for tok in bits:
            if tok.startswith("-L"):
                zmq_config['library_dirs'].append(tok[2:])
            if tok.startswith("-I"):
                zmq_config['include_dirs'].append(tok[2:])
            if tok.startswith("-l"):
                zmq_config['libraries'].append(tok[2:])
        info("Settings obtained from pkg-config: %r" % zmq_config)

    return zmq_config
 def test_build(self, prefix, settings):
     """do a test build ob libzmq"""
     self.create_tempdir()
     settings = settings.copy()
     if self.bundle_libzmq_dylib and not sys.platform.startswith('win'):
         # rpath slightly differently here, because libzmq not in .. but ../zmq:
         settings['library_dirs'] = ['zmq']
         if sys.platform == 'darwin':
             pass
             # unused rpath args for OS X:
             # settings['extra_link_args'] = ['-Wl,-rpath','-Wl,$ORIGIN/../zmq']
         else:
             settings['runtime_library_dirs'] = [ os.path.abspath(pjoin('.', 'zmq')) ]
     
     line()
     info("Configure: Autodetecting ZMQ settings...")
     info("    Custom ZMQ dir:       %s" % prefix)
     try:
         detected = detect_zmq(self.tempdir, compiler=self.compiler_type, **settings)
     finally:
         self.erase_tempdir()
     
     info("    ZMQ version detected: %s" % v_str(detected['vers']))
     
     return detected
Ejemplo n.º 10
0
    def fallback_on_bundled(self):
        """Couldn't build, fallback after waiting a while"""

        line()

        warn(
            "\n".join(
                [
                    "Failed to build or run libzmq detection test.",
                    "",
                    "If you expected pyzmq to link against an installed libzmq, please check to make sure:",
                    "",
                    "    * You have a C compiler installed",
                    "    * A development version of Python is installed (including headers)",
                    "    * A development version of ZMQ >= %s is installed (including headers)" % v_str(min_zmq),
                    "    * If ZMQ is not in a default location, supply the argument --zmq=<path>",
                    "    * If you did recently install ZMQ to a default location,",
                    "      try rebuilding the ld cache with `sudo ldconfig`",
                    "      or specify zmq's location with `--zmq=/usr/local`",
                    "",
                ]
            )
        )

        # ultra-lazy pip detection:
        if "pip" in " ".join(sys.argv):
            info(
                "\n".join(
                    [
                        "If you expected to get a binary install (egg), we have those for",
                        "current Pythons on OS X and Windows. These can be installed with",
                        "easy_install, but PIP DOES NOT SUPPORT EGGS.",
                        "",
                    ]
                )
            )

        info(
            "\n".join(
                [
                    "You can skip all this detection/waiting nonsense if you know",
                    "you want pyzmq to bundle libzmq as an extension by passing:",
                    "",
                    "    `--zmq=bundled`",
                    "",
                    "I will now try to build libzmq as a Python extension",
                    "unless you interrupt me (^C) in the next 10 seconds...",
                    "",
                ]
            )
        )

        for i in range(10, 0, -1):
            sys.stdout.write("\r%2i..." % i)
            sys.stdout.flush()
            time.sleep(1)

        info("")

        return self.bundle_libzmq_extension()
Ejemplo n.º 11
0
Archivo: setup.py Proyecto: dln/pyzmq
 def test_build(self, prefix, settings):
     """do a test build ob libzmq"""
     self.create_tempdir()
     settings = settings.copy()
     if self.bundle_libzmq_dylib and not sys.platform.startswith('win'):
         # rpath slightly differently here, because libzmq not in .. but ../zmq:
         settings['library_dirs'] = ['zmq']
         _add_rpath(settings, os.path.abspath(pjoin('.', 'zmq')))
     line()
     info("Configure: Autodetecting ZMQ settings...")
     info("    Custom ZMQ dir:       %s" % prefix)
     try:
         detected = detect_zmq(self.tempdir, compiler=self.compiler_type, **settings)
     finally:
         self.erase_tempdir()
     
     info("    ZMQ version detected: %s" % v_str(detected['vers']))
     
     return detected
    def 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'])
        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)
            cc.output_dir = self.build_temp
            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)
Ejemplo n.º 13
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 += 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))
            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']:
                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)
            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)
Ejemplo n.º 14
0
Archivo: setup.py Proyecto: fwph/pyzmq
 def bundle_libsodium_extension(self, libzmq):
     bundledir = "bundled"
     ext_modules = self.distribution.ext_modules
     if ext_modules and any(m.name == 'zmq.libsodium' for m in ext_modules):
         # I've already been run
         return
     
     if not os.path.exists(bundledir):
         os.makedirs(bundledir)
     
     line()
     info("Using bundled libsodium")
     
     # fetch sources for libsodium
     fetch_libsodium(bundledir)
     
     # stage headers
     stage_libsodium_headers(pjoin(bundledir, 'libsodium'))
     
     # construct the Extension
     libsodium_src = pjoin(bundledir, 'libsodium', 'src', 'libsodium')
     exclude = pjoin(libsodium_src, 'crypto_stream', 'salsa20', 'amd64_xmm6') # or ref?
     exclude = pjoin(libsodium_src, 'crypto_scalarmult', 'curve25519', 'donna_c64') # or ref?
     
     libsodium_sources = [pjoin('buildutils', 'initlibsodium.c')]
     
     for dir,subdirs,files in os.walk(libsodium_src):
         if dir.startswith(exclude):
             continue
         for f in files:
             if f.endswith('.c'):
                 libsodium_sources.append(pjoin(dir, f))
     
     libsodium = Extension(
         'zmq.libsodium',
         sources = libsodium_sources,
         include_dirs = [
             pjoin(libsodium_src, 'include'),
             pjoin(libsodium_src, 'include', 'sodium'),
         ],
     )
     # There are a few extra things we need to do to build libsodium on
     # Windows:
     # 1) tell libsodium to export its symbols;
     # 2) prevent libsodium from defining C99 `static inline` functions
     #    which aren't parsed correctly by VS2008 nor VS2010;
     # 3) provide an implementation of <stdint.h> which is not provided in
     #    VS2008's "standard" library;
     # 4) link against Microsoft's s crypto API.
     if sys.platform.startswith('win'):
         libsodium.define_macros.append(('SODIUM_DLL_EXPORT', 1))
         libsodium.define_macros.append(('inline', ''))
         if sys.version_info < (3, 3):
             libsodium.include_dirs.append(pjoin('buildutils', 'include_win32'))
         libsodium.libraries.append('advapi32')
     # register the Extension
     self.distribution.ext_modules.insert(0, libsodium)
     
     if sys.byteorder == 'little':
         libsodium.define_macros.append(("NATIVE_LITTLE_ENDIAN", 1))
     else:
         libsodium.define_macros.append(("NATIVE_BIG_ENDIAN", 1))
     
     # tell libzmq about libsodium
     libzmq.define_macros.append(("HAVE_LIBSODIUM", 1))
     libzmq.include_dirs.extend(libsodium.include_dirs)
Ejemplo n.º 15
0
Archivo: setup.py Proyecto: 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)
Ejemplo n.º 16
0
def settings_from_prefix(prefix=None, bundle_libzmq_dylib=False):
    """load appropriate library/include settings from ZMQ prefix"""
    settings = {}
    settings["libraries"] = []
    settings["include_dirs"] = []
    settings["library_dirs"] = []
    settings["runtime_library_dirs"] = []
    settings["extra_link_args"] = []

    if sys.platform.startswith("win"):
        settings["libraries"].append("libzmq")

        if prefix:
            settings["include_dirs"] += [pjoin(prefix, "include")]
            settings["library_dirs"] += [pjoin(prefix, "lib")]
    else:

        # If prefix is not explicitly set, pull it from pkg-config by default.

        if not prefix:
            try:
                p = Popen("pkg-config --variable=prefix --print-errors libzmq".split(), stdout=PIPE, stderr=PIPE)
            except OSError as e:
                if e.errno == errno.ENOENT:
                    info("pkg-config not found")
                else:
                    warn("Running pkg-config failed - %s." % e)
                p = None
            if p is not None:
                if p.wait():
                    info("Did not find libzmq via pkg-config:")
                    info(p.stderr.read().decode())
                else:
                    prefix = p.stdout.readline().strip().decode()
                    info("Using zmq-prefix %s (found via pkg-config)." % prefix)

        settings["libraries"].append("zmq")
        # add pthread on freebsd
        if sys.platform.startswith("freebsd"):
            settings["libraries"].append("pthread")

        if prefix:
            settings["include_dirs"] += [pjoin(prefix, "include")]
            if not bundle_libzmq_dylib:
                if sys.platform == "sunos5":
                    if platform.architecture()[0] == "32bit":
                        settings["library_dirs"] += [pjoin(prefix, "lib")]
                    else:
                        settings["library_dirs"] += [pjoin(prefix, "lib/amd64")]
                        settings["extra_link_args"] += ["-m64"]
                else:
                    settings["library_dirs"] += [pjoin(prefix, "lib")]
        else:
            if sys.platform == "darwin" and os.path.isdir("/opt/local/lib"):
                # allow macports default
                settings["include_dirs"] += ["/opt/local/include"]
                settings["library_dirs"] += ["/opt/local/lib"]
            if os.environ.get("VIRTUAL_ENV", None):
                # find libzmq installed in virtualenv
                env = os.environ["VIRTUAL_ENV"]
                settings["include_dirs"] += [pjoin(env, "include")]
                settings["library_dirs"] += [pjoin(env, "lib")]

        if bundle_libzmq_dylib:
            # bdist should link against bundled libzmq
            settings["library_dirs"].append("zmq")
            if sys.platform == "darwin":
                pass
                # unused rpath args for OS X:
                # settings['extra_link_args'] = ['-Wl,-rpath','-Wl,$ORIGIN/..']
            else:
                settings["runtime_library_dirs"] += ["$ORIGIN/.."]
        elif sys.platform != "darwin":
            settings["runtime_library_dirs"] += [os.path.abspath(x) for x in settings["library_dirs"]]

    return settings
Ejemplo n.º 17
0
Archivo: setup.py Proyecto: fwph/pyzmq
def settings_from_prefix(prefix=None, bundle_libzmq_dylib=False):
    """load appropriate library/include settings from ZMQ prefix"""
    settings = {}
    settings['libraries'] = []
    settings['include_dirs'] = []
    settings['library_dirs'] = []
    settings['runtime_library_dirs'] = []
    settings['extra_link_args'] = [] 
    
    if sys.platform.startswith('win'):
        settings['libraries'].append('libzmq')
        
        if prefix:
            settings['include_dirs'] += [pjoin(prefix, 'include')]
            settings['library_dirs'] += [pjoin(prefix, 'lib')]
    else:

        # If prefix is not explicitly set, pull it from pkg-config by default.

        if not prefix:
            try:
                p = Popen('pkg-config --variable=prefix --print-errors libzmq'.split(), stdout=PIPE, stderr=PIPE)
            except OSError as e:
                if e.errno == errno.ENOENT:
                    info("pkg-config not found")
                else:
                    warn("Running pkg-config failed - %s." % e)
                p = None
            if p is not None:
                if p.wait():
                    info("Did not find libzmq via pkg-config:")
                    info(p.stderr.read().decode())
                else:
                    prefix = p.stdout.readline().strip().decode()
                    info("Using zmq-prefix %s (found via pkg-config)." % prefix)

        settings['libraries'].append('zmq')
        # add pthread on freebsd
        if sys.platform.startswith('freebsd'):
            settings['libraries'].append('pthread')
        
        if sys.platform.startswith('sunos'):
          if platform.architecture()[0] == '32bit':
            settings['extra_link_args'] += ['-m32']
          else:
            settings['extra_link_args'] += ['-m64']
        
        if prefix:
            settings['include_dirs'] += [pjoin(prefix, 'include')]
            if not bundle_libzmq_dylib:
                if sys.platform.startswith('sunos') and platform.architecture()[0] == '64bit':
                    settings['library_dirs'] += [pjoin(prefix, 'lib/amd64')]
                settings['library_dirs'] += [pjoin(prefix, 'lib')]
        else:
            if sys.platform == 'darwin' and os.path.isdir('/opt/local/lib'):
                # allow macports default
                settings['include_dirs'] += ['/opt/local/include']
                settings['library_dirs'] += ['/opt/local/lib']
            if os.environ.get('VIRTUAL_ENV', None):
                # find libzmq installed in virtualenv
                env = os.environ['VIRTUAL_ENV']
                settings['include_dirs'] += [pjoin(env, 'include')]
                settings['library_dirs'] += [pjoin(env, 'lib')]
    
        if bundle_libzmq_dylib:
            # bdist should link against bundled libzmq
            settings['library_dirs'].append('zmq')
            if sys.platform == 'darwin':
                pass
                # unused rpath args for OS X:
                # settings['extra_link_args'] = ['-Wl,-rpath','-Wl,$ORIGIN/..']
            else:
                settings['runtime_library_dirs'] += ['$ORIGIN/..']
        elif sys.platform != 'darwin':
            settings['runtime_library_dirs'] += [
                os.path.abspath(x) for x in settings['library_dirs']
            ]
    
    return settings
Ejemplo n.º 18
0
def settings_from_prefix(prefix=None, bundle_libzmq_dylib=False):
    """load appropriate library/include settings from ZMQ prefix"""
    settings = {}
    settings["libraries"] = []
    settings["include_dirs"] = []
    settings["library_dirs"] = []
    settings["runtime_library_dirs"] = []
    settings["extra_link_args"] = []

    if sys.platform.startswith("win"):
        settings["libraries"].append("libzmq")

        if prefix:
            settings["include_dirs"] += [pjoin(prefix, "include")]
            settings["library_dirs"] += [pjoin(prefix, "lib")]
    else:
        # add pthread on freebsd
        if sys.platform.startswith("freebsd"):
            settings["libraries"].append("pthread")

        if sys.platform.startswith("sunos"):
            if platform.architecture()[0] == "32bit":
                settings["extra_link_args"] += ["-m32"]
            else:
                settings["extra_link_args"] += ["-m64"]

        if prefix:
            settings["libraries"].append("zmq")

            settings["include_dirs"] += [pjoin(prefix, "include")]
            if not bundle_libzmq_dylib:
                if sys.platform.startswith("sunos") and platform.architecture()[0] == "64bit":
                    settings["library_dirs"] += [pjoin(prefix, "lib/amd64")]
                settings["library_dirs"] += [pjoin(prefix, "lib")]
        else:
            # If prefix is not explicitly set, pull it from pkg-config by default.
            # this is probably applicable across platforms, but i don't have
            # sufficient test environments to confirm
            pkgcfginfo = check_pkgconfig()
            if pkgcfginfo is not None:
                # we can get all the zmq-specific values from pkgconfg
                for key, value in pkgcfginfo.items():
                    settings[key].extend(value)
            else:
                settings["libraries"].append("zmq")

                if sys.platform == "darwin" and os.path.isdir("/opt/local/lib"):
                    # allow macports default
                    settings["include_dirs"] += ["/opt/local/include"]
                    settings["library_dirs"] += ["/opt/local/lib"]
                if os.environ.get("VIRTUAL_ENV", None):
                    # find libzmq installed in virtualenv
                    env = os.environ["VIRTUAL_ENV"]
                    settings["include_dirs"] += [pjoin(env, "include")]
                    settings["library_dirs"] += [pjoin(env, "lib")]

        if bundle_libzmq_dylib:
            # bdist should link against bundled libzmq
            settings["library_dirs"].append("zmq")
            if sys.platform == "darwin":
                pass
                # unused rpath args for OS X:
                # settings['extra_link_args'] = ['-Wl,-rpath','-Wl,$ORIGIN/..']
            else:
                settings["runtime_library_dirs"] += ["$ORIGIN/.."]
        elif sys.platform != "darwin":
            info("%r" % settings)
            settings["runtime_library_dirs"] += [os.path.abspath(x) for x in settings["library_dirs"]]

    return settings
Ejemplo n.º 19
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'])
        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)
            cc.output_dir = self.build_temp
            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)
Ejemplo 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'))
        
        # 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)
Ejemplo n.º 21
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)
Ejemplo n.º 22
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)

        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)
Ejemplo n.º 23
0
Archivo: setup.py Proyecto: 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)
Ejemplo n.º 24
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)
 def run(self):
     cfg = self.config
     if 'PyPy' in sys.version:
         info("PyPy: Nothing to configure")
         return
     
     if cfg['libzmq_extension']:
         self.bundle_libzmq_extension()
         self.finish_run()
         return
     
     # When cross-compiling and zmq is given explicitly, we can't testbuild
     # (as we can't testrun the binary), we assume things are alright.
     if cfg['skip_check_zmq'] or self.cross_compiling:
         warn("Skipping zmq version check")
         self.finish_run()
         return
     
     zmq_prefix = cfg['zmq_prefix']
     # There is no available default on Windows, so start with fallback unless
     # zmq was given explicitly, or libzmq extension was explicitly prohibited.
     if sys.platform.startswith("win") and \
             not cfg['no_libzmq_extension'] and \
             not zmq_prefix:
         self.fallback_on_bundled()
         self.finish_run()
         return
     
     if zmq_prefix and self.bundle_libzmq_dylib and not sys.platform.startswith('win'):
         copy_and_patch_libzmq(zmq_prefix, 'libzmq'+lib_ext)
     
     # first try with given config or defaults
     try:
         self.check_zmq_version()
     except Exception:
         etype, evalue, tb = sys.exc_info()
         # print the error as distutils would if we let it raise:
         info("\nerror: %s\n" % evalue)
     else:
         self.finish_run()
         return
     
     # try fallback on /usr/local on *ix if no prefix is given
     if not zmq_prefix and not sys.platform.startswith('win'):
         info("Failed with default libzmq, trying again with /usr/local")
         time.sleep(1)
         zmq_prefix = cfg['zmq_prefix'] = '/usr/local'
         self.init_settings_from_config()
         try:
             self.check_zmq_version()
         except Exception:
             etype, evalue, tb = sys.exc_info()
             # print the error as distutils would if we let it raise:
             info("\nerror: %s\n" % evalue)
         else:
             # if we get here the second run succeeded, so we need to update compiler
             # settings for the extensions with /usr/local prefix
             self.finish_run()
             return
     
     # finally, fallback on bundled
     
     if cfg['no_libzmq_extension']:
         fatal("Falling back on bundled libzmq,"
         " but setup.cfg has explicitly prohibited building the libzmq extension."
         )
     
     self.fallback_on_bundled()
     
     self.finish_run()
Ejemplo n.º 26
0
    def run(self):
        cfg = self.config

        if cfg['libzmq_extension']:
            self.bundle_libzmq_extension()
            self.finish_run()
            return

        # When cross-compiling and zmq is given explicitly, we can't testbuild
        # (as we can't testrun the binary), we assume things are alright.
        if cfg['skip_check_zmq'] or self.cross_compiling:
            warn("Skipping zmq version check")
            self.finish_run()
            return

        zmq_prefix = cfg['zmq_prefix']
        # There is no available default on Windows, so start with fallback unless
        # zmq was given explicitly, or libzmq extension was explicitly prohibited.
        if sys.platform.startswith("win") and \
                not cfg['no_libzmq_extension'] and \
                not zmq_prefix:
            self.fallback_on_bundled()
            self.finish_run()
            return

        if zmq_prefix and self.bundle_libzmq_dylib and not sys.platform.startswith(
                'win'):
            copy_and_patch_libzmq(zmq_prefix, libzmq_name + lib_ext)

        # first try with given config or defaults
        try:
            self.check_zmq_version()
        except LibZMQVersionError as e:
            info("\nBad libzmq version: %s\n" % e)
        except Exception as e:
            # print the error as distutils would if we let it raise:
            info("\nerror: %s\n" % e)
        else:
            self.finish_run()
            return

        # try fallback on /usr/local on *ix if no prefix is given
        if not zmq_prefix and not sys.platform.startswith('win'):
            info("Failed with default libzmq, trying again with /usr/local")
            time.sleep(1)
            zmq_prefix = cfg['zmq_prefix'] = '/usr/local'
            self.init_settings_from_config()
            try:
                self.check_zmq_version()
            except LibZMQVersionError as e:
                info("\nBad libzmq version: %s\n" % e)
            except Exception as e:
                # print the error as distutils would if we let it raise:
                info("\nerror: %s\n" % e)
            else:
                # if we get here the second run succeeded, so we need to update compiler
                # settings for the extensions with /usr/local prefix
                self.finish_run()
                return

        # finally, fallback on bundled

        if cfg['no_libzmq_extension']:
            fatal(
                "Falling back on bundled libzmq,"
                " but config has explicitly prohibited building the libzmq extension."
            )

        self.fallback_on_bundled()

        self.finish_run()
Ejemplo n.º 27
0
def settings_from_prefix(prefix=None, bundle_libzmq_dylib=False):
    """load appropriate library/include settings from ZMQ prefix"""
    settings = {}
    settings['libraries'] = []
    settings['include_dirs'] = []
    settings['library_dirs'] = []
    settings['runtime_library_dirs'] = []
    settings['extra_link_args'] = []

    if sys.platform.startswith('win'):
        settings['libraries'].append(libzmq_name)

        if prefix:
            settings['include_dirs'] += [pjoin(prefix, 'include')]
            settings['library_dirs'] += [pjoin(prefix, 'lib')]
    else:
        # add pthread on freebsd
        if sys.platform.startswith('freebsd'):
            settings['libraries'].append('pthread')

        if sys.platform.startswith('sunos'):
            if platform.architecture()[0] == '32bit':
                settings['extra_link_args'] += ['-m32']
            else:
                settings['extra_link_args'] += ['-m64']

        if prefix:
            settings['libraries'].append('zmq')

            settings['include_dirs'] += [pjoin(prefix, 'include')]
            if not bundle_libzmq_dylib:
                if sys.platform.startswith(
                        'sunos') and platform.architecture()[0] == '64bit':
                    settings['library_dirs'] += [pjoin(prefix, 'lib/amd64')]
                settings['library_dirs'] += [pjoin(prefix, 'lib')]
        else:
            # If prefix is not explicitly set, pull it from pkg-config by default.
            # this is probably applicable across platforms, but i don't have
            # sufficient test environments to confirm
            pkgcfginfo = check_pkgconfig()
            if pkgcfginfo is not None:
                # we can get all the zmq-specific values from pkgconfg
                for key, value in pkgcfginfo.items():
                    settings[key].extend(value)
            else:
                settings['libraries'].append('zmq')

                if sys.platform == 'darwin' and os.path.isdir(
                        '/opt/local/lib'):
                    # allow macports default
                    settings['include_dirs'] += ['/opt/local/include']
                    settings['library_dirs'] += ['/opt/local/lib']
                if os.environ.get('VIRTUAL_ENV', None):
                    # find libzmq installed in virtualenv
                    env = os.environ['VIRTUAL_ENV']
                    settings['include_dirs'] += [pjoin(env, 'include')]
                    settings['library_dirs'] += [pjoin(env, 'lib')]

        if bundle_libzmq_dylib:
            # bdist should link against bundled libzmq
            settings['library_dirs'].append('zmq')
            _add_rpath(settings, '$ORIGIN/..')
            if sys.platform == 'darwin' and pypy:
                settings['extra_link_args'].extend(
                    ['-undefined', 'dynamic_lookup'])
        else:
            for path in settings['library_dirs']:
                _add_rpath(settings, os.path.abspath(path))
    info(settings)

    return settings
Ejemplo n.º 28
0
def settings_from_prefix(prefix=None, bundle_libzmq_dylib=False):
    """load appropriate library/include settings from ZMQ prefix"""
    settings = {}
    settings['libraries'] = []
    settings['include_dirs'] = []
    settings['library_dirs'] = []
    settings['runtime_library_dirs'] = []
    settings['extra_link_args'] = [] 
    
    if sys.platform.startswith('win'):
        settings['libraries'].append('libzmq')
        
        if prefix:
            settings['include_dirs'] += [pjoin(prefix, 'include')]
            settings['library_dirs'] += [pjoin(prefix, 'lib')]
    else:
        # add pthread on freebsd
        if sys.platform.startswith('freebsd'):
            settings['libraries'].append('pthread')

        if sys.platform.startswith('sunos'):
          if platform.architecture()[0] == '32bit':
            settings['extra_link_args'] += ['-m32']
          else:
            settings['extra_link_args'] += ['-m64']

        if prefix:
            settings['libraries'].append('zmq')

            settings['include_dirs'] += [pjoin(prefix, 'include')]
            if not bundle_libzmq_dylib:
                if sys.platform.startswith('sunos') and platform.architecture()[0] == '64bit':
                    settings['library_dirs'] += [pjoin(prefix, 'lib/amd64')]
                settings['library_dirs'] += [pjoin(prefix, 'lib')]
        else:
            # If prefix is not explicitly set, pull it from pkg-config by default.
            # this is probably applicable across platforms, but i don't have
            # sufficient test environments to confirm
            pkgcfginfo = check_pkgconfig()
            if pkgcfginfo is not None:
                # we can get all the zmq-specific values from pkgconfg
                for key, value in pkgcfginfo.items():
                    settings[key].extend(value)
            else:
                settings['libraries'].append('zmq')

                if sys.platform == 'darwin' and os.path.isdir('/opt/local/lib'):
                    # allow macports default
                    settings['include_dirs'] += ['/opt/local/include']
                    settings['library_dirs'] += ['/opt/local/lib']
                if os.environ.get('VIRTUAL_ENV', None):
                    # find libzmq installed in virtualenv
                    env = os.environ['VIRTUAL_ENV']
                    settings['include_dirs'] += [pjoin(env, 'include')]
                    settings['library_dirs'] += [pjoin(env, 'lib')]
    



        if bundle_libzmq_dylib:
            # bdist should link against bundled libzmq
            settings['library_dirs'].append('zmq')
            if sys.platform == 'darwin':
                pass
                # unused rpath args for OS X:
                # settings['extra_link_args'] = ['-Wl,-rpath','-Wl,$ORIGIN/..']
            else:
                settings['runtime_library_dirs'] += ['$ORIGIN/..']
        elif sys.platform != 'darwin':
            info("%r" % settings)
            settings['runtime_library_dirs'] += [
                os.path.abspath(x) for x in settings['library_dirs']
            ]
    
    return settings
Ejemplo n.º 29
0
def settings_from_prefix(prefix=None, bundle_libzmq_dylib=False):
    """load appropriate library/include settings from ZMQ prefix"""
    settings = {}
    settings['libraries'] = []
    settings['include_dirs'] = []
    settings['library_dirs'] = []
    settings['runtime_library_dirs'] = []
    settings['extra_link_args'] = []

    if sys.platform.startswith('win'):
        settings['libraries'].append('libzmq')

        if prefix:
            settings['include_dirs'] += [pjoin(prefix, 'include')]
            settings['library_dirs'] += [pjoin(prefix, 'lib')]
    else:

        # If prefix is not explicitly set, pull it from pkg-config by default.

        if not prefix:
            try:
                p = Popen('pkg-config --variable=prefix --print-errors libzmq'.
                          split(),
                          stdout=PIPE,
                          stderr=PIPE)
            except OSError as e:
                if e.errno == errno.ENOENT:
                    info("pkg-config not found")
                else:
                    warn("Running pkg-config failed - %s." % e)
                p = None
            if p is not None:
                if p.wait():
                    info("Did not find libzmq via pkg-config:")
                    info(p.stderr.read().decode())
                else:
                    prefix = p.stdout.readline().strip().decode()
                    info("Using zmq-prefix %s (found via pkg-config)." %
                         prefix)

        settings['libraries'].append('zmq')
        # add pthread on freebsd
        if sys.platform.startswith('freebsd'):
            settings['libraries'].append('pthread')

        if prefix:
            settings['include_dirs'] += [pjoin(prefix, 'include')]
            if not bundle_libzmq_dylib:
                if sys.platform == 'sunos5':
                    if platform.architecture()[0] == '32bit':
                        settings['library_dirs'] += [pjoin(prefix, 'lib')]
                    else:
                        settings['library_dirs'] += [
                            pjoin(prefix, 'lib/amd64')
                        ]
                        settings['extra_link_args'] += ['-m64']
                else:
                    settings['library_dirs'] += [pjoin(prefix, 'lib')]
        else:
            if sys.platform == 'darwin' and os.path.isdir('/opt/local/lib'):
                # allow macports default
                settings['include_dirs'] += ['/opt/local/include']
                settings['library_dirs'] += ['/opt/local/lib']
            if os.environ.get('VIRTUAL_ENV', None):
                # find libzmq installed in virtualenv
                env = os.environ['VIRTUAL_ENV']
                settings['include_dirs'] += [pjoin(env, 'include')]
                settings['library_dirs'] += [pjoin(env, 'lib')]

        if bundle_libzmq_dylib:
            # bdist should link against bundled libzmq
            settings['library_dirs'].append('zmq')
            if sys.platform == 'darwin':
                pass
                # unused rpath args for OS X:
                # settings['extra_link_args'] = ['-Wl,-rpath','-Wl,$ORIGIN/..']
            else:
                settings['runtime_library_dirs'] += ['$ORIGIN/..']
        elif sys.platform != 'darwin':
            settings['runtime_library_dirs'] += [
                os.path.abspath(x) for x in settings['library_dirs']
            ]

    return settings
Ejemplo n.º 30
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)