Skip to main content
Version: latest

toolchain

clang_build.toolchain

Module containing tool chaines used for compiling and linking.

Toolchain Objects​

class Toolchain()

generate_dependency_file​

@abstractmethod
def generate_dependency_file(source_file, dependency_file, flags, include_directories, is_c_target)

Generate a dependency file for a given source file.

If the dependency file is placed into a non-existing folder, this folder is generated before compilation.

Parameters​

source_file : pathlib.Path The source file to compile

dependency_file : pathlib.Path The dependency file to generate

flags : list of str List of flags to pass to the compiler

Returns​

bool True if the dependency file generation was successful, else False str Output of the compiler

compile​

@abstractmethod
def compile(source_file, object_file, include_directories, flags, is_c_target)

Compile a given source file into an object file.

If the object file is placed into a non-existing folder, this folder is generated before compilation.

Parameters​

source_file : pathlib.Path The source file to compile

object_file : pathlib.Path The object file to generate during compilation

flags : list of str List of flags to pass to the compiler

Returns​

bool True if the compilation was successful, else False str Output of the compiler

@abstractmethod
def link(object_files, output_file, flags, library_directories, libraries, is_library, is_c_target)

Link into the given output_file.

The command should contain all object files, library search paths and libraries against which to link. If the output_file is placed in a non-existing folder, the folder and all required parents are generated.

Parameters​

object_files : list of pathlib.Path Object files to link output_file : pathlib.Path The output file to generate flags : list of str Flags to pass to the linker library_directories : list of pathlib.Path Directories to search for libraries during linking libraries : list of pathlib.Path Libraries to link to is_library : bool If true, create a shared library. Else, create an executable.

Returns​

bool True if linking was successful, False otherwise str The output of the linker

archive​

@abstractmethod
def archive(object_files, output_file, flags)

Archive object files into a static library.

Parameters​

object_files : list of pathlib.Path Object files to put in a static library output_file : pathlib.Path The static library to create flags : list of str Flags to pass to the archiver

Returns​

bool True if archiving was successful, False otherwise str The output of the archiver

LLVM Objects​

class LLVM(Toolchain)

The LLVM toolchain: clang and clang++ compilers, etc.

This class abstracts away many features of the compiler and provides mildly generic compile, link and archive functions.

Attributes​

c_compiler : :any:pathlib.Path Path to the clang executable cpp_compiler : :any:pathlib.Path Path to the clang++ executable archiver : :any:pathlib.Path Path to the llvm-ar executable max_cpp_standard : str Compile flag for the latest supported C++ standard of the found compiler

__init__​

def __init__()

Search for clang and detect compiler features.

Raises​

RuntimeError If a compiler or linker tool wasn't found on the system.

dialect_exists​

@_lru_cache(maxsize=1)
def dialect_exists(year)

Check if a given dialect flag is valid.

Parameters​

year : int The last two digits of the dialect. For example 11 for C++11.

Returns​

bool True if the dialect for the given year is supported by clang.

generate_dependency_file​

def generate_dependency_file(source_file, dependency_file, flags, include_directories, is_c_target)

Generate a dependency file for a given source file.

If the dependency file is placed into a non-existing folder, this folder is generated before compilation.

Parameters​

source_file : pathlib.Path The source file to compile

dependency_file : pathlib.Path The dependency file to generate

flags : list of str List of flags to pass to the compiler

Returns​

bool True if the dependency file generation was successful, else False str Output of the compiler

compile​

def compile(source_file, object_file, include_directories, flags, is_c_target)

Compile a given source file into an object file.

If the object file is placed into a non-existing folder, this folder is generated before compilation.

Parameters​

source_file : pathlib.Path The source file to compile

object_file : pathlib.Path The object file to generate during compilation

flags : list of str List of flags to pass to the compiler

Returns​

bool True if the compilation was successful, else False str Output of the compiler