Toolchain#

toolchain.h#

class Toolchain : public buildcc::internal::FlagApi<Toolchain>, public buildcc::ToolchainFind<Toolchain>, public buildcc::ToolchainVerify<Toolchain>#

Subclassed by buildcc::Toolchain_custom, buildcc::Toolchain_gcc, buildcc::Toolchain_mingw, buildcc::Toolchain_msvc, MockToolchain

Public Functions

inline Toolchain(ToolchainId id, std::string_view name, const ToolchainExecutables &executables, const ToolchainConfig &config = ToolchainConfig())#
virtual ~Toolchain() = default#
Toolchain(Toolchain&&) = default#
Toolchain &operator=(Toolchain&&) = default#
Toolchain(const Toolchain&) = delete#
Toolchain &operator=(const Toolchain&) = delete#
inline ToolchainId GetId() const#
inline const std::string &GetName() const#
inline const std::string &GetAssembler() const#
inline const std::string &GetCCompiler() const#
inline const std::string &GetCppCompiler() const#
inline const std::string &GetArchiver() const#
inline const std::string &GetLinker() const#
inline const ToolchainExecutables &GetToolchainExecutables() const#
inline const ToolchainConfig &GetConfig() const#

Friends

friend class internal::FlagApi< Toolchain >
typedef Toolchain buildcc::BaseToolchain#

toolchain_find.h#

template<typename T>
class ToolchainFind#

Public Functions

std::vector<fs::path> Find(const ToolchainFindConfig &config = ToolchainFindConfig()) const#
struct ToolchainFindConfig#

Configure the behaviour of Toolchain::Find API. By default searches the directories mentioned in the ENV{PATH} variable to find the toolchain.

Param absolute_search_paths

absolute_search_paths expect directories that are iterated for exact toolchain matches

Param env_vars

env_vars contain paths that are seperated by OS delimiter. These are converted to paths and searched similarly to absolute_search_paths

NOTE: env_vars must contain single absolute paths or multiple absolute paths seperated by OS delimiter

Example: [Windows] “absolute_path_1;absolute_path_2;…”

Example: [Linux] “absolute_path_1:absolute_path_2:…”

Public Functions

inline ToolchainFindConfig(const std::vector<std::string> &env_vars = {"PATH"}, const std::vector<fs::path> &absolute_search_paths = {})#

Public Members

std::vector<std::string> env_vars#
std::vector<fs::path> absolute_search_paths#

toolchain_verify.h#

template<typename T>
class ToolchainVerify#

Public Functions

ToolchainVerify() = default#
ToolchainCompilerInfo Verify(const ToolchainFindConfig &config = ToolchainFindConfig())#

Verify your toolchain executables by searching your operating system paths Only add the verified path IF all toolchain executables are matched.

Parameters

config – Search paths to find toolchains

Returns

std::vector<VerifiedToolchain> Operating system can contain multiple toolchains of similar names with different versions. Collect all of them

void SetToolchainInfoCb(const ToolchainInfoCb &cb)#

Set ToolchainInfo callback for run time objects.

const ToolchainInfoCb &GetToolchainInfoCb() const#
struct ToolchainCompilerInfo#

Verified Toolchain information.

Param path

Absolute host path where ALL the toolchain executables are found

NOTE: All the

Toolchain executables must be found in a single folder.

Param compiler_version

Compiler version of the verified toolchain

Param target_arch

Target architecture of the verified toolchain

Public Functions

inline std::string ToString() const#

Public Members

fs::path path#
std::string compiler_version#
std::string target_arch#

Example for Default Toolchain#

 1BaseToolchain arm_gcc(ToolchainId::Gcc, "arm-none-eabi-gcc", "arm-none-eabi-as", "arm-none-eabi-gcc", "arm-none-eabi-g++", "arm-none-eabi-ar", "arm-none-eabi-ld");
 2
 3// Toolchain::Find is only used to return a list of paths where the ToolchainExecutables are found
 4// NOTE: All ToolchainExecutables must be found in a single directory for it to be present in the list
 5{
 6    ToolchainFindConfig find_config;
 7    // Modify it here if needed
 8    auto found_toolchains = arm_gcc.Find(find_config);
 9}
