Exemple #1
0
def select_gcc_cpp_toolchain(
  platform: Platform, native_toolchain: NativeToolchain
) -> GCCCppToolchain:
  provided_gpp = yield Get(CppCompiler, GCC, native_toolchain._gcc)

  if platform == Platform.darwin:
    # GCC needs access to some headers that are only provided by the XCode toolchain
    # currently (e.g. "_stdio.h"). These headers are unlikely to change across versions, so this is
    # probably safe.
    # TODO: we should be providing all of these (so we can eventually phase out XCodeCLITools
    # entirely).
    xcode_clangpp = yield Get(CppCompiler, XCodeCLITools, native_toolchain._xcode_cli_tools)
    joined_cpp_compiler = provided_gpp.sequence(xcode_clangpp)
  else:
    joined_cpp_compiler = provided_gpp

  # GCC needs an assembler, so we provide that (platform-specific) tool here.
  assembler = yield Get(Assembler, NativeToolchain, native_toolchain)
  working_cpp_compiler = joined_cpp_compiler.sequence(assembler).prepend_field('extra_args', [
    '-x', 'c++', '-std=c++11',
    # This flag is intended to avoid using any of the headers from our LLVM distribution's C++
    # stdlib implementation, or any from the host system, and instead, use include dirs from the
    # XCodeCLITools or GCC.
    # TODO(#6143): Determine precisely what this flag does and why it's necessary.
    '-nostdinc++',
  ])

  gcc_linker_wrapper = yield Get(GCCLinker, NativeToolchain, native_toolchain)
  working_linker = gcc_linker_wrapper.for_compiler(working_cpp_compiler, platform)

  yield GCCCppToolchain(CppToolchain(working_cpp_compiler, working_linker))
def select_gcc_cpp_toolchain(platform, native_toolchain):
    provided_gpp = yield Get(CppCompiler, GCC, native_toolchain._gcc)

    # GCC needs an assembler, so we provide that (platform-specific) tool here.
    assembler = yield Get(Assembler, NativeToolchain, native_toolchain)

    gcc_cpp_compiler_args = [
        '-x',
        'c++',
        '-std=c++11',
        # This flag is intended to avoid using any of the headers from our LLVM distribution's C++
        # stdlib implementation, or any from the host system, and instead, use include dirs from the
        # XCodeCLITools or GCC.
        # TODO(#6143): Determine precisely what this flag does and why it's necessary.
        '-nostdinc++',
    ]

    if platform.normalized_os_name == 'darwin':
        # GCC needs access to some headers that are only provided by the XCode toolchain
        # currently (e.g. "_stdio.h"). These headers are unlikely to change across versions, so this is
        # probably safe.
        # TODO: we should be providing all of these (so we can eventually phase out XCodeCLITools
        # entirely).
        xcode_clangpp = yield Get(CppCompiler, XCodeCLITools,
                                  native_toolchain._xcode_cli_tools)
        working_cpp_compiler = provided_gpp.copy(
            path_entries=(provided_gpp.path_entries + assembler.path_entries),
            include_dirs=(provided_gpp.include_dirs +
                          xcode_clangpp.include_dirs),
            extra_args=(gcc_cpp_compiler_args + provided_gpp.extra_args +
                        xcode_clangpp.extra_args),
        )
        extra_linking_library_dirs = []
    else:
        provided_clangpp = yield Get(CppCompiler, LLVM, native_toolchain._llvm)
        working_cpp_compiler = provided_gpp.copy(
            path_entries=(provided_gpp.path_entries + assembler.path_entries),
            extra_args=(gcc_cpp_compiler_args + provided_gpp.extra_args),
        )
        extra_linking_library_dirs = provided_gpp.library_dirs + provided_clangpp.library_dirs

    gcc_linker_wrapper = yield Get(GCCLinker, NativeToolchain,
                                   native_toolchain)
    gcc_linker = gcc_linker_wrapper.linker

    working_linker = gcc_linker.copy(
        path_entries=(working_cpp_compiler.path_entries +
                      gcc_linker.path_entries),
        exe_filename=working_cpp_compiler.exe_filename,
        library_dirs=(gcc_linker.library_dirs +
                      working_cpp_compiler.library_dirs),
        linking_library_dirs=(gcc_linker.linking_library_dirs +
                              extra_linking_library_dirs),
    )

    yield GCCCppToolchain(CppToolchain(working_cpp_compiler, working_linker))
