Esempio n. 1
0
    def set_lldb_flags(
            self, target: hosts.Host, defines: Dict[str, str]) -> None:  # pylint: disable=no-self-use
        """Sets cmake defines for lldb."""
        # By default all these are auto-detected. Disable them explicitly to avoid unexpected dependency.
        # They may be enabled again below if necessary.
        defines['LLDB_ENABLE_LIBEDIT'] = 'OFF'
        defines['LLDB_ENABLE_LZMA'] = 'OFF'
        defines['LLDB_ENABLE_LIBXML2'] = 'OFF'
        defines['LLDB_ENABLE_LUA'] = 'OFF'

        swig_executable = BuilderRegistry.get(
            'swig').install_dir / 'bin' / 'swig'
        defines['SWIG_EXECUTABLE'] = str(swig_executable)
        py_prefix = 'Python3' if target.is_windows else 'PYTHON'
        defines['LLDB_ENABLE_PYTHON'] = 'ON'
        defines[f'{py_prefix}_LIBRARY'] = str(paths.get_python_lib(target))
        defines[f'{py_prefix}_LIBRARIES'] = str(paths.get_python_lib(target))
        defines[f'{py_prefix}_INCLUDE_DIR'] = str(
            paths.get_python_include_dir(target))
        defines[f'{py_prefix}_INCLUDE_DIRS'] = str(
            paths.get_python_include_dir(target))
        defines[f'{py_prefix}_EXECUTABLE'] = str(
            paths.get_python_executable(hosts.build_host()))

        defines['LLDB_EMBED_PYTHON_HOME'] = 'ON'
        defines['LLDB_PYTHON_HOME'] = '../python3'

        if target.is_darwin:
            # Avoids the build of debug server. It is only used in testing.
            defines['LLDB_USE_SYSTEM_DEBUGSERVER'] = 'ON'

        if not target.is_windows:
            libedit_root = BuilderRegistry.get('libedit').install_dir
            defines['LLDB_ENABLE_LIBEDIT'] = 'ON'
            defines['LibEdit_INCLUDE_DIRS'] = str(
                paths.get_libedit_include_dir(libedit_root))
            defines['LibEdit_LIBRARIES'] = str(
                paths.get_libedit_lib(libedit_root, target))
Esempio n. 2
0
 def ldflags(self) -> List[str]:
     ldflags = super().ldflags
     ldflags.append('-Wl,--dynamicbase')
     ldflags.append('-Wl,--nxcompat')
     # Use static-libgcc to avoid runtime dependence on libgcc_eh.
     ldflags.append('-static-libgcc')
     # pthread is needed by libgcc_eh.
     ldflags.append('-pthread')
     # Add path to libc++, libc++abi.
     libcxx_lib = BuilderRegistry.get('libcxx').install_dir / 'lib64'
     ldflags.append(f'-L{libcxx_lib}')
     ldflags.append('-Wl,--high-entropy-va')
     ldflags.append('-Wl,--Xlink=-Brepro')
     ldflags.append(f'-L{paths.WIN_ZLIB_LIB_PATH}')
     return ldflags
Esempio n. 3
0
    def cxxflags(self) -> List[str]:
        cxxflags = super().cxxflags

        # Use -fuse-cxa-atexit to allow static TLS destructors.  This is needed for
        # clang-tools-extra/clangd/Context.cpp
        cxxflags.append('-fuse-cxa-atexit')

        # Explicitly add the path to libc++ headers.  We don't need to configure
        # options like visibility annotations, win32 threads etc. because the
        # __generated_config header in the patch captures all the options used when
        # building libc++.
        cxx_headers = BuilderRegistry.get(
            'libcxx').install_dir / 'include' / 'c++' / 'v1'
        cxxflags.append(f'-I{cxx_headers}')

        return cxxflags