10
11// Runs Toolchain::Find
12// Selects first found toolchain (update ToolchainVerifyConfig if you want to select a different toolchain for verification)
13// Runs a pre-added ToolchainId::GCC verification function
14// If Verification Fails: Terminates the program
15// Else: Updates the arm_gcc ToolchainExecutables to the full path
16// i.e `arm-none-eabi-gcc` becomes `{host_absolute_path}/arm-none-eabi-gcc{host_executable_extension}`
17{
18    ToolchainVerifyConfig verify_config;
19    // Modify it here if needed
20    arm_gcc.Verify(verify_config);
21}

Example for Custom Toolchain#

 1BaseToolchain custom_toolchain(ToolchainId::Custom, "custom_new_toolchain", "assembler", "c_compiler", "cpp_compiler", "archiver", "linker");
 2
 3// Toolchain::Find similar to previous example
 4
 5// Find all the relevant toolchains on your host system
 6// Selects the first found toolchain
 7// Runs a verification function on the selected toolchain depending on the `ToolchainId`
 8Toolchain::AddVerificationFunc(ToolchainId::Custom,
 9[](const ToolchainExecutables & executables) -> buildcc::env::optional<ToolchainCompilerInfo> {
10    // Use executables to get compiler_version and target_arch
11    if (success) {
12        ToolchainCompilerInfo info;
13        info.compiler_version = "compiler_version";
14        info.target_arch = "target_arch";
15        return info;
16    } else {
17        return {};
18    }
19}, "custom_verification_func")
20
21ToolchainVerifyConfig verify_config;
22verify_config.verification_identifier = "custom_verification_func";
23custom_toolchain.Verify(verify_config);

Specialized Toolchain#

toolchain_gcc.h#

class Toolchain_gcc : public buildcc::Toolchain#

Generic GCC Toolchain id = ToolchainId::Gcc

name = “gcc”

asm_compiler = “as”

c_compiler = “gcc”

cpp_compiler = “g++”

archiver = “ar”

linker = “ld”

Public Functions

inline Toolchain_gcc(const std::string &name = "gcc", const env::optional<ToolchainExecutables> &op_executables = {}, const env::optional<ToolchainConfig> &op_config = {})#
virtual ~Toolchain_gcc() = default#
Toolchain_gcc(const Toolchain_gcc&) = delete#

toolchain_mingw.h#

class Toolchain_mingw : public buildcc::Toolchain#

Generic MinGW Toolchain id = ToolchainId::MinGW

name = “gcc”

asm_compiler = “as”

c_compiler = “gcc”

cpp_compiler = “g++”

archiver = “ar”

linker = “ld”

Public Functions

inline Toolchain_mingw(const std::string &name = "gcc", const env::optional<ToolchainExecutables> &op_executables = {}, const env::optional<ToolchainConfig> &op_config = {})#
virtual ~Toolchain_mingw() = default#
Toolchain_mingw(const Toolchain_mingw&) = delete#

toolchain_msvc.h#

class Toolchain_msvc : public buildcc::Toolchain#

Generic GCC Toolchain id = ToolchainId::Msvc

name = “msvc”

asm_compiler = “cl”

c_compiler = “cl”

cpp_compiler = “cl”

archiver = “lib”

linker = “link”

Public Functions

inline Toolchain_msvc(const std::string &name = "msvc", const env::optional<ToolchainExecutables> &op_executables = {}, const env::optional<ToolchainConfig> &op_config = {})#
virtual ~Toolchain_msvc() = default#
Toolchain_msvc(const Toolchain_msvc&) = delete#

Example#

1// Default GCC toolchain
2Toolchain_gcc gcc;
3
4// Default MinGW toolchain
5Toolchain_mingw mingw;
6
7// Default MSVC toolchain
8Toolchain_msvc msvc;