Esempio n. 1
0
async def select_gcc_c_toolchain(
        platform: Platform,
        native_toolchain: NativeToolchain) -> GCCCToolchain:
    provided_gcc = await Get[CCompiler](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.
        xcode_clang = await Get[CCompiler](XCodeCLITools,
                                           native_toolchain._xcode_cli_tools)
        joined_c_compiler = provided_gcc.sequence(xcode_clang)
    else:
        joined_c_compiler = provided_gcc

    # GCC needs an assembler, so we provide that (platform-specific) tool here.
    assembler = await Get[Assembler](NativeToolchain, native_toolchain)
    working_c_compiler = joined_c_compiler.sequence(assembler).prepend_field(
        'extra_args', [
            '-x',
            'c',
            '-std=c11',
        ])

    gcc_linker_wrapper = await Get[GCCLinker](NativeToolchain,
                                              native_toolchain)
    working_linker = gcc_linker_wrapper.for_compiler(working_c_compiler,
                                                     platform)

    return GCCCToolchain(CToolchain(working_c_compiler, working_linker))
Esempio n. 2
0
async def select_llvm_c_toolchain(
        platform: Platform,
        native_toolchain: NativeToolchain) -> LLVMCToolchain:
    provided_clang = await Get[CCompiler](LLVM, native_toolchain._llvm)

    if platform == Platform.darwin:
        xcode_clang = await Get[CCompiler](XCodeCLITools,
                                           native_toolchain._xcode_cli_tools)
        joined_c_compiler = provided_clang.sequence(xcode_clang)
    else:
        gcc_install = await Get[GCCInstallLocationForLLVM](
            GCC, native_toolchain._gcc)
        provided_gcc = await Get[CCompiler](GCC, native_toolchain._gcc)
        joined_c_compiler = (
            provided_clang.sequence(provided_gcc).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_gcc.runtime_library_dirs))

    working_c_compiler = joined_c_compiler.prepend_field(
        'extra_args', [
            '-x',
            'c',
            '-std=c11',
        ])

    llvm_linker_wrapper = await Get[LLVMLinker](NativeToolchain,
                                                native_toolchain)
    working_linker = llvm_linker_wrapper.for_compiler(working_c_compiler,
                                                      platform)

    return LLVMCToolchain(CToolchain(working_c_compiler, working_linker))
Esempio n. 3
0
def select_llvm_c_toolchain(platform, native_toolchain):
    provided_clang = yield Get(CCompiler, LLVM, native_toolchain._llvm)

    # These arguments are shared across platforms.
    llvm_c_compiler_args = [
        '-x',
        'c',
        '-std=c11',
        '-nobuiltininc',
    ]

    if platform.normalized_os_name == 'darwin':
        xcode_clang = yield Get(CCompiler, XCodeCLITools,
                                native_toolchain._xcode_cli_tools)
        working_c_compiler = CCompiler(
            path_entries=(provided_clang.path_entries +
                          xcode_clang.path_entries),
            exe_filename=provided_clang.exe_filename,
            library_dirs=(provided_clang.library_dirs +
                          xcode_clang.library_dirs),
            include_dirs=(provided_clang.include_dirs +
                          xcode_clang.include_dirs),
            extra_args=(llvm_c_compiler_args + xcode_clang.extra_args))
    else:
        gcc_install = yield Get(GCCInstallLocationForLLVM, GCC,
                                native_toolchain._gcc)
        provided_gcc = yield Get(CCompiler, GCC, native_toolchain._gcc)
        working_c_compiler = CCompiler(
            path_entries=provided_clang.path_entries,
            exe_filename=provided_clang.exe_filename,
            # We need g++'s version of the GLIBCXX library to be able to run, unfortunately.
            library_dirs=(provided_gcc.library_dirs +
                          provided_clang.library_dirs),
            include_dirs=provided_gcc.include_dirs,
            extra_args=(llvm_c_compiler_args + gcc_install.as_clang_argv))

    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=(base_linker.path_entries +
                      working_c_compiler.path_entries),
        exe_filename=working_c_compiler.exe_filename,
        library_dirs=(base_linker.library_dirs +
                      working_c_compiler.library_dirs),
        linking_library_dirs=(base_linker.linking_library_dirs +
                              libc_dev.get_libc_dirs(platform)),
        extra_args=base_linker.extra_args)

    yield LLVMCToolchain(CToolchain(working_c_compiler, working_linker))