Esempio n. 4
0
def install_lldb_deps(install_dir: Path, host: hosts.Host):
    lib_dir = install_dir / ('bin' if host.is_windows else 'lib64')
    check_create_path(lib_dir)

    python_prebuilt_dir: Path = paths.get_python_dir(host)
    python_dest_dir: Path = install_dir / 'python3'
    shutil.copytree(python_prebuilt_dir, python_dest_dir, symlinks=True,
                    ignore=shutil.ignore_patterns('*.pyc', '__pycache__', 'Android.bp'
                                                  '.git', '.gitignore'))

    py_lib = paths.get_python_dynamic_lib(host).relative_to(python_prebuilt_dir)
    dest_py_lib = python_dest_dir / py_lib
    py_lib_rel = os.path.relpath(dest_py_lib, lib_dir)
    os.symlink(py_lib_rel, lib_dir / py_lib.name)
    if not host.is_windows:
        libedit_root = BuilderRegistry.get('libedit').install_dir
        shutil.copy2(paths.get_libedit_lib(libedit_root, host), lib_dir)
Esempio n. 5
0
    def cmake_defines(self) -> Dict[str, str]:
        defines: Dict[str, str] = super().cmake_defines
        defines['LIBCXX_ENABLE_STATIC_ABI_LIBRARY'] = 'ON'
        defines['LIBCXX_CXX_ABI'] = 'libcxxabi'
        defines['LIBCXX_HAS_WIN32_THREAD_API'] = 'ON'

        # Use cxxabi header from the source directory since it gets installed
        # into install_dir only during libcxx's install step.  But use the
        # library from install_dir.
        defines['LIBCXX_CXX_ABI_INCLUDE_PATHS'] = str(paths.LLVM_PATH /
                                                      'libcxxabi' / 'include')
        defines['LIBCXX_CXX_ABI_LIBRARY_PATH'] = str(
            BuilderRegistry.get('libcxxabi').install_dir / 'lib64')

        # Build only the static library.
        defines['LIBCXX_ENABLE_SHARED'] = 'OFF'

        if self.enable_assertions:
            defines['LIBCXX_ENABLE_ASSERTIONS'] = 'ON'

        return defines
