Exemplo n.º 1
0
    def get_ext_fullpath(self, name):
        # this method is overridden because of Windows and needing to compile an extension with the same
        # version compiler that was used to compile Python. When building a wheel or an egg
        # we are able to create that binary for each of the Python versions that use a specific msvc compiler
        # an example would be 3.5, 3.6, 3.7, 3.8  all use msvc 14. because the naming conventions of the pyd file
        # target specific python versions like this "kiwisolver.cp37-win_amd64.pyd" we need to shop out all
        # of the middle bits to end up with "kiwisolver.pyd". this file name for the extension is still able
        # to be loaded by python. and this is what gets packaged into the wheel. so we are able to build
        # 4 wheels or 4 eggs with only having to run the build for one of the python versions listed above.
        # the wheel/egg filename is what is going to set the python version/archeticture the wheel/egg is
        # allowed to be installed on.

        path = _build_ext.get_ext_fullpath(self, name)

        path, file_name = os.path.split(path)

        '_libflif.cp38.cp37.cp36.cp35-win_amd64.pyd'

        tag = 'cp' + str(sys.version_info[0]) + str(sys.version_info[1])

        if tag[2:] in ('38', '37', '36', '35'):
            name = name.replace(tag, 'cp38.cp37.cp36.cp35')
        elif tag[2:] in ('34', '33'):
            name = name.replace(tag, 'cp34.cp33')
        elif tag[2:] in ('32', '31', '30'):
            name = name.replace(tag, 'cp32.cp31.cp30')

        return os.path.join(path, file_name)
Exemplo n.º 2
0
Arquivo: setup.py Projeto: uw-ipd/rif
    def build_extension(self, ext):
        extdir = os.path.abspath(
            os.path.dirname(build_ext.get_ext_fullpath(self, ext.name)))
        cmake_args = [
            '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
            '-DPYTHON_EXECUTABLE=' + sys.executable, '-GNinja'
        ]

        if 'CMAKE_OPTIONS' in os.environ:
            cmake_args += os.environ['CMAKE_OPTIONS'].split()

        ncpu = 4

        cmake_args += [
            '-DPYTHON_EXECUTABLE:FILEPATH=' + sys.executable,
        ]
        build_args = ['--config', "Release"]

        env = os.environ.copy()
        env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(
            env.get('CXXFLAGS', ''), self.distribution.get_version())

        os.makedirs(extdir, exist_ok=True)
        os.makedirs(self.build_temp, exist_ok=True)

        try:
            subprocess.check_call(['cmake', ext.sourcedir] + cmake_args,
                                  cwd=self.build_temp,
                                  env=env)
            subprocess.check_call(['cmake', '--build', '.'] + build_args,
                                  cwd=self.build_temp)
        except subprocess.CalledProcessError as e:
            sys.exit(e.returncode)
Exemplo n.º 3
0
def build_cmake(build_ext, ext, output_dir, options):
    cmake_bin = 'cmake'

    # Statically linked archive files go into the provided output directory
    extdir = os.path.abspath(
        os.path.dirname(build_ext.get_ext_fullpath(ext.name)))
    config = 'Debug' if build_ext.debug else 'Release'
    cmake_args = [
        '-DUSE_MPI=ON',
        '-DCMAKE_BUILD_TYPE=' + config,
        '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(config.upper(), extdir),
        '-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_{}={}'.format(config.upper(),
                                                        output_dir),
    ]
    cmake_build_args = [
        '--config', config,
        '--', '-j4',
    ]

    # Keep temp build files within a unique subdirectory
    build_temp = os.path.abspath(os.path.join(build_ext.build_temp, ext.name))
    if not os.path.exists(build_temp):
        os.makedirs(build_temp)

    # Config and build the extension
    try:
        subprocess.check_call([cmake_bin, ext.cmake_lists_dir] + cmake_args,
                              cwd=build_temp)
        subprocess.check_call([cmake_bin, '--build', '.'] + cmake_build_args,
                              cwd=build_temp)
    except OSError as e:
        raise RuntimeError('CMake failed: {}'.format(str(e)))

    # Add the library so other extensions will link against it during compilation
    options['LIBRARIES'] += [ext.name]
def build_cmake(build_ext, ext, prefix, plugin_ext=None, options=None):

    cmake_bin = 'cmake'

    # All statically linked libraries will be placed here
    lib_output_dir = os.path.abspath(os.path.join(build_ext.build_temp, 'lib', prefix))

    if not os.path.exists(lib_output_dir):
        os.makedirs(lib_output_dir)

    if plugin_ext:
        plugin_ext.library_dirs += [lib_output_dir]

    if options:
        options['LIBRARY_DIRS'] += [lib_output_dir]

    extdir = os.path.abspath(os.path.dirname(build_ext.get_ext_fullpath(ext.name)))

    # config = 'Debug' if build_ext.debug else 'Release'
    config = 'Release'

    cmake_args = [
        '-DCMAKE_BUILD_TYPE=' + config,
        '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(config.upper(), extdir),
        '-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_{}={}'.format(config.upper(),
                                                        lib_output_dir),
    ]

    cmake_build_args = [
        '--config', config,
        '--', '-j4',
    ]

    # Keep temp build files within a unique subdirectory
    build_temp = os.path.abspath(os.path.join(build_ext.build_temp, ext.name))

    if not os.path.exists(build_temp):
        os.makedirs(build_temp)

    # Config and build the extension
    try:
        subprocess.check_call([cmake_bin, ext.cmake_lists_dir] + cmake_args, cwd=build_temp)
        subprocess.check_call([cmake_bin, '--build', '.'] + cmake_build_args,cwd=build_temp)

    except OSError as e:
        raise RuntimeError('CMake failed: {}'.format(str(e)))

    # Add the library so the plugin will link against it during compilation
    if plugin_ext:
        plugin_ext.libraries += [ext.name]

    if options:
        options['LIBRARIES'] += [ext.name]