async def select_llvm_cpp_toolchain(
        platform: Platform,
        native_toolchain: NativeToolchain) -> LLVMCppToolchain:
    provided_clangpp = await Get[CppCompiler](LLVM, native_toolchain._llvm)

    # On OSX, we use the libc++ (LLVM) C++ standard library implementation. This is feature-complete
    # for OSX, but not for Linux (see https://libcxx.llvm.org/ for more info).
    if platform == Platform.darwin:
        xcode_clangpp = await Get[CppCompiler](
            XCodeCLITools, native_toolchain._xcode_cli_tools)
        joined_cpp_compiler = provided_clangpp.sequence(xcode_clangpp)
        extra_llvm_linking_library_dirs: Tuple[str, ...] = tuple()
        linker_extra_args: Tuple[str, ...] = tuple()
    else:
        gcc_install = await Get[GCCInstallLocationForLLVM](
            GCC, native_toolchain._gcc)
        provided_gpp = await Get[CppCompiler](GCC, native_toolchain._gcc)
        joined_cpp_compiler = (
            provided_clangpp.sequence(provided_gpp)
            # NB: we use g++'s headers on Linux, and therefore their C++ standard
            # library.
            .copy(include_dirs=provided_gpp.include_dirs).append_field(
                "extra_args", gcc_install.as_clang_argv)
            # We need g++'s version of the GLIBCXX library to be able to run.
            .prepend_field("runtime_library_dirs",
                           provided_gpp.runtime_library_dirs))
        extra_llvm_linking_library_dirs = (
            provided_gpp.runtime_library_dirs +
            provided_clangpp.runtime_library_dirs)
        # Ensure we use libstdc++, provided by g++, during the linking stage.
        linker_extra_args = ("-stdlib=libstdc++", )

    working_cpp_compiler = joined_cpp_compiler.prepend_field(
        "extra_args",
        [
            "-x",
            "c++",
            "-std=c++11",
            # This flag is intended to avoid using any of the headers from our LLVM distribution's C++
            # stdlib implementation, or any from the host system, and instead, use include dirs from the
            # XCodeCLITools or GCC.
            # TODO(#6143): Determine precisely what this flag does and why it's necessary.
            "-nostdinc++",
        ],
    )

    llvm_linker_wrapper = await Get[LLVMLinker](NativeToolchain,
                                                native_toolchain)
    working_linker = (
        llvm_linker_wrapper.for_compiler(working_cpp_compiler).append_field(
            "linking_library_dirs",
            extra_llvm_linking_library_dirs).prepend_field(
                "extra_args", linker_extra_args))

    return LLVMCppToolchain(CppToolchain(working_cpp_compiler, working_linker))
Exemple #4
0
def select_llvm_cpp_toolchain(platform, native_toolchain):
    provided_clangpp = yield Get(CppCompiler, LLVM, native_toolchain._llvm)

    # On OSX, we use the libc++ (LLVM) C++ standard library implementation. This is feature-complete
    # for OSX, but not for Linux (see https://libcxx.llvm.org/ for more info).
    if platform == Platform.darwin:
        xcode_clangpp = yield Get(CppCompiler, XCodeCLITools,
                                  native_toolchain._xcode_cli_tools)
        joined_cpp_compiler = provided_clangpp.sequence(xcode_clangpp)
        extra_llvm_linking_library_dirs = []
        linker_extra_args = []
    else:
        gcc_install = yield Get(GCCInstallLocationForLLVM, GCC,
                                native_toolchain._gcc)
        provided_gpp = yield Get(CppCompiler, GCC, native_toolchain._gcc)
        joined_cpp_compiler = (
            provided_clangpp.sequence(provided_gpp)
            # NB: we use g++'s headers on Linux, and therefore their C++ standard
            # library.
            .copy(include_dirs=provided_gpp.include_dirs).append_field(
                'extra_args', gcc_install.as_clang_argv)
            # We need g++'s version of the GLIBCXX library to be able to run.
            .prepend_field('runtime_library_dirs',
                           provided_gpp.runtime_library_dirs))
        extra_llvm_linking_library_dirs = provided_gpp.runtime_library_dirs + provided_clangpp.runtime_library_dirs
        # Ensure we use libstdc++, provided by g++, during the linking stage.
        linker_extra_args = ['-stdlib=libstdc++']

    working_cpp_compiler = joined_cpp_compiler.prepend_field(
        'extra_args',
        [
            '-x',
            'c++',
            '-std=c++11',
            # This flag is intended to avoid using any of the headers from our LLVM distribution's C++
            # stdlib implementation, or any from the host system, and instead, use include dirs from the
            # XCodeCLITools or GCC.
            # TODO(#6143): Determine precisely what this flag does and why it's necessary.
            '-nostdinc++',
        ])

    llvm_linker_wrapper = yield Get(LLVMLinker, NativeToolchain,
                                    native_toolchain)
    working_linker = (llvm_linker_wrapper.for_compiler(
        working_cpp_compiler,
        platform).append_field('linking_library_dirs',
                               extra_llvm_linking_library_dirs).prepend_field(
                                   'extra_args', linker_extra_args))

    yield LLVMCppToolchain(CppToolchain(working_cpp_compiler, working_linker))