Esempio n. 6
0
def main():
    args = parse_args()
    if args.skip_build:
        # Skips all builds
        BuilderRegistry.add_filter(lambda name: False)
    elif args.skip:
        BuilderRegistry.add_skips(args.skip)
    elif args.build:
        BuilderRegistry.add_builds(args.build)
    do_runtimes = not args.skip_runtimes
    do_package = not args.skip_package
    do_strip = not args.no_strip
    do_strip_host_package = do_strip and not args.debug and not args.build_llvm_next
    build_lldb = 'lldb' not in args.no_build

    android_version.set_llvm_next(args.build_llvm_next)

    need_host = hosts.build_host().is_darwin or ('linux' not in args.no_build)
    need_windows = hosts.build_host().is_linux and ('windows'
                                                    not in args.no_build)

    logging.basicConfig(level=logging.DEBUG)

    logger().info(
        'do_build=%r do_stage1=%r do_stage2=%r do_runtimes=%r do_package=%r need_windows=%r'
        % (not args.skip_build, BuilderRegistry.should_build('stage1'),
           BuilderRegistry.should_build('stage2'), do_runtimes, do_package,
           need_windows))

    # Clone sources to be built and apply patches.
    if not args.skip_source_setup:
        source_manager.setup_sources(source_dir=paths.LLVM_PATH)

    # Build the stage1 Clang for the build host
    instrumented = hosts.build_host().is_linux and args.build_instrumented

    stage1 = builders.Stage1Builder()
    stage1.build_name = 'stage1'
    stage1.svn_revision = android_version.get_svn_revision()
    # Build lldb for lldb-tblgen. It will be used to build lldb-server and windows lldb.
    stage1.build_lldb = build_lldb
    stage1.build_android_targets = args.debug or instrumented
    stage1.build()
    set_default_toolchain(stage1.installed_toolchain)

    if build_lldb:
        # Swig is needed for both host and windows lldb.
        swig_builder = builders.SwigBuilder()
        swig_builder.build()
    else:
        swig_builder = None

    if need_host:
        if not args.no_pgo:
            profdata = extract_profdata()
        else:
            profdata = None

        stage2 = builders.Stage2Builder()
        stage2.build_name = args.build_name
        stage2.svn_revision = android_version.get_svn_revision()
        stage2.debug_build = args.debug
        stage2.enable_assertions = args.enable_assertions
        stage2.lto = not args.no_lto
        stage2.build_instrumented = instrumented
        stage2.profdata_file = profdata if profdata else None

        libxml2_builder = builders.LibXml2Builder()
        libxml2_builder.build()
        stage2.libxml2 = libxml2_builder

        stage2.build_lldb = build_lldb
        if build_lldb:
            stage2.swig_executable = swig_builder.install_dir / 'bin' / 'swig'

            xz_builder = builders.XzBuilder()
            xz_builder.build()
            stage2.liblzma = xz_builder

            libncurses = builders.LibNcursesBuilder()
            libncurses.build()
            stage2.libncurses = libncurses

            libedit_builder = builders.LibEditBuilder()
            libedit_builder.libncurses = libncurses
            libedit_builder.build()
            stage2.libedit = libedit_builder

        stage2_tags = []
        # Annotate the version string if there is no profdata.
        if profdata is None:
            stage2_tags.append('NO PGO PROFILE')
        # Annotate the version string if this is an llvm-next build.
        if args.build_llvm_next:
            stage2_tags.append('ANDROID_LLVM_NEXT')
        stage2.build_tags = stage2_tags

        stage2.build()
        if not (stage2.build_instrumented or stage2.debug_build):
            set_default_toolchain(stage2.installed_toolchain)

        Builder.output_toolchain = stage2.installed_toolchain
        if hosts.build_host().is_linux and do_runtimes:
            build_runtimes(build_lldb_server=build_lldb)

    if need_windows:
        if args.windows_sdk:
            win_sdk.set_path(Path(args.windows_sdk))
        win_builder, win_lldb_bins = build_llvm_for_windows(
            enable_assertions=args.enable_assertions,
            build_name=args.build_name,
            build_lldb=build_lldb,
            swig_builder=swig_builder)

    if do_package and need_host:
        package_toolchain(stage2,
                          strip=do_strip_host_package,
                          create_tar=args.create_tar,
                          llvm_next=args.build_llvm_next)

    if do_package and need_windows:
        package_toolchain(win_builder,
                          necessary_bin_files=win_lldb_bins,
                          strip=do_strip,
                          create_tar=args.create_tar)

    return 0
