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
linkβ
@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