Exemple #5
0
def select_gcc_cpp_toolchain(platform, native_toolchain):
    provided_gpp = yield Get(CppCompiler, GCC, native_toolchain._gcc)

    # GCC needs an assembler, so we provide that (platform-specific) tool here.
    assembler = yield Get(Assembler, NativeToolchain, native_toolchain)

    if platform.normalized_os_name == 'darwin':
        # GCC needs access to some headers that are only provided by the XCode toolchain
        # currently (e.g. "_stdio.h"). These headers are unlikely to change across versions, so this is
        # probably safe.
        # TODO: we should be providing all of these (so we can eventually phase out XCodeCLITools
        # entirely).
        xcode_clangpp = yield Get(CppCompiler, XCodeCLITools,
                                  native_toolchain._xcode_cli_tools)
        new_include_dirs = xcode_clangpp.include_dirs + provided_gpp.include_dirs
    else:
        new_include_dirs = provided_gpp.include_dirs

    working_cpp_compiler = CppCompiler(
        path_entries=(provided_gpp.path_entries + assembler.path_entries),
        exe_filename=provided_gpp.exe_filename,
        library_dirs=provided_gpp.library_dirs,
        include_dirs=new_include_dirs,
        extra_args=([
            '-x',
            'c++',
            '-std=c++11',
            '-nostdinc++',
        ]))

    base_linker_wrapper = yield Get(BaseLinker, NativeToolchain,
                                    native_toolchain)
    base_linker = base_linker_wrapper.linker
    libc_dev = yield Get(LibcDev, NativeToolchain, native_toolchain)
    working_linker = Linker(
        path_entries=(working_cpp_compiler.path_entries +
                      base_linker.path_entries),
        exe_filename=working_cpp_compiler.exe_filename,
        library_dirs=(base_linker.library_dirs +
                      working_cpp_compiler.library_dirs),
        linking_library_dirs=(base_linker.linking_library_dirs +
                              libc_dev.get_libc_dirs(platform)),
        extra_args=base_linker.extra_args)

    yield GCCCppToolchain(CppToolchain(working_cpp_compiler, working_linker))
Exemple #6
0
def select_llvm_cpp_toolchain(platform, native_toolchain):
    provided_clangpp = yield Get(CppCompiler, LLVM, native_toolchain._llvm)

    # These arguments are shared across platforms.
    llvm_cpp_compiler_args = [
        '-x',
        'c++',
        '-std=c++11',
        # This mean we don't use any of the headers from our LLVM distribution's C++ stdlib
        # implementation, or any from the host system. Instead, we use include dirs from the
        # XCodeCLITools or GCC.
        '-nobuiltininc',
        '-nostdinc++',
    ]

    if platform.normalized_os_name == 'darwin':
        xcode_clang = yield Get(CppCompiler, XCodeCLITools,
                                native_toolchain._xcode_cli_tools)
        working_cpp_compiler = CppCompiler(
            path_entries=(provided_clangpp.path_entries +
                          xcode_clang.path_entries),
            exe_filename=provided_clangpp.exe_filename,
            library_dirs=(provided_clangpp.library_dirs +
                          xcode_clang.library_dirs),
            include_dirs=(provided_clangpp.include_dirs +
                          xcode_clang.include_dirs),
            # On OSX, this uses the libc++ (LLVM) C++ standard library implementation. This is
            # feature-complete for OSX, but not for Linux (see https://libcxx.llvm.org/ for more info).
            extra_args=(llvm_cpp_compiler_args + xcode_clang.extra_args))
        linking_library_dirs = []
        linker_extra_args = []
    else:
        gcc_install = yield Get(GCCInstallLocationForLLVM, GCC,
                                native_toolchain._gcc)
        provided_gpp = yield Get(CppCompiler, GCC, native_toolchain._gcc)
        working_cpp_compiler = CppCompiler(
            path_entries=provided_clangpp.path_entries,
            exe_filename=provided_clangpp.exe_filename,
            # We need g++'s version of the GLIBCXX library to be able to run, unfortunately.
            library_dirs=(provided_gpp.library_dirs +
                          provided_clangpp.library_dirs),
            # NB: we use g++'s headers on Linux, and therefore their C++ standard library.
            include_dirs=provided_gpp.include_dirs,
            extra_args=(llvm_cpp_compiler_args + gcc_install.as_clang_argv))
        linking_library_dirs = provided_gpp.library_dirs + provided_clangpp.library_dirs
        # Ensure we use libstdc++, provided by g++, during the linking stage.
        linker_extra_args = ['-stdlib=libstdc++']

    libc_dev = yield Get(LibcDev, NativeToolchain, native_toolchain)
    base_linker_wrapper = yield Get(BaseLinker, NativeToolchain,
                                    native_toolchain)
    base_linker = base_linker_wrapper.linker
    working_linker = Linker(
        path_entries=(base_linker.path_entries +
                      working_cpp_compiler.path_entries),
        exe_filename=working_cpp_compiler.exe_filename,
        library_dirs=(base_linker.library_dirs +
                      working_cpp_compiler.library_dirs),
        linking_library_dirs=(base_linker.linking_library_dirs +
                              linking_library_dirs +
                              libc_dev.get_libc_dirs(platform)),
        extra_args=(base_linker.extra_args + linker_extra_args))

    yield LLVMCppToolchain(CppToolchain(working_cpp_compiler, working_linker))