Esempio n. 7
0
def main():
    args = parse_args()
    if args.skip_build:
        # Skips all builds
        BuilderRegistry.add_filter(lambda name: False)
    elif args.skip:
        BuilderRegistry.add_skips(args.skip)
    elif args.build:
        BuilderRegistry.add_builds(args.build)
    do_runtimes = not args.skip_runtimes
    do_package = not args.skip_package
    do_strip = not args.no_strip
    do_strip_host_package = do_strip and not args.debug

    # TODO (Pirama): Avoid using global statement
    global BUILD_LLDB, BUILD_LLVM_NEXT
    BUILD_LLDB = 'lldb' not in args.no_build
    BUILD_LLVM_NEXT = args.build_llvm_next

    need_host = hosts.build_host().is_darwin or ('linux' not in args.no_build)
    need_windows = hosts.build_host().is_linux and ('windows' not in args.no_build)

    log_levels = [logging.INFO, logging.DEBUG]
    verbosity = min(args.verbose, len(log_levels) - 1)
    log_level = log_levels[verbosity]
    logging.basicConfig(level=log_level)

    logger().info('do_build=%r do_stage1=%r do_stage2=%r do_runtimes=%r do_package=%r need_windows=%r' %
                  (not args.skip_build, BuilderRegistry.should_build('stage1'), BuilderRegistry.should_build('stage2'),
                  do_runtimes, do_package, need_windows))

    # Clone sources to be built and apply patches.
    source_manager.setup_sources(source_dir=utils.llvm_path(),
                                 build_llvm_next=args.build_llvm_next)

    # Build the stage1 Clang for the build host
    instrumented = hosts.build_host().is_linux and args.build_instrumented

    # Windows libs are built with stage1 toolchain. llvm-config is required.
    stage1_build_llvm_tools = instrumented or \
                              need_windows or \
                              args.debug

    stage1 = builders.Stage1Builder()
    stage1.build_name = args.build_name
    stage1.svn_revision = android_version.get_svn_revision(BUILD_LLVM_NEXT)
    stage1.build_llvm_tools = stage1_build_llvm_tools
    stage1.build_android_targets = args.debug or instrumented
    stage1.use_goma_for_stage1 = USE_GOMA_FOR_STAGE1
    stage1.build()
    stage1_toolchain = toolchains.get_toolchain_from_builder(stage1)
    toolchains.set_runtime_toolchain(stage1_toolchain)
    stage1_install = str(stage1.install_dir)

    if BUILD_LLDB:
        builders.SwigBuilder().build()
        if BuilderRegistry.should_build('stage2'):
            # libedit is not needed for windows lldb.
            builders.LibEditBuilder().build()

    if need_host:
        profdata_filename = pgo_profdata_filename()
        profdata = pgo_profdata_file(profdata_filename)
        # Do not use PGO profiles if profdata file doesn't exist unless failure
        # is explicitly requested via --check-pgo-profile.
        if profdata is None and args.check_pgo_profile:
            raise RuntimeError('Profdata file does not exist for ' +
                               profdata_filename)

        stage2 = builders.Stage2Builder()
        stage2.build_name = args.build_name
        stage2.svn_revision = android_version.get_svn_revision(BUILD_LLVM_NEXT)
        stage2.build_lldb = BUILD_LLDB
        stage2.debug_build = args.debug
        stage2.enable_assertions = args.enable_assertions
        stage2.lto = not args.no_lto
        stage2.build_instrumented = instrumented
        stage2.profdata_file = Path(profdata) if profdata else None

        # Annotate the version string if there is no profdata.
        if profdata is None:
            stage2.build_name += ', NO PGO PROFILE, '

        stage2.build()
        if not (stage2.build_instrumented or stage2.debug_build):
            stage2_toolchain = toolchains.get_toolchain_from_builder(stage2)
            toolchains.set_runtime_toolchain(stage2_toolchain)
        stage2_install = str(stage2.install_dir)

        if hosts.build_host().is_linux and do_runtimes:
            runtimes_toolchain = stage2_install
            if args.debug or instrumented:
                runtimes_toolchain = stage1_install
            build_runtimes(runtimes_toolchain, args)

    if need_windows:
        windows64_install = build_llvm_for_windows(
            enable_assertions=args.enable_assertions,
            build_name=args.build_name)

    dist_dir = ORIG_ENV.get('DIST_DIR', utils.out_path())
    if do_package and need_host:
        package_toolchain(
            stage2_install,
            args.build_name,
            hosts.build_host(),
            dist_dir,
            strip=do_strip_host_package)

    if do_package and need_windows:
        package_toolchain(
            windows64_install,
            args.build_name,
            hosts.Host.Windows,
            dist_dir,
            strip=do_strip)

    return 0
Esempio n. 8
0
def get_toolchain_by_name(name: str) -> Toolchain:
    """Tet a toolchain by name."""
    if name == 'prebuilt':
        return get_prebuilt_toolchain()
    return _get_toolchain_from_builder(BuilderRegistry.get(name))
Esempio n. 9
0
def get_runtime_toolchain() -> Toolchain:
    """Gets the toolchain used to build runtime."""
    builder = BuilderRegistry.get('stage2')
    if not builder or builder.build_instrumented or builder.debug_build:
        builder = BuilderRegistry.get('stage1')
    return _get_toolchain_from_builder(builder)