Exemplo n.º 5
0
 def get_ext_fullpath(self, ext_name):
     defaultname = build_ext.get_ext_fullpath(self, ext_name)
     path = os.path.dirname(defaultname)
     path += '-' + self.my_tag + '/'
     path += os.path.basename(defaultname)
     return path, defaultname
Exemplo n.º 6
0
    def run(self):
        """Run the command."""
        # Generate docs/INFO_SRC
        write_info_src(VERSION_TEXT)

        disabled = []  # Extensions to be disabled
        for ext in self.extensions:
            # Add Protobuf include and library dirs
            if ext.name == "_mysqlxpb":
                if not self.with_mysqlxpb_cext:
                    self.log.warning(
                        "The '_mysqlxpb' C extension will not be built")
                    disabled.append(ext)
                    continue
                ext.include_dirs.append(self.with_protobuf_include_dir)
                ext.library_dirs.append(self._build_protobuf_lib_dir)
                ext.libraries.append(
                    "libprotobuf" if os.name == "nt" else "protobuf")
                # Add -std=c++11 needed for Protobuf 3.6.1
                ext.extra_compile_args.append("-std=c++11")
                self._run_protoc()
            if ext.name == "_mysql_connector":
                if not self.with_mysql_capi:
                    self.log.warning(
                        "The '_mysql_connector' C extension will not be built")
                    disabled.append(ext)
                    continue
                # Add extra compile args
                if self.extra_compile_args:
                    ext.extra_compile_args.extend(
                        self.extra_compile_args.split())
                # Add extra link args
                if self.extra_link_args:
                    ext.extra_link_args.extend(self.extra_link_args.split())
                # Add -rpath if the platform is Linux
                if platform.system() == "Linux":
                    ext.extra_link_args.extend([
                        "-Wl,-rpath,$ORIGIN/mysql/vendor"])
                # Add include dirs
                if self.with_openssl_include_dir:
                    ext.include_dirs.append(self.with_openssl_include_dir)
                if "include_dirs" in self._mysql_info:
                    ext.include_dirs.extend(self._mysql_info["include_dirs"])
                # Add library dirs
                ext.library_dirs.append(self._build_mysql_lib_dir)
                if "library_dirs" in self._mysql_info:
                    ext.library_dirs.extend(self._mysql_info["library_dirs"])
                if self.with_openssl_lib_dir:
                    ext.library_dirs.append(self.with_openssl_lib_dir)
                # Add libraries
                if "libraries" in self._mysql_info:
                    ext.libraries.extend(self._mysql_info["libraries"])
            # Suppress unknown pragmas
            if os.name == "posix":
                ext.extra_compile_args.append("-Wno-unknown-pragmas")

        # Remove disabled extensions
        for ext in disabled:
            self.extensions.remove(ext)

        build_ext.run(self)

        # Change @loader_path if the platform is MacOS
        if platform.system() == "Darwin" and self.with_openssl_lib_dir:
            for ext in self.extensions:
                if ext.name == "_mysql_connector":
                    libssl, libcrypto = self._get_openssl_libs()
                    cmd_libssl = [
                        "install_name_tool", "-change", libssl,
                        "@loader_path/mysql/vendor/{0}".format(libssl),
                        build_ext.get_ext_fullpath(self, "_mysql_connector")
                    ]
                    self.log.info("Executing: {0}"
                                  "".format(" ".join(cmd_libssl)))
                    proc = Popen(cmd_libssl, stdout=PIPE,
                                 universal_newlines=True)
                    stdout, _ = proc.communicate()
                    cmd_libcrypto = [
                        "install_name_tool", "-change", libcrypto,
                        "@loader_path/mysql/vendor/{0}".format(libcrypto),
                        build_ext.get_ext_fullpath(self, "_mysql_connector")
                    ]
                    self.log.info("Executing: {0}"
                                  "".format(" ".join(cmd_libcrypto)))
                    proc = Popen(cmd_libcrypto, stdout=PIPE,
                                 universal_newlines=True)
                    stdout, _ = proc.communicate()

        # Generate docs/INFO_BIN
        if self.with_mysql_capi:
            mysql_version = self._get_mysql_version()
            compiler = self.compiler.compiler_so[0] \
                if hasattr(self.compiler, "compiler_so") else None
            write_info_bin(mysql_version, compiler)