def select_llvm_cpp_toolchain(platform, native_toolchain):
    provided_clangpp = yield Get(CppCompiler, LLVM, native_toolchain._llvm)

    # These arguments are shared across platforms.
    llvm_cpp_compiler_args = [
        '-x',
        'c++',
        '-std=c++11',
        # This flag is intended to avoid using any of the headers from our LLVM distribution's C++
        # stdlib implementation, or any from the host system, and instead, use include dirs from the
        # XCodeCLITools or GCC.
        # TODO(#6143): Determine precisely what this flag does and why it's necessary.
        '-nostdinc++',
    ]

    if platform.normalized_os_name == 'darwin':
        xcode_clangpp = yield Get(CppCompiler, XCodeCLITools,
                                  native_toolchain._xcode_cli_tools)
        working_cpp_compiler = provided_clangpp.copy(
            path_entries=(provided_clangpp.path_entries +
                          xcode_clangpp.path_entries),
            library_dirs=(provided_clangpp.library_dirs +
                          xcode_clangpp.library_dirs),
            include_dirs=(provided_clangpp.include_dirs +
                          xcode_clangpp.include_dirs),
            # On OSX, this uses the libc++ (LLVM) C++ standard library implementation. This is
            # feature-complete for OSX, but not for Linux (see https://libcxx.llvm.org/ for more info).
            extra_args=(llvm_cpp_compiler_args + provided_clangpp.extra_args +
                        xcode_clangpp.extra_args))
        extra_linking_library_dirs = []
        linker_extra_args = []
    else:
        gcc_install = yield Get(GCCInstallLocationForLLVM, GCC,
                                native_toolchain._gcc)
        provided_gpp = yield Get(CppCompiler, GCC, native_toolchain._gcc)
        working_cpp_compiler = provided_clangpp.copy(
            # We need g++'s version of the GLIBCXX library to be able to run, unfortunately.
            library_dirs=(provided_gpp.library_dirs +
                          provided_clangpp.library_dirs),
            # NB: we use g++'s headers on Linux, and therefore their C++ standard library.
            include_dirs=provided_gpp.include_dirs,
            extra_args=(llvm_cpp_compiler_args + provided_clangpp.extra_args +
                        gcc_install.as_clang_argv))
        # TODO(#6855): why are these necessary? this is very mysterious.
        extra_linking_library_dirs = provided_gpp.library_dirs + provided_clangpp.library_dirs
        # Ensure we use libstdc++, provided by g++, during the linking stage.
        linker_extra_args = ['-stdlib=libstdc++']

    llvm_linker_wrapper = yield Get(LLVMLinker, NativeToolchain,
                                    native_toolchain)
    llvm_linker = llvm_linker_wrapper.linker

    working_linker = llvm_linker.copy(
        path_entries=(llvm_linker.path_entries +
                      working_cpp_compiler.path_entries),
        exe_filename=working_cpp_compiler.exe_filename,
        library_dirs=(llvm_linker.library_dirs +
                      working_cpp_compiler.library_dirs),
        linking_library_dirs=(llvm_linker.linking_library_dirs +
                              extra_linking_library_dirs),
        extra_args=(llvm_linker.extra_args + linker_extra_args),
    )

    yield LLVMCppToolchain(CppToolchain(working_cpp_compiler, working_linker))