Esempio n. 4
0
def select_llvm_c_toolchain(platform, native_toolchain):
    provided_clang = yield Get(CCompiler, LLVM, native_toolchain._llvm)

    # These arguments are shared across platforms.
    llvm_c_compiler_args = [
        '-x',
        'c',
        '-std=c11',
    ]

    if platform.normalized_os_name == 'darwin':
        xcode_clang = yield Get(CCompiler, XCodeCLITools,
                                native_toolchain._xcode_cli_tools)
        working_c_compiler = provided_clang.copy(
            path_entries=(provided_clang.path_entries +
                          xcode_clang.path_entries),
            library_dirs=(provided_clang.library_dirs +
                          xcode_clang.library_dirs),
            include_dirs=(provided_clang.include_dirs +
                          xcode_clang.include_dirs),
            extra_args=(provided_clang.extra_args + llvm_c_compiler_args +
                        xcode_clang.extra_args))
    else:
        gcc_install = yield Get(GCCInstallLocationForLLVM, GCC,
                                native_toolchain._gcc)
        provided_gcc = yield Get(CCompiler, GCC, native_toolchain._gcc)
        working_c_compiler = provided_clang.copy(
            # We need g++'s version of the GLIBCXX library to be able to run, unfortunately.
            library_dirs=(provided_gcc.library_dirs +
                          provided_clang.library_dirs),
            include_dirs=provided_gcc.include_dirs,
            extra_args=(llvm_c_compiler_args + provided_clang.extra_args +
                        gcc_install.as_clang_argv))

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

    # TODO(#6855): introduce a more concise way to express these compositions of executables.
    working_linker = llvm_linker.copy(
        path_entries=(llvm_linker.path_entries +
                      working_c_compiler.path_entries),
        exe_filename=working_c_compiler.exe_filename,
        library_dirs=(llvm_linker.library_dirs +
                      working_c_compiler.library_dirs),
    )

    yield LLVMCToolchain(CToolchain(working_c_compiler, working_linker))
Esempio n. 5
0
def select_gcc_c_toolchain(platform, native_toolchain):
    provided_gcc = yield Get(CCompiler, 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_clang = yield Get(CCompiler, XCodeCLITools,
                                native_toolchain._xcode_cli_tools)
        new_include_dirs = xcode_clang.include_dirs + provided_gcc.include_dirs
    else:
        new_include_dirs = provided_gcc.include_dirs

    working_c_compiler = CCompiler(path_entries=(provided_gcc.path_entries +
                                                 assembler.path_entries),
                                   exe_filename=provided_gcc.exe_filename,
                                   library_dirs=provided_gcc.library_dirs,
                                   include_dirs=new_include_dirs,
                                   extra_args=['-x', 'c', '-std=c11'])

    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_c_compiler.path_entries +
                      base_linker.path_entries),
        exe_filename=working_c_compiler.exe_filename,
        library_dirs=(base_linker.library_dirs +
                      working_c_compiler.library_dirs),
        linking_library_dirs=(base_linker.linking_library_dirs +
                              libc_dev.get_libc_dirs(platform)),
        extra_args=base_linker.extra_args)

    yield GCCCToolchain(CToolchain(working_c_compiler, working_linker))
Esempio n. 6
0
def select_gcc_c_toolchain(platform, native_toolchain):
    provided_gcc = yield Get(CCompiler, GCC, native_toolchain._gcc)

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

    gcc_c_compiler_args = [
        '-x',
        'c',
        '-std=c11',
    ]

    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.
        xcode_clang = yield Get(CCompiler, XCodeCLITools,
                                native_toolchain._xcode_cli_tools)
        new_include_dirs = provided_gcc.include_dirs + xcode_clang.include_dirs
    else:
        new_include_dirs = provided_gcc.include_dirs

    working_c_compiler = provided_gcc.copy(
        path_entries=(provided_gcc.path_entries + assembler.path_entries),
        include_dirs=new_include_dirs,
        extra_args=gcc_c_compiler_args)

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

    working_linker = gcc_linker.copy(
        path_entries=(working_c_compiler.path_entries +
                      gcc_linker.path_entries),
        exe_filename=working_c_compiler.exe_filename,
        library_dirs=(gcc_linker.library_dirs +
                      working_c_compiler.library_dirs),
    )

    yield GCCCToolchain(CToolchain(working_c_compiler, working_linker))