From d8e2392da0100029188e95c953f067b305845a9c Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 22:54:37 -0800 Subject: [PATCH 01/65] Updated tpl cb with TplConfig --- bootstrap/include/bootstrap/build_tpl.h | 8 +++++++- bootstrap/src/build_tpl.cpp | 13 ++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bootstrap/include/bootstrap/build_tpl.h b/bootstrap/include/bootstrap/build_tpl.h index 5ac24653..296892a2 100644 --- a/bootstrap/include/bootstrap/build_tpl.h +++ b/bootstrap/include/bootstrap/build_tpl.h @@ -21,7 +21,13 @@ namespace buildcc { -void tpl_cb(BaseTarget &target); +struct TplConfig { + TplConfig() = default; + + OsId os_id{OsId::Linux}; +}; + +void tpl_cb(BaseTarget &target, const TplConfig &config = TplConfig()); } // namespace buildcc diff --git a/bootstrap/src/build_tpl.cpp b/bootstrap/src/build_tpl.cpp index 5fbdf513..b212f2c7 100644 --- a/bootstrap/src/build_tpl.cpp +++ b/bootstrap/src/build_tpl.cpp @@ -18,15 +18,22 @@ namespace buildcc { -void tpl_cb(BaseTarget &target) { +void tpl_cb(BaseTarget &target, const TplConfig &config) { target.AddSource("process.cpp"); target.AddIncludeDir(""); target.AddHeader("process.hpp"); - if constexpr (env::is_win()) { + switch (config.os_id) { + case OsId::Win: target.AddSource("process_win.cpp"); - } else { + break; + case OsId::Linux: + case OsId::Unix: + case OsId::Mac: target.AddSource("process_unix.cpp"); + break; + default: + break; } target.Build(); From 5993275830a794a5e7ababa788cc24562a6f852c Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 22:54:43 -0800 Subject: [PATCH 02/65] Update main.buildcc.cpp --- bootstrap/main.buildcc.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index ee26e955..f671dcac 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -43,7 +43,6 @@ int main(int argc, char **argv) { BaseToolchain toolchain = custom_toolchain_arg.ConstructToolchain(); - PersistentStorage storage; BuildBuildCC buildcc( reg, toolchain, TargetEnv(env::get_project_root_dir(), env::get_project_build_dir())); From c7a119199225a2708439f014e181b1ea5ac95558 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 22:54:53 -0800 Subject: [PATCH 03/65] Update build_buildcc.cpp --- bootstrap/src/build_buildcc.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bootstrap/src/build_buildcc.cpp b/bootstrap/src/build_buildcc.cpp index ec40da1b..efe87e75 100644 --- a/bootstrap/src/build_buildcc.cpp +++ b/bootstrap/src/build_buildcc.cpp @@ -238,7 +238,9 @@ void BuildBuildCC::Setup(const ArgToolchainState &state) { "tiny-process-library", env_.GetTargetBuildDir())); reg_.CallbackIf(state, global_flags_cb, tpl_lib, toolchain_); - reg_.Build(state, tpl_cb, tpl_lib); + TplConfig tpl_config; + tpl_config.os_id = get_host_os(); + reg_.Build(state, tpl_cb, tpl_lib, tpl_config); // TODO, Make this a generic selection between StaticTarget and // DynamicTarget From 20317f0e6e44c72ffd38e8d3874cf601c6bb2889 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 22:54:57 -0800 Subject: [PATCH 04/65] Update build_cli11.cpp --- bootstrap/src/build_cli11.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/bootstrap/src/build_cli11.cpp b/bootstrap/src/build_cli11.cpp index fa900aa7..d464c7c4 100644 --- a/bootstrap/src/build_cli11.cpp +++ b/bootstrap/src/build_cli11.cpp @@ -21,7 +21,6 @@ namespace buildcc { void cli11_ho_cb(TargetInfo &info) { info.AddIncludeDir("include"); info.GlobHeaders("include/CLI"); - // TODO, Add PCH } } // namespace buildcc From d4082fb4bd953cfac1fb933527039a20cbcd4d91 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 22:55:11 -0800 Subject: [PATCH 05/65] Update build_flatbuffers.cpp --- bootstrap/src/build_flatbuffers.cpp | 47 ++++++++++------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/bootstrap/src/build_flatbuffers.cpp b/bootstrap/src/build_flatbuffers.cpp index 01039ae0..68c706d6 100644 --- a/bootstrap/src/build_flatbuffers.cpp +++ b/bootstrap/src/build_flatbuffers.cpp @@ -82,45 +82,30 @@ void build_flatc_exe_cb(BaseTarget &target) { kFlatcPreprocessorFlags.cend(), [&](const auto &f) { target.AddPreprocessorFlag(f); }); - if constexpr (env::is_win()) { - switch (target.GetToolchain().GetId()) { - case ToolchainId::Gcc: - case ToolchainId::MinGW: - std::for_each(kFlatcGccCppCompileFlags.cbegin(), - kFlatcGccCppCompileFlags.cend(), - [&](const auto &f) { target.AddCppCompileFlag(f); }); - break; - case ToolchainId::Msvc: - std::for_each(kFlatcMsvcCppCompileFlags.cbegin(), - kFlatcMsvcCppCompileFlags.cend(), - [&](const auto &f) { target.AddCppCompileFlag(f); }); - break; - default: - break; - } + switch (target.GetToolchain().GetId()) { + case ToolchainId::Gcc: + case ToolchainId::MinGW: + std::for_each(kFlatcGccCppCompileFlags.cbegin(), + kFlatcGccCppCompileFlags.cend(), + [&](const auto &f) { target.AddCppCompileFlag(f); }); + break; + case ToolchainId::Msvc: + std::for_each(kFlatcMsvcCppCompileFlags.cbegin(), + kFlatcMsvcCppCompileFlags.cend(), + [&](const auto &f) { target.AddCppCompileFlag(f); }); + break; + case ToolchainId::Clang: + break; + default: + break; } - if constexpr (env::is_linux()) { - switch (target.GetToolchain().GetId()) { - case ToolchainId::Gcc: - std::for_each(kFlatcGccCppCompileFlags.cbegin(), - kFlatcGccCppCompileFlags.cend(), - [&](const auto &f) { target.AddCppCompileFlag(f); }); - break; - default: - break; - } - } - - // TODO, Add PCH - target.Build(); } void flatbuffers_ho_cb(TargetInfo &info) { info.AddIncludeDir("include"); info.GlobHeaders("include/flatbuffers"); - // TODO, Add PCH } } // namespace buildcc From 789026d765b27028d018bbb39ce4489e9d23edeb Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 22:55:17 -0800 Subject: [PATCH 06/65] Update build_taskflow.cpp --- bootstrap/src/build_taskflow.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bootstrap/src/build_taskflow.cpp b/bootstrap/src/build_taskflow.cpp index 9d945194..ef206c8b 100644 --- a/bootstrap/src/build_taskflow.cpp +++ b/bootstrap/src/build_taskflow.cpp @@ -23,7 +23,13 @@ void taskflow_ho_cb(TargetInfo &info) { info.GlobHeaders("taskflow"); info.GlobHeaders("taskflow/core"); info.GlobHeaders("taskflow/core/algorithm"); - // TODO, Track more header files + info.GlobHeaders("taskflow/cuda"); + info.GlobHeaders("taskflow/cuda/cuda_algorithm"); + info.GlobHeaders("taskflow/dsl"); + info.GlobHeaders("taskflow/sanitizer"); + info.GlobHeaders("taskflow/sycl"); + info.GlobHeaders("taskflow/sycl/sycl_algorithm"); + info.GlobHeaders("taskflow/utility"); } } // namespace buildcc From 560b47f7f92f9d4fa06ce1fa7f89c64faed15dd7 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 22:55:38 -0800 Subject: [PATCH 07/65] Update host_os.h --- buildcc/lib/env/include/env/host_os.h | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/buildcc/lib/env/include/env/host_os.h b/buildcc/lib/env/include/env/host_os.h index 36a6c2fd..18740211 100644 --- a/buildcc/lib/env/include/env/host_os.h +++ b/buildcc/lib/env/include/env/host_os.h @@ -56,4 +56,37 @@ inline constexpr bool is_unix() { } // namespace buildcc::env +namespace buildcc { + +enum class OsId { + Linux, + Win, + Mac, + Unix, + Undefined, +}; + +inline constexpr OsId get_host_os() { + OsId os_id = OsId::Undefined; + if constexpr (env::is_linux()) { + os_id = OsId::Linux; + } + + if constexpr (env::is_unix()) { + os_id = OsId::Unix; + } + + if constexpr (env::is_win()) { + os_id = OsId::Win; + } + + if constexpr (env::is_mac()) { + os_id = OsId::Mac; + } + + return os_id; +} + +} // namespace buildcc + #endif From 333ac9358fe1f9cb062241a14bc0967e03a03282 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 22:57:33 -0800 Subject: [PATCH 08/65] Updated toolchain files to toolchain.host --- bootstrap/config/toolchain_linux_gcc.toml | 2 +- bootstrap/config/toolchain_win_gcc.toml | 2 +- bootstrap/config/toolchain_win_msvc.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bootstrap/config/toolchain_linux_gcc.toml b/bootstrap/config/toolchain_linux_gcc.toml index 6ac3dd34..89ce7d40 100644 --- a/bootstrap/config/toolchain_linux_gcc.toml +++ b/bootstrap/config/toolchain_linux_gcc.toml @@ -1,4 +1,4 @@ -[toolchain.custom] +[toolchain.host] build = true test = true diff --git a/bootstrap/config/toolchain_win_gcc.toml b/bootstrap/config/toolchain_win_gcc.toml index dfd67809..a5202c8c 100644 --- a/bootstrap/config/toolchain_win_gcc.toml +++ b/bootstrap/config/toolchain_win_gcc.toml @@ -1,4 +1,4 @@ -[toolchain.custom] +[toolchain.host] build = true test = true diff --git a/bootstrap/config/toolchain_win_msvc.toml b/bootstrap/config/toolchain_win_msvc.toml index f14f51e5..2fb80da5 100644 --- a/bootstrap/config/toolchain_win_msvc.toml +++ b/bootstrap/config/toolchain_win_msvc.toml @@ -1,4 +1,4 @@ -[toolchain.custom] +[toolchain.host] build = true test = true From 2407184bfe90319aa99ae52791f5a28e8c208f72 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 22:57:51 -0800 Subject: [PATCH 09/65] Update main.buildcc.cpp --- bootstrap/main.buildcc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index f671dcac..6104c73a 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -35,7 +35,7 @@ static void hybrid_simple_example_cb(BaseTarget &target, int main(int argc, char **argv) { Args args; ArgToolchain custom_toolchain_arg; - args.AddToolchain("custom", "Host Toolchain", custom_toolchain_arg); + args.AddToolchain("host", "Host Toolchain", custom_toolchain_arg); args.Parse(argc, argv); Register reg(args); From 1fab57dfc0873f8ed7c6abb65bb8293c33621383 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 22:58:23 -0800 Subject: [PATCH 10/65] Update buildexe.cpp --- buildexe/buildexe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildexe/buildexe.cpp b/buildexe/buildexe.cpp index 36738ead..3c5e183b 100644 --- a/buildexe/buildexe.cpp +++ b/buildexe/buildexe.cpp @@ -91,7 +91,7 @@ int main(int argc, char **argv) { Args args; ArgToolchain custom_toolchain_arg; - args.AddToolchain("custom", "Host Toolchain", custom_toolchain_arg); + args.AddToolchain("host", "Host Toolchain", custom_toolchain_arg); // TODO, Add Verification subcommand here for OS, Compiler etc! // os win, linux considerations From 7b22566a54f54fa2b7dfccddd1c9b80cc9d06898 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 23:02:05 -0800 Subject: [PATCH 11/65] Update target_generic.h --- .../targets/include/targets/target_generic.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/buildcc/targets/include/targets/target_generic.h b/buildcc/targets/include/targets/target_generic.h index efefb7a7..82c86a6a 100644 --- a/buildcc/targets/include/targets/target_generic.h +++ b/buildcc/targets/include/targets/target_generic.h @@ -21,9 +21,11 @@ #include #include "target/target.h" +#include "toolchain/toolchain.h" + #include "target_gcc.h" +#include "target_mingw.h" #include "target_msvc.h" -#include "toolchain/toolchain.h" namespace buildcc { @@ -139,8 +141,10 @@ class ExecutableTarget_generic : public BaseTarget { case ToolchainId::Msvc: Copy(ExecutableTarget_msvc(name, toolchain, env), kGenericCopyOptions); break; - case ToolchainId::Clang: case ToolchainId::MinGW: + Copy(ExecutableTarget_mingw(name, toolchain, env), kGenericCopyOptions); + break; + case ToolchainId::Clang: default: env::assert_fatal("Compiler ID not supported"); break; @@ -163,8 +167,10 @@ class StaticTarget_generic : public BaseTarget { case ToolchainId::Msvc: Copy(StaticTarget_msvc(name, toolchain, env), kGenericCopyOptions); break; - case ToolchainId::Clang: case ToolchainId::MinGW: + Copy(StaticTarget_mingw(name, toolchain, env), kGenericCopyOptions); + break; + case ToolchainId::Clang: default: env::assert_fatal("Compiler ID not supported"); break; @@ -186,8 +192,10 @@ class DynamicTarget_generic : public BaseTarget { case ToolchainId::Msvc: Copy(DynamicTarget_msvc(name, toolchain, env), kGenericCopyOptions); break; - case ToolchainId::Clang: case ToolchainId::MinGW: + Copy(DynamicTarget_mingw(name, toolchain, env), kGenericCopyOptions); + break; + case ToolchainId::Clang: default: env::assert_fatal("Compiler ID not supported"); break; @@ -208,7 +216,6 @@ class Target_generic : public BaseTarget { Copy(ExecutableTarget_generic(name, toolchain, env), kGenericCopyOptions); break; case TargetType::StaticLibrary: - Copy(StaticTarget_generic(name, toolchain, env), kGenericCopyOptions); break; case TargetType::DynamicLibrary: From d5ecc72d1fbcedf1ab01dc00af06d50c277be85e Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 23:02:15 -0800 Subject: [PATCH 12/65] Update target_generic.h --- buildcc/targets/include/targets/target_generic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildcc/targets/include/targets/target_generic.h b/buildcc/targets/include/targets/target_generic.h index 82c86a6a..14c14bee 100644 --- a/buildcc/targets/include/targets/target_generic.h +++ b/buildcc/targets/include/targets/target_generic.h @@ -1,5 +1,5 @@ /* - * Copyright 2021 Niket Naidu. All rights reserved. + * Copyright 2021-2022 Niket Naidu. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 701fea5a3db8a63f7f20287328dbedb12c834c3f Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 23:07:54 -0800 Subject: [PATCH 13/65] Updated Target_generic for Mingw --- buildcc/targets/include/targets/target_generic.h | 12 +++++++++--- buildcc/targets/include/targets/target_mingw.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/buildcc/targets/include/targets/target_generic.h b/buildcc/targets/include/targets/target_generic.h index 14c14bee..0d5d5ed0 100644 --- a/buildcc/targets/include/targets/target_generic.h +++ b/buildcc/targets/include/targets/target_generic.h @@ -78,8 +78,10 @@ class GenericConfig : ConfigInterface { case ToolchainId::Msvc: config = MsvcConfig::Executable(); break; - case ToolchainId::Clang: case ToolchainId::MinGW: + config = MingwConfig::Executable(); + break; + case ToolchainId::Clang: default: env::assert_fatal("Compiler ID not supported"); break; @@ -97,8 +99,10 @@ class GenericConfig : ConfigInterface { case ToolchainId::Msvc: config = MsvcConfig::StaticLib(); break; - case ToolchainId::Clang: case ToolchainId::MinGW: + config = MingwConfig::StaticLib(); + break; + case ToolchainId::Clang: default: env::assert_fatal("Compiler ID not supported"); break; @@ -116,8 +120,10 @@ class GenericConfig : ConfigInterface { case ToolchainId::Msvc: config = MsvcConfig::DynamicLib(); break; - case ToolchainId::Clang: case ToolchainId::MinGW: + config = MingwConfig::DynamicLib(); + break; + case ToolchainId::Clang: default: env::assert_fatal("Compiler ID not supported"); break; diff --git a/buildcc/targets/include/targets/target_mingw.h b/buildcc/targets/include/targets/target_mingw.h index f2326229..44f93720 100644 --- a/buildcc/targets/include/targets/target_mingw.h +++ b/buildcc/targets/include/targets/target_mingw.h @@ -41,6 +41,8 @@ class MingwConfig : ConfigInterface { kGccExecutableLinkCommand); } + static TargetConfig StaticLib() { return GccConfig::StaticLib(); } + static TargetConfig DynamicLib() { return DefaultMingwConfig(kMingwDynamicLibExt, kGccGenericCompileCommand, kMingwDynamicLibLinkCommand); From 5e0a98167f65e2d1a129aab60a5442420f9bb97a Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 23:09:27 -0800 Subject: [PATCH 14/65] Update toolchain_win_gcc.toml --- bootstrap/config/toolchain_win_gcc.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/config/toolchain_win_gcc.toml b/bootstrap/config/toolchain_win_gcc.toml index a5202c8c..d078e06f 100644 --- a/bootstrap/config/toolchain_win_gcc.toml +++ b/bootstrap/config/toolchain_win_gcc.toml @@ -2,7 +2,7 @@ build = true test = true -id = "gcc" +id = "mingw" name = "x86_64-w64-mingw32" asm_compiler = "as" c_compiler = "gcc" From cbe4370f7e571d33969f3a3be553510311acd864 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 23:11:16 -0800 Subject: [PATCH 15/65] Update args.cpp --- buildcc/lib/args/src/args.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/buildcc/lib/args/src/args.cpp b/buildcc/lib/args/src/args.cpp index 67a09998..a4642c01 100644 --- a/buildcc/lib/args/src/args.cpp +++ b/buildcc/lib/args/src/args.cpp @@ -77,11 +77,12 @@ const std::unordered_map kLogLevelMap{ const std::unordered_map kToolchainIdMap{ - {"gcc", buildcc::base::Toolchain::Id::Gcc}, - {"msvc", buildcc::base::Toolchain::Id::Msvc}, - {"clang", buildcc::base::Toolchain::Id::Clang}, - {"custom", buildcc::base::Toolchain::Id::Custom}, - {"undefined", buildcc::base::Toolchain::Id::Undefined}, + {"gcc", buildcc::ToolchainId::Gcc}, + {"msvc", buildcc::ToolchainId::Msvc}, + {"mingw", buildcc::ToolchainId::MinGW}, + {"clang", buildcc::ToolchainId::Clang}, + {"custom", buildcc::ToolchainId::Custom}, + {"undefined", buildcc::ToolchainId::Undefined}, }; } // namespace From 0c8dafee167f58a7b903ba8df694da83965dc34a Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 23:13:40 -0800 Subject: [PATCH 16/65] Update include_api.cpp --- buildcc/lib/target/src/api/include_api.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/buildcc/lib/target/src/api/include_api.cpp b/buildcc/lib/target/src/api/include_api.cpp index 2b66eb19..3b5de205 100644 --- a/buildcc/lib/target/src/api/include_api.cpp +++ b/buildcc/lib/target/src/api/include_api.cpp @@ -54,7 +54,6 @@ void IncludeApi::GlobHeadersAbsolute(const fs::path &absolute_path) { for (const auto &p : fs::directory_iterator(absolute_path)) { if (t.config_.IsValidHeader(p.path())) { - env::log_trace(__FUNCTION__, fmt::format("Added header {}", p.path())); AddHeaderAbsolute(p.path()); } } From f2da211a1a9714b2fb5b40fb5d8731d915b479a4 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 23:23:42 -0800 Subject: [PATCH 17/65] Update build_taskflow.cpp --- bootstrap/src/build_taskflow.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/bootstrap/src/build_taskflow.cpp b/bootstrap/src/build_taskflow.cpp index ef206c8b..22049ad3 100644 --- a/bootstrap/src/build_taskflow.cpp +++ b/bootstrap/src/build_taskflow.cpp @@ -26,7 +26,6 @@ void taskflow_ho_cb(TargetInfo &info) { info.GlobHeaders("taskflow/cuda"); info.GlobHeaders("taskflow/cuda/cuda_algorithm"); info.GlobHeaders("taskflow/dsl"); - info.GlobHeaders("taskflow/sanitizer"); info.GlobHeaders("taskflow/sycl"); info.GlobHeaders("taskflow/sycl/sycl_algorithm"); info.GlobHeaders("taskflow/utility"); From 65008e280a9e7213f45308ddba50b20eaf1047c0 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 23:31:27 -0800 Subject: [PATCH 18/65] Updated compiler with path --- buildcc/lib/target/src/target/build.cpp | 10 +++++----- .../lib/target/src/target/friend/compile_object.cpp | 2 +- buildcc/lib/target/src/target/friend/compile_pch.cpp | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/buildcc/lib/target/src/target/build.cpp b/buildcc/lib/target/src/target/build.cpp index 6fea12c9..ef9654a5 100644 --- a/buildcc/lib/target/src/target/build.cpp +++ b/buildcc/lib/target/src/target/build.cpp @@ -86,11 +86,11 @@ void Target::Build() { {kLinkFlags, internal::aggregate(GetLinkFlags())}, // Toolchain executables here - {kAsmCompiler, toolchain_.GetAsmCompiler()}, - {kCCompiler, toolchain_.GetCCompiler()}, - {kCppCompiler, toolchain_.GetCppCompiler()}, - {kArchiver, toolchain_.GetArchiver()}, - {kLinker, toolchain_.GetLinker()}, + {kAsmCompiler, fmt::format("{}", fs::path(toolchain_.GetAsmCompiler()))}, + {kCCompiler, fmt::format("{}", fs::path(toolchain_.GetCCompiler()))}, + {kCppCompiler, fmt::format("{}", fs::path(toolchain_.GetCppCompiler()))}, + {kArchiver, fmt::format("{}", fs::path(toolchain_.GetArchiver()))}, + {kLinker, fmt::format("{}", fs::path(toolchain_.GetLinker()))}, }); // Load the serialized file diff --git a/buildcc/lib/target/src/target/friend/compile_object.cpp b/buildcc/lib/target/src/target/friend/compile_object.cpp index 2f001993..fe6b74ae 100644 --- a/buildcc/lib/target/src/target/friend/compile_object.cpp +++ b/buildcc/lib/target/src/target/friend/compile_object.cpp @@ -50,7 +50,7 @@ void CompileObject::CacheCompileCommands() { const std::string selected_aggregated_compile_flags = target_.SelectCompileFlags(type).value_or(""); const std::string selected_compiler = - target_.SelectCompiler(type).value_or(""); + fmt::format("{}", fs::path(target_.SelectCompiler(type).value_or(""))); object_iter.second.command = target_.command_.Construct( target_.GetConfig().compile_command, { diff --git a/buildcc/lib/target/src/target/friend/compile_pch.cpp b/buildcc/lib/target/src/target/friend/compile_pch.cpp index 4914e856..23767692 100644 --- a/buildcc/lib/target/src/target/friend/compile_pch.cpp +++ b/buildcc/lib/target/src/target/friend/compile_pch.cpp @@ -136,9 +136,10 @@ fs::path CompilePch::ConstructObjectPath() const { } std::string CompilePch::ConstructCompileCommand() const { - const std::string compiler = target_.GetState().contains_cpp - ? target_.GetToolchain().GetCppCompiler() - : target_.GetToolchain().GetCCompiler(); + std::string compiler = target_.GetState().contains_cpp + ? target_.GetToolchain().GetCppCompiler() + : target_.GetToolchain().GetCCompiler(); + compiler = fmt::format("{}", fs::path(compiler)); const TargetFileExt file_ext_type = target_.GetState().contains_cpp ? TargetFileExt::Cpp : TargetFileExt::C; const std::string compile_flags = From 127974b16ae1ea4e85613e201e0ea6e97ee96dc8 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 4 Jan 2022 23:31:47 -0800 Subject: [PATCH 19/65] Update buildexe.cpp --- buildexe/buildexe.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/buildexe/buildexe.cpp b/buildexe/buildexe.cpp index 3c5e183b..3e9d062a 100644 --- a/buildexe/buildexe.cpp +++ b/buildexe/buildexe.cpp @@ -185,7 +185,6 @@ int main(int argc, char **argv) { SyncOption::ExternalLibDeps, }); switch (toolchain.GetId()) { - case ToolchainId::Gcc: case ToolchainId::MinGW: user_output_target.AddLinkFlag("-Wl,--allow-multiple-definition"); break; From 108eedac699e16607a5cc31e622901e8ae2190fb Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 01:37:15 -0800 Subject: [PATCH 20/65] Update toc.rst --- docs/source/intro/toc.rst | 68 +++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/docs/source/intro/toc.rst b/docs/source/intro/toc.rst index 91dc0d21..7e0e4511 100644 --- a/docs/source/intro/toc.rst +++ b/docs/source/intro/toc.rst @@ -1,17 +1,73 @@ Introduction ============= -Aim/Purpose/Usecase --------------------- +Aim +---- -Definitions ------------- +BuildCC aims to be an alternative to Makefiles while using the feature rich C++ language instead of a custom DSL. Features ---------- -Community Help ---------------- +* Complete flexibility for custom workflows and toolchains +* C++ language feature benefits and debuggable build binaries +* Optimized rebuilds through serialization. See target.fbs schema + * Can optimize for rebuilds by comparing the previous stored build with current build. + * Also see the FAQ for more details on Serialization +* Customizable for community plugins. + +Pre-requisites +-------------- + +* Technical Knowledge + * C++03 classes and template usage +* C++17 Compiler with + * C++17 filesystem library support + * C++11 thread library support +* Third Party Libraries (See License below) + * Flatbuffers v2.0.0 + * Taskflow v3.1.0 + * CLI11 v2.1.0 + * Tiny Process Library v2.0.4 + * fmt v8.0.1 + * spdlog v1.9.2 + * CppUTest v4.0 + +General Information +------------------- + +* A one stage **input / output** procedure is called a **Generator** with a wide variety of use cases + * Single input creates single output + * Single input creates multiple outputs + * Multiple inputs create single output + * Multiple inputs creates multiple outputs +* A two stage **compile** and **link** procedure is called a **Target** + * This means that Executables, StaticLibraries and DynamicLibraries are all categorized as Targets + * In the future C++20 modules can also be its own target depending on compiler implementations +* Every Target requires a complementary (and compatible) **Toolchain** + * This ensures that cross compiling is very easy and explicit in nature. + * Multiple toolchains can be `mixed` in a single build file i.e we can generate targets using the GCC, Clang, MSVC and many other compilers **simultaneously**. +* The **compile_command** (pch and object commands) and **link_command** (target command) is fed to the **process** call to invoke the **Toolchain**. +* Each **Target** can depend on other targets efficiently through Parallel Programming using **Taskflow**. + * Dependency between targets is explicitly mentioned through the Taskflow APIs + * This has been made easier for the user through the ``buildcc::Register`` module. +* Build files can be customized through command line arguments + * Command line arguments can be stored in configurable ``.toml`` files and passed using the ``--config`` flag. + * Users can define their own custom arguments. + * Argument passing has been made easy using the ``buildcc::Args`` module. Licenses --------- + +`BuildCC` is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text. `BuildCC` aims to use open-source libraries containing permissive licenses. + +> Developers who would like to suggest an alternative library, raise an issue with the **license** and **advantages** clearly outlined. + +* [Fmtlib](https://github.com/fmtlib/fmt) (Formatting) [MIT License] [Header Only] +* [Spdlog](https://github.com/gabime/spdlog) (Logging) [MIT License] [Header Only] +* [Tiny Process Library](https://gitlab.com/eidheim/tiny-process-library) (Process handling) [MIT License] +* [Taskflow](https://github.com/taskflow/taskflow) (Parallel Programming) [MIT License] [Header Only] + * See also [3rd-Party](https://github.com/taskflow/taskflow/tree/master/3rd-party) used by Taskflow +* [Flatbuffers](https://github.com/google/flatbuffers) (Serialization) [Apache-2.0 License] [Header Only] +* [CLI11](https://github.com/CLIUtils/CLI11) (Argument Parsing) [BSD-3-Clause License] [Header Only] +* [CppUTest](https://github.com/cpputest/cpputest) (Unit Testing/Mocking) [BSD-3-Clause License] From bf8dd26ab96c1b15c44b63edc5d041258ad18f74 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 01:41:31 -0800 Subject: [PATCH 21/65] Update toc.rst --- docs/source/intro/toc.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/source/intro/toc.rst b/docs/source/intro/toc.rst index 7e0e4511..9a74265c 100644 --- a/docs/source/intro/toc.rst +++ b/docs/source/intro/toc.rst @@ -59,15 +59,15 @@ General Information Licenses --------- -`BuildCC` is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text. `BuildCC` aims to use open-source libraries containing permissive licenses. +`BuildCC` is licensed under the Apache License, Version 2.0. See **LICENSE** for the full license text. `BuildCC` aims to use open-source libraries containing permissive licenses. -> Developers who would like to suggest an alternative library, raise an issue with the **license** and **advantages** clearly outlined. +.. note:: Developers who would like to suggest an alternative library, raise an issue with the **license** and **advantages** clearly outlined. -* [Fmtlib](https://github.com/fmtlib/fmt) (Formatting) [MIT License] [Header Only] -* [Spdlog](https://github.com/gabime/spdlog) (Logging) [MIT License] [Header Only] -* [Tiny Process Library](https://gitlab.com/eidheim/tiny-process-library) (Process handling) [MIT License] -* [Taskflow](https://github.com/taskflow/taskflow) (Parallel Programming) [MIT License] [Header Only] - * See also [3rd-Party](https://github.com/taskflow/taskflow/tree/master/3rd-party) used by Taskflow -* [Flatbuffers](https://github.com/google/flatbuffers) (Serialization) [Apache-2.0 License] [Header Only] -* [CLI11](https://github.com/CLIUtils/CLI11) (Argument Parsing) [BSD-3-Clause License] [Header Only] -* [CppUTest](https://github.com/cpputest/cpputest) (Unit Testing/Mocking) [BSD-3-Clause License] +* `Fmtlib `_ (Formatting) [MIT License] [Header Only] +* `Spdlog `_ (Logging) [MIT License] [Header Only] +* `Tiny Process Library `_ (Process handling) [MIT License] +* `Taskflow `_ (Parallel Programming) [MIT License] [Header Only] + * See also `3rd-Party `_ used by Taskflow +* `Flatbuffers `_ (Serialization) [Apache-2.0 License] [Header Only] +* `CLI11 `_ (Argument Parsing) [BSD-3-Clause License] [Header Only] +* `CppUTest `_ (Unit Testing/Mocking) [BSD-3-Clause License] From 6ecec2cb3ee92c6850e1165b3c3f3edab1d484f2 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 01:48:19 -0800 Subject: [PATCH 22/65] Update toc.rst --- docs/source/intro/toc.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/intro/toc.rst b/docs/source/intro/toc.rst index 9a74265c..3e2b01f5 100644 --- a/docs/source/intro/toc.rst +++ b/docs/source/intro/toc.rst @@ -11,9 +11,9 @@ Features * Complete flexibility for custom workflows and toolchains * C++ language feature benefits and debuggable build binaries -* Optimized rebuilds through serialization. See target.fbs schema +* Optimized rebuilds through serialization. * Can optimize for rebuilds by comparing the previous stored build with current build. - * Also see the FAQ for more details on Serialization + * Further details given in **Architecture** * Customizable for community plugins. Pre-requisites From 423e14c0db6fa7dd974e283a37e43adedf260674 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 20:31:03 -0800 Subject: [PATCH 23/65] Create setup.rst --- docs/source/getting_started/setup.rst | 86 +++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 docs/source/getting_started/setup.rst diff --git a/docs/source/getting_started/setup.rst b/docs/source/getting_started/setup.rst new file mode 100644 index 00000000..44834f46 --- /dev/null +++ b/docs/source/getting_started/setup.rst @@ -0,0 +1,86 @@ +Setup +======== + +ENV[BUILDCC_HOME] +----------------- + +* Add the environment variable ``BUILDCC_HOME`` with the absolute path on the operating system. For example: ``BUILDCC_HOME=C:\buildcc`` or ``BUILDCC_HOME=/local/mnt/buildcc`` +* Create directories **bin**, **extensions**, **libs** and **host** inside your ENV[BUILDCC_HOME] directory + * Download **BuildExe_Win.zip** or **BuildExe_Linux.zip** and unzip the bin file contents into the **bin** folder + * **extensions** and **libs** folder will be empty for the time being +* Update your ``PATH`` variable with the **bin** folder. + * For example: ``PATH += ENV[BUILDCC_HOME]/bin;ENV[PATH]`` + * Linux : ``export PATH="$BUILDCC_HOME/bin:$PATH"`` + * Windows : My Computer -> Properties -> Advanced System Settings -> Environment Variables -> [Update your system variables] + +* Git clone the buildcc project in the ENV[BUILDCC_HOME] directory. + +.. code-block:: bash + + git clone https://github.com/coder137/build_in_cpp.git buildcc + git submodule init + git submodule update + +* To update just do the following + +.. code-block:: bash + + git pull + git submodule init + git submodule update + +* Your ENV[BUILDCC_HOME] directory should look like the following + +.. uml:: + + @startmindmap + * ENV[BUILDCC_HOME] + ** bin + *** flatc + *** buildexe + ** buildcc + *** [git cloned] + ** extensions + *** [empty] + ** libs + *** [empty] + ** host + *** [empty] + @endmindmap + +Host Toolchains +------------------ + +From the above map we can see that the **host** folder is empty + +This folder will contain the .toml files of all the HOST toolchains present on your system. + +.. code-block:: toml + :linenos: + + [toolchain.host] + # Toolchain family id + # valid options are: gcc, msvc, mingw + # clang is not yet supported + id = "gcc" + + # NOTE: Each name MUST be unique + # Preferrably use the [id]_[target_arch]_[compiler_version] for uniqueness, + # but make sure the name is unique if you have multiple similar host toolchains installed on your system + name = "gcc_x86_64-linux-gnu_9.3.0" + + # Make sure all of these executables are present when you install your toolchain + asm_compiler = "as" + c_compiler = "gcc" + cpp_compiler = "g++" + archiver = "ar" + linker = "ld" + + # Additional information + # Necessary if multiple similar toolchains are installed + # For example. Installed gcc version 9.3.0 and 10.2.0 + path = "/usr/bin" + compiler_version = "9.3.0" + target_arch = "x86_64-linux-gnu" + +.. important:: For **Windows**, make sure to use ``vcvarsall.bat [flavour]`` to activate your toolchain From 76d6790642d50e79be79a238b2c0d8923c88bf03 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 20:31:06 -0800 Subject: [PATCH 24/65] Update toc.rst --- docs/source/getting_started/toc.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/source/getting_started/toc.rst b/docs/source/getting_started/toc.rst index 1d5daef4..29055442 100644 --- a/docs/source/getting_started/toc.rst +++ b/docs/source/getting_started/toc.rst @@ -1,14 +1,17 @@ Getting Started ================= -Pre-requisites ----------------- +.. toctree:: -Installation and Setup ------------------------ + setup + +Usage through BuildExe +---------------------- + +Usage through CMake +------------------- Walkthroughs ------------- .. note:: Add walkthroughs and example snippets of increasing complexity - From 6e9497f98dc766e965270a49783c260beab9708a Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 20:35:38 -0800 Subject: [PATCH 25/65] Update setup.rst --- docs/source/getting_started/setup.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/source/getting_started/setup.rst b/docs/source/getting_started/setup.rst index 44834f46..64907294 100644 --- a/docs/source/getting_started/setup.rst +++ b/docs/source/getting_started/setup.rst @@ -84,3 +84,24 @@ This folder will contain the .toml files of all the HOST toolchains present on y target_arch = "x86_64-linux-gnu" .. important:: For **Windows**, make sure to use ``vcvarsall.bat [flavour]`` to activate your toolchain + +* Your ENV[BUILDCC_HOME] directory should look like the following + +.. uml:: + + @startmindmap + * ENV[BUILDCC_HOME] + ** bin + *** flatc + *** buildexe + ** buildcc + *** [git cloned] + ** extensions + *** [empty] + ** libs + *** [empty] + ** host + *** gcc_x86_64-linux-gnu_9.3.0.toml + *** mingw_x86_64-w64-mingw32_10.2.0.toml + *** msvc_am64_19.29.30137.toml + @endmindmap From 17d7d43012d4f02f6ff4db48ecda4ad8e425c197 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 22:21:25 -0800 Subject: [PATCH 26/65] Update build_buildcc.cpp --- bootstrap/src/build_buildcc.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bootstrap/src/build_buildcc.cpp b/bootstrap/src/build_buildcc.cpp index efe87e75..76bf48a9 100644 --- a/bootstrap/src/build_buildcc.cpp +++ b/bootstrap/src/build_buildcc.cpp @@ -54,8 +54,10 @@ void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen, target.GlobHeaders("lib/env/include/env"); // TOOLCHAIN + target.GlobSources("lib/toolchain/src/api"); target.AddIncludeDir("lib/toolchain/include"); target.GlobHeaders("lib/toolchain/include/toolchain"); + target.GlobHeaders("lib/toolchain/include/toolchain/api"); // TARGET target.GlobSources("lib/target/src/common"); From 262368b518eece8c88abc345bd7ab611dd2e3b4a Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 22:57:34 -0800 Subject: [PATCH 27/65] Segregated args for buildexe to args_setup.h/.cpp --- buildexe/CMakeLists.txt | 4 ++ buildexe/buildexe.cpp | 96 +++----------------------- buildexe/include/buildexe/args_setup.h | 53 ++++++++++++++ buildexe/src/args_setup.cpp | 59 ++++++++++++++++ 4 files changed, 124 insertions(+), 88 deletions(-) create mode 100644 buildexe/include/buildexe/args_setup.h create mode 100644 buildexe/src/args_setup.cpp diff --git a/buildexe/CMakeLists.txt b/buildexe/CMakeLists.txt index 9e1f9ea2..0afcfb8e 100644 --- a/buildexe/CMakeLists.txt +++ b/buildexe/CMakeLists.txt @@ -1,5 +1,8 @@ add_executable(buildexe buildexe.cpp + + src/args_setup.cpp + include/buildexe/args_setup.h ) target_sources(buildexe PRIVATE ../bootstrap/src/build_buildcc.cpp @@ -11,6 +14,7 @@ target_sources(buildexe PRIVATE ../bootstrap/src/build_tpl.cpp ) target_include_directories(buildexe PRIVATE + include ../bootstrap/include ) target_link_libraries(buildexe PRIVATE buildcc) diff --git a/buildexe/buildexe.cpp b/buildexe/buildexe.cpp index 3e9d062a..d0e1fbd7 100644 --- a/buildexe/buildexe.cpp +++ b/buildexe/buildexe.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2021 Niket Naidu. All rights reserved. + * Copyright 2021-2022 Niket Naidu. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ #include "buildcc.h" +#include "buildexe/args_setup.h" + #include "bootstrap/build_buildcc.h" #include "bootstrap/build_cli11.h" #include "bootstrap/build_flatbuffers.h" @@ -33,40 +35,6 @@ enum class BuildExeMode { Script, }; -struct ArgTargetInfo { - std::string name; - TargetType type; - fs::path relative_to_root; -}; - -struct ArgTargetInputs { - // Sources - std::vector source_files; - std::vector include_dirs; - - // External libs - std::vector lib_dirs; - std::vector external_lib_deps; - - // Flags - std::vector preprocessor_flags; - std::vector common_compile_flags; - std::vector asm_compile_flags; - std::vector c_compile_flags; - std::vector cpp_compile_flags; - std::vector link_flags; -}; - -struct ArgScriptInfo { - std::vector configs; -}; - -static const std::unordered_map kTargetTypeMap{ - {"executable", TargetType::Executable}, - {"staticLibrary", TargetType::StaticLibrary}, - {"dynamicLibrary", TargetType::DynamicLibrary}, -}; - static const std::unordered_map kBuildExeModeMap{ {"immediate", BuildExeMode::Immediate}, {"script", BuildExeMode::Script}, @@ -74,10 +42,6 @@ static const std::unordered_map kBuildExeModeMap{ static void clean_cb(); -static void setup_arg_target_info(Args &args, ArgTargetInfo &out); -static void setup_arg_target_inputs(Args &args, ArgTargetInputs &out); -static void setup_arg_script_mode(Args &args, ArgScriptInfo &out); - static void host_toolchain_verify(const BaseToolchain &toolchain); static fs::path get_env_buildcc_home(); @@ -151,9 +115,6 @@ int main(int argc, char **argv) { counter++; } - // TODO, Update Toolchain with VerifiedToolchain - // toolchain.UpdateFrom(verified_toolchain); - if (mode == BuildExeMode::Script) { host_toolchain_verify(toolchain); } @@ -204,6 +165,9 @@ int main(int argc, char **argv) { // Runners reg.RunBuild(); + env::log_info(kTag, fmt::format("************** Running '{}' **************", + out_targetinfo.name)); + // Run if (mode == BuildExeMode::Script) { std::vector configs; @@ -235,52 +199,6 @@ static void clean_cb() { fs::remove_all(env::get_project_build_dir()); } -// TODO, Add subcommand [build.info] -static void setup_arg_target_info(Args &args, ArgTargetInfo &out) { - auto &app = args.Ref(); - - app.add_option("--name", out.name, "Provide Target name")->required(); - - app.add_option("--type", out.type, "Provide Target Type") - ->transform(CLI::CheckedTransformer(kTargetTypeMap, CLI::ignore_case)) - ->required(); - - app.add_option("--relative_to_root", out.relative_to_root, - "Provide Target relative to root") - ->required(); -} - -// TODO, Add subcommand [build.inputs] -// TODO, Add group, group by sources, headers, inncludes on CLI -static void setup_arg_target_inputs(Args &args, ArgTargetInputs &out) { - auto &app = args.Ref(); - - app.add_option("--srcs", out.source_files, "Provide source files"); - app.add_option("--includes", out.include_dirs, "Provide include dirs"); - - app.add_option("--lib_dirs", out.lib_dirs, "Provide lib dirs"); - app.add_option("--external_libs", out.external_lib_deps, - "Provide external libs"); - - app.add_option("--preprocessor_flags", out.preprocessor_flags, - "Provide Preprocessor flags"); - app.add_option("--common_compile_flags", out.common_compile_flags, - "Provide CommonCompile Flags"); - app.add_option("--asm_compile_flags", out.asm_compile_flags, - "Provide AsmCompile Flags"); - app.add_option("--c_compile_flags", out.c_compile_flags, - "Provide CCompile Flags"); - app.add_option("--cpp_compile_flags", out.cpp_compile_flags, - "Provide CppCompile Flags"); - app.add_option("--link_flags", out.link_flags, "Provide Link Flags"); -} - -static void setup_arg_script_mode(Args &args, ArgScriptInfo &out) { - auto *script_args = args.Ref().add_subcommand("script"); - script_args->add_option("--configs", out.configs, - "Config files for script mode"); -} - static void host_toolchain_verify(const BaseToolchain &toolchain) { env::log_info(kTag, "*** Starting Toolchain verification ***"); @@ -294,8 +212,10 @@ static void host_toolchain_verify(const BaseToolchain &toolchain) { namespace fs = std::filesystem; int main() { + std::cout << "********************" << std::endl; std::cout << "Verifying host toolchain" << std::endl; std::cout << "Current Path: " << fs::current_path() << std::endl; + std::cout << "********************" << std::endl; return 0; })"; env::save_file(path_as_string(file).c_str(), file_data, false); diff --git a/buildexe/include/buildexe/args_setup.h b/buildexe/include/buildexe/args_setup.h new file mode 100644 index 00000000..4f61f821 --- /dev/null +++ b/buildexe/include/buildexe/args_setup.h @@ -0,0 +1,53 @@ +/* + * Copyright 2021-2022 Niket Naidu. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "buildcc.h" + +namespace buildcc { + +struct ArgTargetInfo { + std::string name; + TargetType type; + fs::path relative_to_root; +}; + +struct ArgTargetInputs { + // Sources + std::vector source_files; + std::vector include_dirs; + + // External libs + std::vector lib_dirs; + std::vector external_lib_deps; + + // Flags + std::vector preprocessor_flags; + std::vector common_compile_flags; + std::vector asm_compile_flags; + std::vector c_compile_flags; + std::vector cpp_compile_flags; + std::vector link_flags; +}; + +struct ArgScriptInfo { + std::vector configs; +}; + +void setup_arg_target_info(Args &args, ArgTargetInfo &out); +void setup_arg_target_inputs(Args &args, ArgTargetInputs &out); +void setup_arg_script_mode(Args &args, ArgScriptInfo &out); + +} // namespace buildcc diff --git a/buildexe/src/args_setup.cpp b/buildexe/src/args_setup.cpp new file mode 100644 index 00000000..ce164f53 --- /dev/null +++ b/buildexe/src/args_setup.cpp @@ -0,0 +1,59 @@ + + +#include "buildexe/args_setup.h" + +namespace buildcc { + +static const std::unordered_map kTargetTypeMap{ + {"executable", TargetType::Executable}, + {"staticLibrary", TargetType::StaticLibrary}, + {"dynamicLibrary", TargetType::DynamicLibrary}, +}; + +// TODO, Add subcommand [build.info] +void setup_arg_target_info(Args &args, ArgTargetInfo &out) { + auto &app = args.Ref(); + + app.add_option("--name", out.name, "Provide Target name")->required(); + + app.add_option("--type", out.type, "Provide Target Type") + ->transform(CLI::CheckedTransformer(kTargetTypeMap, CLI::ignore_case)) + ->required(); + + app.add_option("--relative_to_root", out.relative_to_root, + "Provide Target relative to root") + ->required(); +} + +// TODO, Add subcommand [build.inputs] +// TODO, Add group, group by sources, headers, inncludes on CLI +void setup_arg_target_inputs(Args &args, ArgTargetInputs &out) { + auto &app = args.Ref(); + + app.add_option("--srcs", out.source_files, "Provide source files"); + app.add_option("--includes", out.include_dirs, "Provide include dirs"); + + app.add_option("--lib_dirs", out.lib_dirs, "Provide lib dirs"); + app.add_option("--external_libs", out.external_lib_deps, + "Provide external libs"); + + app.add_option("--preprocessor_flags", out.preprocessor_flags, + "Provide Preprocessor flags"); + app.add_option("--common_compile_flags", out.common_compile_flags, + "Provide CommonCompile Flags"); + app.add_option("--asm_compile_flags", out.asm_compile_flags, + "Provide AsmCompile Flags"); + app.add_option("--c_compile_flags", out.c_compile_flags, + "Provide CCompile Flags"); + app.add_option("--cpp_compile_flags", out.cpp_compile_flags, + "Provide CppCompile Flags"); + app.add_option("--link_flags", out.link_flags, "Provide Link Flags"); +} + +void setup_arg_script_mode(Args &args, ArgScriptInfo &out) { + auto *script_args = args.Ref().add_subcommand("script"); + script_args->add_option("--configs", out.configs, + "Config files for script mode"); +} + +} // namespace buildcc From ea7fa20bafbf2fea663065c68a36d11cd5be1298 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 22:57:55 -0800 Subject: [PATCH 28/65] Update args_setup.cpp --- buildexe/src/args_setup.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/buildexe/src/args_setup.cpp b/buildexe/src/args_setup.cpp index ce164f53..ad1f2244 100644 --- a/buildexe/src/args_setup.cpp +++ b/buildexe/src/args_setup.cpp @@ -1,4 +1,18 @@ - +/* + * Copyright 2021-2022 Niket Naidu. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include "buildexe/args_setup.h" From 801d78fed05e9d6ac76f41919ac561aa397267b3 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 23:02:36 -0800 Subject: [PATCH 29/65] Segregated buildexe toolchain to toolchain_setup.h/.cpp --- buildexe/CMakeLists.txt | 3 + buildexe/buildexe.cpp | 58 +---------------- buildexe/include/buildexe/toolchain_setup.h | 23 +++++++ buildexe/src/toolchain_setup.cpp | 69 +++++++++++++++++++++ 4 files changed, 98 insertions(+), 55 deletions(-) create mode 100644 buildexe/include/buildexe/toolchain_setup.h create mode 100644 buildexe/src/toolchain_setup.cpp diff --git a/buildexe/CMakeLists.txt b/buildexe/CMakeLists.txt index 0afcfb8e..34e1b6ca 100644 --- a/buildexe/CMakeLists.txt +++ b/buildexe/CMakeLists.txt @@ -3,6 +3,9 @@ add_executable(buildexe src/args_setup.cpp include/buildexe/args_setup.h + + src/toolchain_setup.cpp + include/buildexe/toolchain_setup.h ) target_sources(buildexe PRIVATE ../bootstrap/src/build_buildcc.cpp diff --git a/buildexe/buildexe.cpp b/buildexe/buildexe.cpp index d0e1fbd7..b82164a1 100644 --- a/buildexe/buildexe.cpp +++ b/buildexe/buildexe.cpp @@ -17,6 +17,7 @@ #include "buildcc.h" #include "buildexe/args_setup.h" +#include "buildexe/toolchain_setup.h" #include "bootstrap/build_buildcc.h" #include "bootstrap/build_cli11.h" @@ -42,8 +43,6 @@ static const std::unordered_map kBuildExeModeMap{ static void clean_cb(); -static void host_toolchain_verify(const BaseToolchain &toolchain); - static fs::path get_env_buildcc_home(); static void user_output_target_cb(BaseTarget &target, @@ -116,7 +115,9 @@ int main(int argc, char **argv) { } if (mode == BuildExeMode::Script) { + env::log_info(kTag, "*** Starting Toolchain verification ***"); host_toolchain_verify(toolchain); + env::log_info(kTag, "*** Toolchain verification done ***"); } PersistentStorage storage; @@ -199,59 +200,6 @@ static void clean_cb() { fs::remove_all(env::get_project_build_dir()); } -static void host_toolchain_verify(const BaseToolchain &toolchain) { - env::log_info(kTag, "*** Starting Toolchain verification ***"); - - fs::path file = env::get_project_build_dir() / "verify_host_toolchain" / - "verify_host_toolchain.cpp"; - fs::create_directories(file.parent_path()); - std::string file_data = R"(// Generated by BuildExe -#include -#include - -namespace fs = std::filesystem; - -int main() { - std::cout << "********************" << std::endl; - std::cout << "Verifying host toolchain" << std::endl; - std::cout << "Current Path: " << fs::current_path() << std::endl; - std::cout << "********************" << std::endl; - return 0; -})"; - env::save_file(path_as_string(file).c_str(), file_data, false); - - ExecutableTarget_generic target( - "verify", toolchain, TargetEnv(file.parent_path(), file.parent_path())); - - target.AddSource(file); - switch (toolchain.GetId()) { - case ToolchainId::Gcc: - case ToolchainId::MinGW: - target.AddCppCompileFlag("-std=c++17"); - break; - case ToolchainId::Msvc: - target.AddCppCompileFlag("/std:c++17"); - break; - default: - env::assert_fatal("Invalid Compiler Id"); - } - target.Build(); - - // Build - tf::Executor executor; - executor.run(target.GetTaskflow()); - executor.wait_for_all(); - env::assert_fatal(env::get_task_state() == env::TaskState::SUCCESS, - "Input toolchain could not compile host program. " - "Requires HOST toolchain"); - - // Run - bool execute = env::Command::Execute(fmt::format( - "{executable}", fmt::arg("executable", target.GetTargetPath().string()))); - env::assert_fatal(execute, "Could not execute verification target"); - env::log_info(kTag, "*** Toolchain verification done ***"); -} - static fs::path get_env_buildcc_home() { const char *buildcc_home = getenv("BUILDCC_HOME"); env::assert_fatal(buildcc_home != nullptr, diff --git a/buildexe/include/buildexe/toolchain_setup.h b/buildexe/include/buildexe/toolchain_setup.h new file mode 100644 index 00000000..a0ad8bc7 --- /dev/null +++ b/buildexe/include/buildexe/toolchain_setup.h @@ -0,0 +1,23 @@ +/* + * Copyright 2021-2022 Niket Naidu. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "buildcc.h" + +namespace buildcc { + +void host_toolchain_verify(const BaseToolchain &toolchain); + +} diff --git a/buildexe/src/toolchain_setup.cpp b/buildexe/src/toolchain_setup.cpp new file mode 100644 index 00000000..460d4613 --- /dev/null +++ b/buildexe/src/toolchain_setup.cpp @@ -0,0 +1,69 @@ +/* + * Copyright 2021-2022 Niket Naidu. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace buildcc { + +void host_toolchain_verify(const BaseToolchain &toolchain) { + fs::path file = env::get_project_build_dir() / "verify_host_toolchain" / + "verify_host_toolchain.cpp"; + fs::create_directories(file.parent_path()); + std::string file_data = R"(// Generated by BuildExe +#include +#include + +namespace fs = std::filesystem; + +int main() { + std::cout << "********************" << std::endl; + std::cout << "Verifying host toolchain" << std::endl; + std::cout << "Current Path: " << fs::current_path() << std::endl; + std::cout << "********************" << std::endl; + return 0; +})"; + env::save_file(path_as_string(file).c_str(), file_data, false); + + ExecutableTarget_generic target( + "verify", toolchain, TargetEnv(file.parent_path(), file.parent_path())); + + target.AddSource(file); + switch (toolchain.GetId()) { + case ToolchainId::Gcc: + case ToolchainId::MinGW: + target.AddCppCompileFlag("-std=c++17"); + break; + case ToolchainId::Msvc: + target.AddCppCompileFlag("/std:c++17"); + break; + default: + env::assert_fatal("Invalid Compiler Id"); + } + target.Build(); + + // Build + tf::Executor executor; + executor.run(target.GetTaskflow()); + executor.wait_for_all(); + env::assert_fatal(env::get_task_state() == env::TaskState::SUCCESS, + "Input toolchain could not compile host program. " + "Requires HOST toolchain"); + + // Run + bool execute = env::Command::Execute(fmt::format( + "{executable}", fmt::arg("executable", target.GetTargetPath().string()))); + env::assert_fatal(execute, "Could not execute verification target"); +} + +} // namespace buildcc From 8004e5a4d2d41905fc2b61cdf2568a7aca95c7d9 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 23:07:53 -0800 Subject: [PATCH 30/65] Shifted buildexe_mode to args_setup.h/.cpp --- buildexe/buildexe.cpp | 40 ++++++++------------------ buildexe/include/buildexe/args_setup.h | 6 ++++ buildexe/src/args_setup.cpp | 12 ++++++++ 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/buildexe/buildexe.cpp b/buildexe/buildexe.cpp index b82164a1..d21f46e3 100644 --- a/buildexe/buildexe.cpp +++ b/buildexe/buildexe.cpp @@ -31,16 +31,6 @@ using namespace buildcc; constexpr const char *const kTag = "BuildExe"; -enum class BuildExeMode { - Immediate, - Script, -}; - -static const std::unordered_map kBuildExeModeMap{ - {"immediate", BuildExeMode::Immediate}, - {"script", BuildExeMode::Script}, -}; - static void clean_cb(); static fs::path get_env_buildcc_home(); @@ -49,23 +39,14 @@ static void user_output_target_cb(BaseTarget &target, const ArgTargetInputs &inputs); // TODO, Add BuildExeMode::Script usage -// TODO, Refactor magic strings int main(int argc, char **argv) { Args args; ArgToolchain custom_toolchain_arg; args.AddToolchain("host", "Host Toolchain", custom_toolchain_arg); - // TODO, Add Verification subcommand here for OS, Compiler etc! - // os win, linux considerations - // compiler gcc, msvc considerations - // arch considerations - - BuildExeMode mode; - args.Ref() - .add_option("--mode", mode, "Provide BuildExe run mode") - ->transform(CLI::CheckedTransformer(kBuildExeModeMap, CLI::ignore_case)) - ->required(); + BuildExeMode out_mode; + setup_arg_buildexe_mode(args, out_mode); ArgTargetInfo out_targetinfo; setup_arg_target_info(args, out_targetinfo); @@ -76,14 +57,17 @@ int main(int argc, char **argv) { ArgScriptInfo out_scriptinfo; setup_arg_script_mode(args, out_scriptinfo); - // script mode specific arguments + args.Parse(argc, argv); + + // TODO, Add Verification subcommand here for OS, Compiler etc! + // os win, linux considerations + // compiler gcc, msvc considerations + // arch considerations // TODO, Add buildcc (git cloned) // TODO, Add libraries (git cloned) // TODO, Add extension (git cloned) - args.Parse(argc, argv); - Register reg(args); reg.Clean(clean_cb); @@ -114,7 +98,7 @@ int main(int argc, char **argv) { counter++; } - if (mode == BuildExeMode::Script) { + if (out_mode == BuildExeMode::Script) { env::log_info(kTag, "*** Starting Toolchain verification ***"); host_toolchain_verify(toolchain); env::log_info(kTag, "*** Toolchain verification done ***"); @@ -124,7 +108,7 @@ int main(int argc, char **argv) { Target_generic user_output_target(out_targetinfo.name, out_targetinfo.type, toolchain, TargetEnv(out_targetinfo.relative_to_root)); - if (mode == BuildExeMode::Script) { + if (out_mode == BuildExeMode::Script) { // Compile buildcc using the constructed toolchain fs::path buildcc_home = get_env_buildcc_home(); auto &buildcc_package = storage.Add( @@ -158,7 +142,7 @@ int main(int argc, char **argv) { reg.Build(custom_toolchain_arg.state, user_output_target_cb, user_output_target, out_targetinputs); - if (mode == BuildExeMode::Script) { + if (out_mode == BuildExeMode::Script) { auto &buildcc_package = storage.Ref("BuildccPackage"); reg.Dep(user_output_target, buildcc_package.GetBuildcc()); } @@ -170,7 +154,7 @@ int main(int argc, char **argv) { out_targetinfo.name)); // Run - if (mode == BuildExeMode::Script) { + if (out_mode == BuildExeMode::Script) { std::vector configs; for (const auto &c : out_scriptinfo.configs) { std::string config = fmt::format("--config {}", c); diff --git a/buildexe/include/buildexe/args_setup.h b/buildexe/include/buildexe/args_setup.h index 4f61f821..a20a43f7 100644 --- a/buildexe/include/buildexe/args_setup.h +++ b/buildexe/include/buildexe/args_setup.h @@ -18,6 +18,11 @@ namespace buildcc { +enum class BuildExeMode { + Immediate, + Script, +}; + struct ArgTargetInfo { std::string name; TargetType type; @@ -46,6 +51,7 @@ struct ArgScriptInfo { std::vector configs; }; +void setup_arg_buildexe_mode(Args &args, BuildExeMode &out); void setup_arg_target_info(Args &args, ArgTargetInfo &out); void setup_arg_target_inputs(Args &args, ArgTargetInputs &out); void setup_arg_script_mode(Args &args, ArgScriptInfo &out); diff --git a/buildexe/src/args_setup.cpp b/buildexe/src/args_setup.cpp index ad1f2244..4c175e4f 100644 --- a/buildexe/src/args_setup.cpp +++ b/buildexe/src/args_setup.cpp @@ -18,12 +18,24 @@ namespace buildcc { +static const std::unordered_map kBuildExeModeMap{ + {"immediate", BuildExeMode::Immediate}, + {"script", BuildExeMode::Script}, +}; + static const std::unordered_map kTargetTypeMap{ {"executable", TargetType::Executable}, {"staticLibrary", TargetType::StaticLibrary}, {"dynamicLibrary", TargetType::DynamicLibrary}, }; +void setup_arg_buildexe_mode(Args &args, BuildExeMode &out) { + args.Ref() + .add_option("--mode", out, "Provide BuildExe run mode") + ->transform(CLI::CheckedTransformer(kBuildExeModeMap, CLI::ignore_case)) + ->required(); +} + // TODO, Add subcommand [build.info] void setup_arg_target_info(Args &args, ArgTargetInfo &out) { auto &app = args.Ref(); From 2fb53ee2ae91dd29d27b9c2c8519f8223a0a026c Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 23:08:39 -0800 Subject: [PATCH 31/65] Update buildexe.cpp --- buildexe/buildexe.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/buildexe/buildexe.cpp b/buildexe/buildexe.cpp index d21f46e3..6bf3faff 100644 --- a/buildexe/buildexe.cpp +++ b/buildexe/buildexe.cpp @@ -42,8 +42,8 @@ static void user_output_target_cb(BaseTarget &target, int main(int argc, char **argv) { Args args; - ArgToolchain custom_toolchain_arg; - args.AddToolchain("host", "Host Toolchain", custom_toolchain_arg); + ArgToolchain host_toolchain_arg; + args.AddToolchain("host", "Host Toolchain", host_toolchain_arg); BuildExeMode out_mode; setup_arg_buildexe_mode(args, out_mode); @@ -72,9 +72,9 @@ int main(int argc, char **argv) { reg.Clean(clean_cb); // Build - BaseToolchain toolchain = custom_toolchain_arg.ConstructToolchain(); + BaseToolchain toolchain = host_toolchain_arg.ConstructToolchain(); - // BaseToolchain toolchain = custom_toolchain_arg.ConstructToolchain(); + // BaseToolchain toolchain = host_toolchain_arg.ConstructToolchain(); auto verified_toolchains = toolchain.Verify(); env::assert_fatal(!verified_toolchains.empty(), "Toolchain could not be verified. Please input correct " @@ -115,7 +115,7 @@ int main(int argc, char **argv) { "BuildccPackage", reg, toolchain, TargetEnv(buildcc_home / "buildcc", buildcc_home / "buildcc" / "_build_exe")); - buildcc_package.Setup(custom_toolchain_arg.state); + buildcc_package.Setup(host_toolchain_arg.state); // Add buildcc as a dependency to user_output_target user_output_target.AddLibDep(buildcc_package.GetBuildcc()); @@ -139,8 +139,8 @@ int main(int argc, char **argv) { } } - reg.Build(custom_toolchain_arg.state, user_output_target_cb, - user_output_target, out_targetinputs); + reg.Build(host_toolchain_arg.state, user_output_target_cb, user_output_target, + out_targetinputs); if (out_mode == BuildExeMode::Script) { auto &buildcc_package = storage.Ref("BuildccPackage"); From 58169be6b4b22e36a99c954516ebd97f704af3c5 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 23:15:07 -0800 Subject: [PATCH 32/65] Added find_toolchain_verify --- buildexe/buildexe.cpp | 28 +---------------- buildexe/include/buildexe/toolchain_setup.h | 3 +- buildexe/src/toolchain_setup.cpp | 35 +++++++++++++++++++++ 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/buildexe/buildexe.cpp b/buildexe/buildexe.cpp index 6bf3faff..98fce005 100644 --- a/buildexe/buildexe.cpp +++ b/buildexe/buildexe.cpp @@ -73,35 +73,9 @@ int main(int argc, char **argv) { // Build BaseToolchain toolchain = host_toolchain_arg.ConstructToolchain(); - - // BaseToolchain toolchain = host_toolchain_arg.ConstructToolchain(); - auto verified_toolchains = toolchain.Verify(); - env::assert_fatal(!verified_toolchains.empty(), - "Toolchain could not be verified. Please input correct " - "Gcc, Msvc, Clang or MinGW toolchain executable names"); - if (verified_toolchains.size() > 1) { - env::log_info( - kTag, - fmt::format( - "Found {} toolchains. By default using the first added" - "toolchain. Modify your environment `PATH` information if you " - "would like compiler precedence when similar compilers are " - "detected in different folders", - verified_toolchains.size())); - } - - // Print - int counter = 1; - for (const auto &vt : verified_toolchains) { - std::string info = fmt::format("{}. : {}", counter, vt.ToString()); - env::log_info("Host Toolchain", info); - counter++; - } - + find_toolchain_verify(toolchain); if (out_mode == BuildExeMode::Script) { - env::log_info(kTag, "*** Starting Toolchain verification ***"); host_toolchain_verify(toolchain); - env::log_info(kTag, "*** Toolchain verification done ***"); } PersistentStorage storage; diff --git a/buildexe/include/buildexe/toolchain_setup.h b/buildexe/include/buildexe/toolchain_setup.h index a0ad8bc7..98683610 100644 --- a/buildexe/include/buildexe/toolchain_setup.h +++ b/buildexe/include/buildexe/toolchain_setup.h @@ -18,6 +18,7 @@ namespace buildcc { +void find_toolchain_verify(BaseToolchain &toolchain); void host_toolchain_verify(const BaseToolchain &toolchain); -} +} // namespace buildcc diff --git a/buildexe/src/toolchain_setup.cpp b/buildexe/src/toolchain_setup.cpp index 460d4613..e9bfe0e1 100644 --- a/buildexe/src/toolchain_setup.cpp +++ b/buildexe/src/toolchain_setup.cpp @@ -14,9 +14,42 @@ * limitations under the License. */ +namespace { + +constexpr const char *const kTag = "BuildExe"; + +} + namespace buildcc { +void find_toolchain_verify(BaseToolchain &toolchain) { + auto verified_toolchains = toolchain.Verify(); + env::assert_fatal(!verified_toolchains.empty(), + "Toolchain could not be verified. Please input correct " + "Gcc, Msvc, Clang or MinGW toolchain executable names"); + if (verified_toolchains.size() > 1) { + env::log_info( + kTag, + fmt::format( + "Found {} toolchains. By default using the first added" + "toolchain. Modify your environment `PATH` information if you " + "would like compiler precedence when similar compilers are " + "detected in different folders", + verified_toolchains.size())); + } + + // Print + int counter = 1; + for (const auto &vt : verified_toolchains) { + std::string info = fmt::format("{}. : {}", counter, vt.ToString()); + env::log_info("Host Toolchain", info); + counter++; + } +} + void host_toolchain_verify(const BaseToolchain &toolchain) { + env::log_info(kTag, "*** Starting Toolchain verification ***"); + fs::path file = env::get_project_build_dir() / "verify_host_toolchain" / "verify_host_toolchain.cpp"; fs::create_directories(file.parent_path()); @@ -64,6 +97,8 @@ int main() { bool execute = env::Command::Execute(fmt::format( "{executable}", fmt::arg("executable", target.GetTargetPath().string()))); env::assert_fatal(execute, "Could not execute verification target"); + + env::log_info(kTag, "*** Toolchain verification done ***"); } } // namespace buildcc From 77117b09ed6f4ec0dc24f4d8d274635c2f9de677 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 23:24:13 -0800 Subject: [PATCH 33/65] Update buildexe.cpp --- buildexe/buildexe.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/buildexe/buildexe.cpp b/buildexe/buildexe.cpp index 98fce005..4f95422c 100644 --- a/buildexe/buildexe.cpp +++ b/buildexe/buildexe.cpp @@ -113,7 +113,9 @@ int main(int argc, char **argv) { } } - reg.Build(host_toolchain_arg.state, user_output_target_cb, user_output_target, + ArgToolchainState user_output_state; + user_output_state.build = true; + reg.Build(user_output_state, user_output_target_cb, user_output_target, out_targetinputs); if (out_mode == BuildExeMode::Script) { From 82dc2d62c799962826233d9419a6d983127ed326 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 5 Jan 2022 23:29:37 -0800 Subject: [PATCH 34/65] Added ifdefs --- buildexe/include/buildexe/args_setup.h | 5 +++++ buildexe/include/buildexe/toolchain_setup.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/buildexe/include/buildexe/args_setup.h b/buildexe/include/buildexe/args_setup.h index a20a43f7..d511a116 100644 --- a/buildexe/include/buildexe/args_setup.h +++ b/buildexe/include/buildexe/args_setup.h @@ -14,6 +14,9 @@ * limitations under the License. */ +#ifndef BUILDEXE_ARGS_SETUP_H_ +#define BUILDEXE_ARGS_SETUP_H_ + #include "buildcc.h" namespace buildcc { @@ -57,3 +60,5 @@ void setup_arg_target_inputs(Args &args, ArgTargetInputs &out); void setup_arg_script_mode(Args &args, ArgScriptInfo &out); } // namespace buildcc + +#endif diff --git a/buildexe/include/buildexe/toolchain_setup.h b/buildexe/include/buildexe/toolchain_setup.h index 98683610..423bbbf4 100644 --- a/buildexe/include/buildexe/toolchain_setup.h +++ b/buildexe/include/buildexe/toolchain_setup.h @@ -14,6 +14,9 @@ * limitations under the License. */ +#ifndef BUILDEXE_TOOLCHAIN_SETUP_H_ +#define BUILDEXE_TOOLCHAIN_SETUP_H_ + #include "buildcc.h" namespace buildcc { @@ -22,3 +25,5 @@ void find_toolchain_verify(BaseToolchain &toolchain); void host_toolchain_verify(const BaseToolchain &toolchain); } // namespace buildcc + +#endif From 153abc2392c07a21539a8e75a64b9fdfb2ffef2f Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 6 Jan 2022 00:56:49 -0800 Subject: [PATCH 35/65] Added buildcc_setup.h --- buildexe/CMakeLists.txt | 3 + buildexe/buildexe.cpp | 77 +++++++++-------------- buildexe/include/buildexe/buildcc_setup.h | 28 +++++++++ buildexe/src/buildcc_setup.cpp | 43 +++++++++++++ 4 files changed, 105 insertions(+), 46 deletions(-) create mode 100644 buildexe/include/buildexe/buildcc_setup.h create mode 100644 buildexe/src/buildcc_setup.cpp diff --git a/buildexe/CMakeLists.txt b/buildexe/CMakeLists.txt index 34e1b6ca..e2e3729b 100644 --- a/buildexe/CMakeLists.txt +++ b/buildexe/CMakeLists.txt @@ -6,6 +6,9 @@ add_executable(buildexe src/toolchain_setup.cpp include/buildexe/toolchain_setup.h + + src/buildcc_setup.cpp + include/buildexe/buildcc_setup.h ) target_sources(buildexe PRIVATE ../bootstrap/src/build_buildcc.cpp diff --git a/buildexe/buildexe.cpp b/buildexe/buildexe.cpp index 4f95422c..83372aef 100644 --- a/buildexe/buildexe.cpp +++ b/buildexe/buildexe.cpp @@ -17,6 +17,7 @@ #include "buildcc.h" #include "buildexe/args_setup.h" +#include "buildexe/buildcc_setup.h" #include "buildexe/toolchain_setup.h" #include "bootstrap/build_buildcc.h" @@ -33,8 +34,8 @@ constexpr const char *const kTag = "BuildExe"; static void clean_cb(); -static fs::path get_env_buildcc_home(); - +static void user_output_buildcc_dep_cb(BaseTarget &user_target, + BaseTarget &buildcc_target); static void user_output_target_cb(BaseTarget &target, const ArgTargetInputs &inputs); @@ -78,43 +79,24 @@ int main(int argc, char **argv) { host_toolchain_verify(toolchain); } + ArgToolchainState user_output_state; + user_output_state.build = true; + PersistentStorage storage; Target_generic user_output_target(out_targetinfo.name, out_targetinfo.type, toolchain, TargetEnv(out_targetinfo.relative_to_root)); if (out_mode == BuildExeMode::Script) { - // Compile buildcc using the constructed toolchain fs::path buildcc_home = get_env_buildcc_home(); auto &buildcc_package = storage.Add( "BuildccPackage", reg, toolchain, TargetEnv(buildcc_home / "buildcc", buildcc_home / "buildcc" / "_build_exe")); - buildcc_package.Setup(host_toolchain_arg.state); - - // Add buildcc as a dependency to user_output_target - user_output_target.AddLibDep(buildcc_package.GetBuildcc()); - user_output_target.Insert(buildcc_package.GetBuildcc(), - { - SyncOption::PreprocessorFlags, - SyncOption::CppCompileFlags, - SyncOption::IncludeDirs, - SyncOption::LinkFlags, - SyncOption::HeaderFiles, - SyncOption::IncludeDirs, - SyncOption::LibDeps, - SyncOption::ExternalLibDeps, - }); - switch (toolchain.GetId()) { - case ToolchainId::MinGW: - user_output_target.AddLinkFlag("-Wl,--allow-multiple-definition"); - break; - default: - break; - } - } - ArgToolchainState user_output_state; - user_output_state.build = true; + buildcc_package.Setup(user_output_state); + user_output_buildcc_dep_cb(user_output_target, + buildcc_package.GetBuildcc()); + } reg.Build(user_output_state, user_output_target_cb, user_output_target, out_targetinputs); @@ -160,24 +142,27 @@ static void clean_cb() { fs::remove_all(env::get_project_build_dir()); } -static fs::path get_env_buildcc_home() { - const char *buildcc_home = getenv("BUILDCC_HOME"); - env::assert_fatal(buildcc_home != nullptr, - "BUILDCC_HOME environment variable not defined"); - - // NOTE, Verify BUILDCC_HOME - // auto &buildcc_path = storage.Add("buildcc_path", buildcc_home); - fs::path buildcc_home_path{buildcc_home}; - env::assert_fatal(fs::exists(buildcc_home_path), - "{BUILDCC_HOME} path not found path not found"); - env::assert_fatal(fs::exists(buildcc_home_path / "buildcc"), - "{BUILDCC_HOME}/buildcc path not found"); - env::assert_fatal(fs::exists(buildcc_home_path / "libs"), - "{BUILDCC_HOME}/libs path not found"); - env::assert_fatal(fs::exists(buildcc_home_path / "extensions"), - "{BUILDCC_HOME}/extensions path not found"); - - return buildcc_home_path; +static void user_output_buildcc_dep_cb(BaseTarget &user_target, + BaseTarget &buildcc_target) { + // Add buildcc as a dependency to user_target + user_target.AddLibDep(buildcc_target); + user_target.Insert(buildcc_target, { + SyncOption::PreprocessorFlags, + SyncOption::CppCompileFlags, + SyncOption::IncludeDirs, + SyncOption::LinkFlags, + SyncOption::HeaderFiles, + SyncOption::IncludeDirs, + SyncOption::LibDeps, + SyncOption::ExternalLibDeps, + }); + switch (user_target.GetToolchain().GetId()) { + case ToolchainId::MinGW: + user_target.AddLinkFlag("-Wl,--allow-multiple-definition"); + break; + default: + break; + } } static void user_output_target_cb(BaseTarget &target, diff --git a/buildexe/include/buildexe/buildcc_setup.h b/buildexe/include/buildexe/buildcc_setup.h new file mode 100644 index 00000000..2e96cb90 --- /dev/null +++ b/buildexe/include/buildexe/buildcc_setup.h @@ -0,0 +1,28 @@ +/* + * Copyright 2021-2022 Niket Naidu. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BUILDEXE_BUILDCC_SETUP_H_ +#define BUILDEXE_BUILDCC_SETUP_H_ + +#include "buildcc.h" + +namespace buildcc { + +fs::path get_env_buildcc_home(); + +} // namespace buildcc + +#endif diff --git a/buildexe/src/buildcc_setup.cpp b/buildexe/src/buildcc_setup.cpp new file mode 100644 index 00000000..4c061b08 --- /dev/null +++ b/buildexe/src/buildcc_setup.cpp @@ -0,0 +1,43 @@ +/* + * Copyright 2021-2022 Niket Naidu. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "buildexe/buildcc_setup.h" + +#include "bootstrap/build_buildcc.h" + +namespace buildcc { + +fs::path get_env_buildcc_home() { + const char *buildcc_home = getenv("BUILDCC_HOME"); + env::assert_fatal(buildcc_home != nullptr, + "BUILDCC_HOME environment variable not defined"); + + // NOTE, Verify BUILDCC_HOME + // auto &buildcc_path = storage.Add("buildcc_path", buildcc_home); + fs::path buildcc_home_path{buildcc_home}; + env::assert_fatal(fs::exists(buildcc_home_path), + "{BUILDCC_HOME} path not found"); + env::assert_fatal(fs::exists(buildcc_home_path / "buildcc"), + "{BUILDCC_HOME}/buildcc path not found"); + env::assert_fatal(fs::exists(buildcc_home_path / "libs"), + "{BUILDCC_HOME}/libs path not found"); + env::assert_fatal(fs::exists(buildcc_home_path / "extensions"), + "{BUILDCC_HOME}/extensions path not found"); + + return buildcc_home_path; +} + +} // namespace buildcc From 12a41766203b3de013db1782c8563b083780b4eb Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 6 Jan 2022 03:18:05 -0800 Subject: [PATCH 36/65] Renamed buildcc_setup to build_env_setup.h/.cpp --- buildexe/CMakeLists.txt | 4 +- buildexe/buildexe.cpp | 101 ++------------ buildexe/include/buildexe/build_env_setup.h | 73 ++++++++++ buildexe/include/buildexe/buildcc_setup.h | 28 ---- buildexe/src/build_env_setup.cpp | 147 ++++++++++++++++++++ buildexe/src/buildcc_setup.cpp | 43 ------ 6 files changed, 231 insertions(+), 165 deletions(-) create mode 100644 buildexe/include/buildexe/build_env_setup.h delete mode 100644 buildexe/include/buildexe/buildcc_setup.h create mode 100644 buildexe/src/build_env_setup.cpp delete mode 100644 buildexe/src/buildcc_setup.cpp diff --git a/buildexe/CMakeLists.txt b/buildexe/CMakeLists.txt index e2e3729b..51ba908c 100644 --- a/buildexe/CMakeLists.txt +++ b/buildexe/CMakeLists.txt @@ -7,8 +7,8 @@ add_executable(buildexe src/toolchain_setup.cpp include/buildexe/toolchain_setup.h - src/buildcc_setup.cpp - include/buildexe/buildcc_setup.h + src/build_env_setup.cpp + include/buildexe/build_env_setup.h ) target_sources(buildexe PRIVATE ../bootstrap/src/build_buildcc.cpp diff --git a/buildexe/buildexe.cpp b/buildexe/buildexe.cpp index 83372aef..c7a554c8 100644 --- a/buildexe/buildexe.cpp +++ b/buildexe/buildexe.cpp @@ -17,7 +17,7 @@ #include "buildcc.h" #include "buildexe/args_setup.h" -#include "buildexe/buildcc_setup.h" +#include "buildexe/build_env_setup.h" #include "buildexe/toolchain_setup.h" #include "bootstrap/build_buildcc.h" @@ -34,11 +34,6 @@ constexpr const char *const kTag = "BuildExe"; static void clean_cb(); -static void user_output_buildcc_dep_cb(BaseTarget &user_target, - BaseTarget &buildcc_target); -static void user_output_target_cb(BaseTarget &target, - const ArgTargetInputs &inputs); - // TODO, Add BuildExeMode::Script usage int main(int argc, char **argv) { Args args; @@ -79,30 +74,13 @@ int main(int argc, char **argv) { host_toolchain_verify(toolchain); } - ArgToolchainState user_output_state; - user_output_state.build = true; - - PersistentStorage storage; - Target_generic user_output_target(out_targetinfo.name, out_targetinfo.type, - toolchain, - TargetEnv(out_targetinfo.relative_to_root)); - if (out_mode == BuildExeMode::Script) { - fs::path buildcc_home = get_env_buildcc_home(); - auto &buildcc_package = storage.Add( - "BuildccPackage", reg, toolchain, - TargetEnv(buildcc_home / "buildcc", - buildcc_home / "buildcc" / "_build_exe")); - - buildcc_package.Setup(user_output_state); - user_output_buildcc_dep_cb(user_output_target, - buildcc_package.GetBuildcc()); - } - reg.Build(user_output_state, user_output_target_cb, user_output_target, - out_targetinputs); - + BuildEnvSetup build_setup(reg, toolchain, out_targetinfo, out_targetinputs); if (out_mode == BuildExeMode::Script) { - auto &buildcc_package = storage.Ref("BuildccPackage"); - reg.Dep(user_output_target, buildcc_package.GetBuildcc()); + build_setup.BuildccTarget(); + build_setup.UserTargetWithBuildcc(); + build_setup.DepUserTargetOnBuildcc(); + } else { + build_setup.UserTarget(); } // Runners @@ -125,14 +103,14 @@ int main(int argc, char **argv) { "{executable} {configs}", { {"executable", - fmt::format("{}", user_output_target.GetTargetPath())}, + fmt::format("{}", build_setup.GetUserTarget().GetTargetPath())}, {"configs", aggregated_configs}, }); env::Command::Execute(command_str); } // - Clang Compile Commands - plugin::ClangCompileCommands({&user_output_target}).Generate(); + plugin::ClangCompileCommands({&build_setup.GetUserTarget()}).Generate(); return 0; } @@ -141,64 +119,3 @@ static void clean_cb() { env::log_info(kTag, fmt::format("Cleaning {}", env::get_project_build_dir())); fs::remove_all(env::get_project_build_dir()); } - -static void user_output_buildcc_dep_cb(BaseTarget &user_target, - BaseTarget &buildcc_target) { - // Add buildcc as a dependency to user_target - user_target.AddLibDep(buildcc_target); - user_target.Insert(buildcc_target, { - SyncOption::PreprocessorFlags, - SyncOption::CppCompileFlags, - SyncOption::IncludeDirs, - SyncOption::LinkFlags, - SyncOption::HeaderFiles, - SyncOption::IncludeDirs, - SyncOption::LibDeps, - SyncOption::ExternalLibDeps, - }); - switch (user_target.GetToolchain().GetId()) { - case ToolchainId::MinGW: - user_target.AddLinkFlag("-Wl,--allow-multiple-definition"); - break; - default: - break; - } -} - -static void user_output_target_cb(BaseTarget &target, - const ArgTargetInputs &inputs) { - for (const auto &s : inputs.source_files) { - target.AddSource(s); - } - for (const auto &i : inputs.include_dirs) { - target.AddIncludeDir(i); - } - - for (const auto &l : inputs.lib_dirs) { - target.AddLibDir(l); - } - for (const auto &el : inputs.external_lib_deps) { - target.AddLibDep(el); - } - - for (const auto &flag : inputs.preprocessor_flags) { - target.AddPreprocessorFlag(flag); - } - for (const auto &flag : inputs.common_compile_flags) { - target.AddCommonCompileFlag(flag); - } - for (const auto &flag : inputs.asm_compile_flags) { - target.AddAsmCompileFlag(flag); - } - for (const auto &flag : inputs.c_compile_flags) { - target.AddCCompileFlag(flag); - } - for (const auto &flag : inputs.cpp_compile_flags) { - target.AddCppCompileFlag(flag); - } - for (const auto &flag : inputs.link_flags) { - target.AddLinkFlag(flag); - } - - target.Build(); -} diff --git a/buildexe/include/buildexe/build_env_setup.h b/buildexe/include/buildexe/build_env_setup.h new file mode 100644 index 00000000..f0b3248b --- /dev/null +++ b/buildexe/include/buildexe/build_env_setup.h @@ -0,0 +1,73 @@ +/* + * Copyright 2021-2022 Niket Naidu. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BUILDEXE_BUILD_ENV_SETUP_H_ +#define BUILDEXE_BUILD_ENV_SETUP_H_ + +#include "buildcc.h" + +#include "bootstrap/build_buildcc.h" +#include "buildexe/args_setup.h" + +namespace buildcc { + +class BuildEnvSetup { +public: + static constexpr const char *const kBuildccPackageName = "BuildccPackage"; + static constexpr const char *const kUserTargetName = "UserTarget"; + +public: + BuildEnvSetup(Register ®, const BaseToolchain &toolchain, + const ArgTargetInfo &arg_target_info, + const ArgTargetInputs &arg_target_inputs) + : reg_(reg), toolchain_(toolchain), arg_target_info_(arg_target_info), + arg_target_inputs_(arg_target_inputs) { + state_.build = true; + } + + void BuildccTarget(); + void UserTarget(); + void UserTargetWithBuildcc(); + void DepUserTargetOnBuildcc(); + + // Getters + StaticTarget_generic &GetBuildcc() { + return storage_.Ref(kBuildccPackageName).GetBuildcc(); + } + Target_generic &GetUserTarget() { + return storage_.Ref(kUserTargetName); + } + +private: + void UserTargetSetup(); + void UserTargetCb(); + void UserTargetBuild(); + + void UserTargetWithBuildccSetup(); + +private: + Register ®_; + const BaseToolchain &toolchain_; + const ArgTargetInfo &arg_target_info_; + const ArgTargetInputs &arg_target_inputs_; + + ArgToolchainState state_; + PersistentStorage storage_; +}; + +} // namespace buildcc + +#endif diff --git a/buildexe/include/buildexe/buildcc_setup.h b/buildexe/include/buildexe/buildcc_setup.h deleted file mode 100644 index 2e96cb90..00000000 --- a/buildexe/include/buildexe/buildcc_setup.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2021-2022 Niket Naidu. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BUILDEXE_BUILDCC_SETUP_H_ -#define BUILDEXE_BUILDCC_SETUP_H_ - -#include "buildcc.h" - -namespace buildcc { - -fs::path get_env_buildcc_home(); - -} // namespace buildcc - -#endif diff --git a/buildexe/src/build_env_setup.cpp b/buildexe/src/build_env_setup.cpp new file mode 100644 index 00000000..11971188 --- /dev/null +++ b/buildexe/src/build_env_setup.cpp @@ -0,0 +1,147 @@ +/* + * Copyright 2021-2022 Niket Naidu. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "buildexe/build_env_setup.h" + +namespace buildcc { + +static fs::path get_env_buildcc_home() { + const char *buildcc_home = getenv("BUILDCC_HOME"); + env::assert_fatal(buildcc_home != nullptr, + "BUILDCC_HOME environment variable not defined"); + + // NOTE, Verify BUILDCC_HOME + // auto &buildcc_path = storage.Add("buildcc_path", buildcc_home); + fs::path buildcc_home_path{buildcc_home}; + env::assert_fatal(fs::exists(buildcc_home_path), + "{BUILDCC_HOME} path not found"); + env::assert_fatal(fs::exists(buildcc_home_path / "buildcc"), + "{BUILDCC_HOME}/buildcc path not found"); + env::assert_fatal(fs::exists(buildcc_home_path / "libs"), + "{BUILDCC_HOME}/libs path not found"); + env::assert_fatal(fs::exists(buildcc_home_path / "extensions"), + "{BUILDCC_HOME}/extensions path not found"); + + return buildcc_home_path; +} + +void BuildEnvSetup::BuildccTarget() { + fs::path buildcc_home = get_env_buildcc_home(); + auto &buildcc_package = storage_.Add( + kBuildccPackageName, reg_, toolchain_, + TargetEnv(buildcc_home / "buildcc", + buildcc_home / "buildcc" / "_build_exe")); + buildcc_package.Setup(state_); +} + +void BuildEnvSetup::UserTarget() { + UserTargetSetup(); + UserTargetCb(); + UserTargetBuild(); +} + +void BuildEnvSetup::UserTargetWithBuildcc() { + BuildccTarget(); + UserTargetSetup(); + UserTargetCb(); + UserTargetWithBuildccSetup(); + UserTargetBuild(); +} + +void BuildEnvSetup::DepUserTargetOnBuildcc() { + reg_.Dep(GetUserTarget(), GetBuildcc()); +} + +// Private + +void BuildEnvSetup::UserTargetSetup() { + Target_generic &user_target = storage_.Add( + kUserTargetName, arg_target_info_.name, arg_target_info_.type, toolchain_, + TargetEnv(arg_target_info_.relative_to_root)); +} + +/** + * @brief Adds from Arg Target Inputs + * + * Source files + * Include Dirs + * Lib Dirs + * External Lib Deps + * Preprocessor flags + * Common Compile flags + * Asm Compile flags + * C Compile flags + * Cpp Compile flags + * Link flags + */ +void BuildEnvSetup::UserTargetCb() { + Target_generic &user_target = GetUserTarget(); + for (const auto &s : arg_target_inputs_.source_files) { + user_target.AddSource(s); + } + for (const auto &i : arg_target_inputs_.include_dirs) { + user_target.AddIncludeDir(i); + } + for (const auto &l : arg_target_inputs_.lib_dirs) { + user_target.AddLibDir(l); + } + for (const auto &el : arg_target_inputs_.external_lib_deps) { + user_target.AddLibDep(el); + } + for (const auto &flag : arg_target_inputs_.preprocessor_flags) { + user_target.AddPreprocessorFlag(flag); + } + for (const auto &flag : arg_target_inputs_.common_compile_flags) { + user_target.AddCommonCompileFlag(flag); + } + for (const auto &flag : arg_target_inputs_.asm_compile_flags) { + user_target.AddAsmCompileFlag(flag); + } + for (const auto &flag : arg_target_inputs_.c_compile_flags) { + user_target.AddCCompileFlag(flag); + } + for (const auto &flag : arg_target_inputs_.cpp_compile_flags) { + user_target.AddCppCompileFlag(flag); + } + for (const auto &flag : arg_target_inputs_.link_flags) { + user_target.AddLinkFlag(flag); + } +} + +void BuildEnvSetup::UserTargetBuild() { GetUserTarget().Build(); } + +void BuildEnvSetup::UserTargetWithBuildccSetup() { + GetUserTarget().AddLibDep(GetBuildcc()); + GetUserTarget().Insert(GetBuildcc(), { + SyncOption::PreprocessorFlags, + SyncOption::CppCompileFlags, + SyncOption::IncludeDirs, + SyncOption::LinkFlags, + SyncOption::HeaderFiles, + SyncOption::IncludeDirs, + SyncOption::LibDeps, + SyncOption::ExternalLibDeps, + }); + switch (GetUserTarget().GetToolchain().GetId()) { + case ToolchainId::MinGW: + GetUserTarget().AddLinkFlag("-Wl,--allow-multiple-definition"); + break; + default: + break; + } +} + +} // namespace buildcc diff --git a/buildexe/src/buildcc_setup.cpp b/buildexe/src/buildcc_setup.cpp deleted file mode 100644 index 4c061b08..00000000 --- a/buildexe/src/buildcc_setup.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2021-2022 Niket Naidu. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "buildexe/buildcc_setup.h" - -#include "bootstrap/build_buildcc.h" - -namespace buildcc { - -fs::path get_env_buildcc_home() { - const char *buildcc_home = getenv("BUILDCC_HOME"); - env::assert_fatal(buildcc_home != nullptr, - "BUILDCC_HOME environment variable not defined"); - - // NOTE, Verify BUILDCC_HOME - // auto &buildcc_path = storage.Add("buildcc_path", buildcc_home); - fs::path buildcc_home_path{buildcc_home}; - env::assert_fatal(fs::exists(buildcc_home_path), - "{BUILDCC_HOME} path not found"); - env::assert_fatal(fs::exists(buildcc_home_path / "buildcc"), - "{BUILDCC_HOME}/buildcc path not found"); - env::assert_fatal(fs::exists(buildcc_home_path / "libs"), - "{BUILDCC_HOME}/libs path not found"); - env::assert_fatal(fs::exists(buildcc_home_path / "extensions"), - "{BUILDCC_HOME}/extensions path not found"); - - return buildcc_home_path; -} - -} // namespace buildcc From a26aa07f40b512bdbe6ce2e533e61e8d0fb92fd8 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 6 Jan 2022 03:32:05 -0800 Subject: [PATCH 37/65] Updated BuildEnvSetup --- buildexe/buildexe.cpp | 2 -- buildexe/include/buildexe/build_env_setup.h | 4 +-- buildexe/src/build_env_setup.cpp | 34 ++++++++++++--------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/buildexe/buildexe.cpp b/buildexe/buildexe.cpp index c7a554c8..dce68974 100644 --- a/buildexe/buildexe.cpp +++ b/buildexe/buildexe.cpp @@ -76,9 +76,7 @@ int main(int argc, char **argv) { BuildEnvSetup build_setup(reg, toolchain, out_targetinfo, out_targetinputs); if (out_mode == BuildExeMode::Script) { - build_setup.BuildccTarget(); build_setup.UserTargetWithBuildcc(); - build_setup.DepUserTargetOnBuildcc(); } else { build_setup.UserTarget(); } diff --git a/buildexe/include/buildexe/build_env_setup.h b/buildexe/include/buildexe/build_env_setup.h index f0b3248b..7a67bcde 100644 --- a/buildexe/include/buildexe/build_env_setup.h +++ b/buildexe/include/buildexe/build_env_setup.h @@ -38,10 +38,8 @@ class BuildEnvSetup { state_.build = true; } - void BuildccTarget(); void UserTarget(); void UserTargetWithBuildcc(); - void DepUserTargetOnBuildcc(); // Getters StaticTarget_generic &GetBuildcc() { @@ -52,11 +50,13 @@ class BuildEnvSetup { } private: + void BuildccTargetSetup(); void UserTargetSetup(); void UserTargetCb(); void UserTargetBuild(); void UserTargetWithBuildccSetup(); + void DepUserTargetOnBuildcc(); private: Register ®_; diff --git a/buildexe/src/build_env_setup.cpp b/buildexe/src/build_env_setup.cpp index 11971188..5d9b1a61 100644 --- a/buildexe/src/build_env_setup.cpp +++ b/buildexe/src/build_env_setup.cpp @@ -38,15 +38,6 @@ static fs::path get_env_buildcc_home() { return buildcc_home_path; } -void BuildEnvSetup::BuildccTarget() { - fs::path buildcc_home = get_env_buildcc_home(); - auto &buildcc_package = storage_.Add( - kBuildccPackageName, reg_, toolchain_, - TargetEnv(buildcc_home / "buildcc", - buildcc_home / "buildcc" / "_build_exe")); - buildcc_package.Setup(state_); -} - void BuildEnvSetup::UserTarget() { UserTargetSetup(); UserTargetCb(); @@ -54,23 +45,33 @@ void BuildEnvSetup::UserTarget() { } void BuildEnvSetup::UserTargetWithBuildcc() { - BuildccTarget(); + BuildccTargetSetup(); UserTargetSetup(); UserTargetCb(); UserTargetWithBuildccSetup(); UserTargetBuild(); + DepUserTargetOnBuildcc(); } +// Private + void BuildEnvSetup::DepUserTargetOnBuildcc() { reg_.Dep(GetUserTarget(), GetBuildcc()); } -// Private +void BuildEnvSetup::BuildccTargetSetup() { + fs::path buildcc_home = get_env_buildcc_home(); + auto &buildcc_package = storage_.Add( + kBuildccPackageName, reg_, toolchain_, + TargetEnv(buildcc_home / "buildcc", + buildcc_home / "buildcc" / "_build_exe")); + buildcc_package.Setup(state_); +} void BuildEnvSetup::UserTargetSetup() { - Target_generic &user_target = storage_.Add( - kUserTargetName, arg_target_info_.name, arg_target_info_.type, toolchain_, - TargetEnv(arg_target_info_.relative_to_root)); + storage_.Add(kUserTargetName, arg_target_info_.name, + arg_target_info_.type, toolchain_, + TargetEnv(arg_target_info_.relative_to_root)); } /** @@ -121,7 +122,10 @@ void BuildEnvSetup::UserTargetCb() { } } -void BuildEnvSetup::UserTargetBuild() { GetUserTarget().Build(); } +void BuildEnvSetup::UserTargetBuild() { + reg_.Build( + state_, [](BaseTarget &target) { target.Build(); }, GetUserTarget()); +} void BuildEnvSetup::UserTargetWithBuildccSetup() { GetUserTarget().AddLibDep(GetBuildcc()); From 65e829f3370445f1bb1ffa85cba1050fc2a9cf3e Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 6 Jan 2022 21:34:42 -0800 Subject: [PATCH 38/65] Added RunUserTarget API --- buildexe/buildexe.cpp | 32 ++++++--------------- buildexe/include/buildexe/build_env_setup.h | 6 ++-- buildexe/src/build_env_setup.cpp | 24 ++++++++++++++-- example/hybrid/single/build.cpp | 11 ++++++- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/buildexe/buildexe.cpp b/buildexe/buildexe.cpp index dce68974..ed2c0fb3 100644 --- a/buildexe/buildexe.cpp +++ b/buildexe/buildexe.cpp @@ -74,37 +74,23 @@ int main(int argc, char **argv) { host_toolchain_verify(toolchain); } + // Build environment BuildEnvSetup build_setup(reg, toolchain, out_targetinfo, out_targetinputs); if (out_mode == BuildExeMode::Script) { - build_setup.UserTargetWithBuildcc(); + // buildcc and user target + build_setup.ConstructUserTargetWithBuildcc(); } else { - build_setup.UserTarget(); + // user target + build_setup.ConstructUserTarget(); } - - // Runners reg.RunBuild(); - env::log_info(kTag, fmt::format("************** Running '{}' **************", - out_targetinfo.name)); - // Run if (out_mode == BuildExeMode::Script) { - std::vector configs; - for (const auto &c : out_scriptinfo.configs) { - std::string config = fmt::format("--config {}", c); - configs.push_back(config); - } - std::string aggregated_configs = fmt::format("{}", fmt::join(configs, " ")); - - env::Command command; - std::string command_str = command.Construct( - "{executable} {configs}", - { - {"executable", - fmt::format("{}", build_setup.GetUserTarget().GetTargetPath())}, - {"configs", aggregated_configs}, - }); - env::Command::Execute(command_str); + env::log_info(kTag, + fmt::format("************** Running '{}' **************", + out_targetinfo.name)); + build_setup.RunUserTarget(out_scriptinfo); } // - Clang Compile Commands diff --git a/buildexe/include/buildexe/build_env_setup.h b/buildexe/include/buildexe/build_env_setup.h index 7a67bcde..4cc219d5 100644 --- a/buildexe/include/buildexe/build_env_setup.h +++ b/buildexe/include/buildexe/build_env_setup.h @@ -38,8 +38,10 @@ class BuildEnvSetup { state_.build = true; } - void UserTarget(); - void UserTargetWithBuildcc(); + void ConstructUserTarget(); + void ConstructUserTargetWithBuildcc(); + + void RunUserTarget(const ArgScriptInfo &arg_script_info); // Getters StaticTarget_generic &GetBuildcc() { diff --git a/buildexe/src/build_env_setup.cpp b/buildexe/src/build_env_setup.cpp index 5d9b1a61..1c65d8c1 100644 --- a/buildexe/src/build_env_setup.cpp +++ b/buildexe/src/build_env_setup.cpp @@ -38,13 +38,13 @@ static fs::path get_env_buildcc_home() { return buildcc_home_path; } -void BuildEnvSetup::UserTarget() { +void BuildEnvSetup::ConstructUserTarget() { UserTargetSetup(); UserTargetCb(); UserTargetBuild(); } -void BuildEnvSetup::UserTargetWithBuildcc() { +void BuildEnvSetup::ConstructUserTargetWithBuildcc() { BuildccTargetSetup(); UserTargetSetup(); UserTargetCb(); @@ -53,6 +53,26 @@ void BuildEnvSetup::UserTargetWithBuildcc() { DepUserTargetOnBuildcc(); } +void BuildEnvSetup::RunUserTarget(const ArgScriptInfo &arg_script_info) { + // Aggregate the different input build .toml files to + // `--config .toml` files + std::vector configs; + std::transform(arg_script_info.configs.begin(), arg_script_info.configs.end(), + std::back_inserter(configs), + [](const std::string &c) -> std::string { + return fmt::format("--config {}", c); + }); + std::string aggregated_configs = fmt::format("{}", fmt::join(configs, " ")); + + // Construct and execute with user target on subprocess + std::string command_str = + fmt::format("{executable} {configs}", + fmt::arg("executable", + fmt::format("{}", GetUserTarget().GetTargetPath())), + fmt::arg("configs", aggregated_configs)); + env::Command::Execute(command_str); +} + // Private void BuildEnvSetup::DepUserTargetOnBuildcc() { diff --git a/example/hybrid/single/build.cpp b/example/hybrid/single/build.cpp index a94fb512..4bb7f829 100644 --- a/example/hybrid/single/build.cpp +++ b/example/hybrid/single/build.cpp @@ -8,7 +8,10 @@ constexpr const char *const EXE = "build"; static void clean_cb(); static void hello_world_build_cb(BaseTarget &target); +static PersistentStorage storage; int main(int argc, char **argv) { + std::atexit([]() { env::log_info("Cleaning", ""); }); + // 1. Get arguments Args args; ArgToolchain arg_gcc; @@ -23,7 +26,13 @@ int main(int argc, char **argv) { // 4. Build steps // Explicit toolchain - target pairs - Toolchain_gcc gcc; + // Toolchain_gcc gcc; + + // PersistentStorage storage; + Toolchain_gcc &gcc = storage.Add("toolchain_gcc"); + storage.Add("hello_world", "hello_world", gcc, ""); + + return 0; ExecutableTarget_gcc hello_world("hello_world", gcc, ""); auto verified_toolchains = gcc.Verify(); From 9aab820ce30c82fb33ab1275fe43d1be24b84f8a Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 6 Jan 2022 21:35:54 -0800 Subject: [PATCH 39/65] Update persistent_storage.h --- buildcc/lib/args/include/args/persistent_storage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildcc/lib/args/include/args/persistent_storage.h b/buildcc/lib/args/include/args/persistent_storage.h index 4c3c5b73..9e4c86e7 100644 --- a/buildcc/lib/args/include/args/persistent_storage.h +++ b/buildcc/lib/args/include/args/persistent_storage.h @@ -48,7 +48,7 @@ class PersistentStorage { metadata.ptr = (void *)ptr; metadata.typeid_name = typeid(T).name(); metadata.destructor = [this, identifier, ptr]() { - env::log_info("Cleaning", identifier); + env::log_trace("Cleaning", identifier); Remove(ptr); }; ptrs_.emplace(identifier, metadata); From e778d159c801a1d2398aeebd6654370610601a43 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 6 Jan 2022 21:53:29 -0800 Subject: [PATCH 40/65] Update build.cpp --- example/hybrid/single/build.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/example/hybrid/single/build.cpp b/example/hybrid/single/build.cpp index 4bb7f829..a94fb512 100644 --- a/example/hybrid/single/build.cpp +++ b/example/hybrid/single/build.cpp @@ -8,10 +8,7 @@ constexpr const char *const EXE = "build"; static void clean_cb(); static void hello_world_build_cb(BaseTarget &target); -static PersistentStorage storage; int main(int argc, char **argv) { - std::atexit([]() { env::log_info("Cleaning", ""); }); - // 1. Get arguments Args args; ArgToolchain arg_gcc; @@ -26,13 +23,7 @@ int main(int argc, char **argv) { // 4. Build steps // Explicit toolchain - target pairs - // Toolchain_gcc gcc; - - // PersistentStorage storage; - Toolchain_gcc &gcc = storage.Add("toolchain_gcc"); - storage.Add("hello_world", "hello_world", gcc, ""); - - return 0; + Toolchain_gcc gcc; ExecutableTarget_gcc hello_world("hello_world", gcc, ""); auto verified_toolchains = gcc.Verify(); From 5899026517c9fe9049ef0ca9605421621c1c2ab3 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 6 Jan 2022 21:53:40 -0800 Subject: [PATCH 41/65] Update setup.rst --- docs/source/getting_started/setup.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/source/getting_started/setup.rst b/docs/source/getting_started/setup.rst index 64907294..1ae1edcd 100644 --- a/docs/source/getting_started/setup.rst +++ b/docs/source/getting_started/setup.rst @@ -105,3 +105,6 @@ This folder will contain the .toml files of all the HOST toolchains present on y *** mingw_x86_64-w64-mingw32_10.2.0.toml *** msvc_am64_19.29.30137.toml @endmindmap + + +.. note:: **Extensions** and **Libs** will come later in the tutorial From 6f0279d070f1cac75bb01f63109c90a1842f9b96 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 6 Jan 2022 22:39:05 -0800 Subject: [PATCH 42/65] Added usage_buildexe.rst --- docs/source/getting_started/toc.rst | 4 +- .../source/getting_started/usage_buildexe.rst | 158 ++++++++++++++++++ 2 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 docs/source/getting_started/usage_buildexe.rst diff --git a/docs/source/getting_started/toc.rst b/docs/source/getting_started/toc.rst index 29055442..81d25567 100644 --- a/docs/source/getting_started/toc.rst +++ b/docs/source/getting_started/toc.rst @@ -4,9 +4,9 @@ Getting Started .. toctree:: setup + usage_buildexe + -Usage through BuildExe ----------------------- Usage through CMake ------------------- diff --git a/docs/source/getting_started/usage_buildexe.rst b/docs/source/getting_started/usage_buildexe.rst new file mode 100644 index 00000000..0bea4513 --- /dev/null +++ b/docs/source/getting_started/usage_buildexe.rst @@ -0,0 +1,158 @@ +Usage through BuildExe +====================== + +Basic Procedure +---------------- + +Since we are writing our scripts in C++ we first need to **compile** our "script" to an executable, and then **execute** it to build targets. + +.. uml:: + + usecase "build.helloworld.cpp" as build_cpp + usecase "compile.toml" as compile_toml + usecase "host_toolchain.toml" as host_toolchain_toml + usecase "./build.helloworld" as build_project_exe + usecase "build.toml" as build_toml + + rectangle "./buildexe" as buildexe_exe + + artifact "./hello_world" as hello_world_exe + + compile_toml -up-> build_cpp + host_toolchain_toml -up-> build_cpp + build_cpp -right-> buildexe_exe + buildexe_exe -right-> build_project_exe + build_toml -up-> build_project_exe + build_project_exe -right-> hello_world_exe + +Helloworld example +------------------ + +* Write your C++ "script" +* Write your ``compile.toml`` file +* Write your ``build.toml`` file +* Invoke ``buildexe`` from the command line from the **[workspace]** folder + * Pay attention to the ``root_dir`` and ``build_dir`` parameters set in your ``compile.toml`` and ``build.toml`` file. + * These directories are relative to the directory from which you **invoke** buildexe + +.. code-block:: bash + + ./buildexe --config compile.toml --config $BUILDCC_HOME/host/host_toolchain.toml + +Directory structure +++++++++++++++++++++ + +.. uml:: + + @startmindmap + * [workspace] + ** [src] + *** main.cpp + ** build.helloworld.cpp + ** compile.toml + ** build.toml + @endmindmap + +Write your C++ "script" +++++++++++++++++++++++++ + +.. code-block:: cpp + :linenos: + :caption: build.helloworld.cpp + + #include "buildcc.h" + + using namespace buildcc; + + void clean_cb(); + // All specialized targets derive from BaseTarget + void hello_world_build_cb(BaseTarget & target); + + int main(int argc, char ** argv) { + // Step 1. Setup your args + Args args; + ArgToolchain arg_gcc; + args.AddToolchain("gcc", "GCC toolchain", arg_gcc); + args.Parse(argc, argv); + + // Step 2. Register + Register reg(args); + + // Step 3. Pre build steps + // for example. clean your environment + reg.Clean(clean_cb); + + // Step 4. Build steps + Toolchain_gcc gcc; + auto verified_gcc_toolchains = gcc.Verify(); + env::assert_fatal(!verified_gcc_toolchains.empty(), "GCC toolchain not found"); + + ExecutableTarget_gcc hello_world("hello_world", gcc, ""); + reg.Build(arg_gcc.state, hello_world_build_cb, hello_world); + + // Step 5. Build your targets + reg.RunBuild(); + + // Step 6. Post build steps + // for example. clang compile commands database + plugin::ClangCompileCommands({&hello_world}).Generate(); + + return 0; + } + + void clean_cb() { + fs::remove_all(env::get_project_build_dir()); + } + + void hello_world_build_cb(BaseTarget & target) { + // Add your source + target.AddSource("src/main.cpp"); + + // Initializes the target build tasks + target.Build(); + } + +Write your ``compile.toml`` file +++++++++++++++++++++++++++++++++ + +.. code-block:: toml + :linenos: + :caption: compile.toml + + # Settings + root_dir = "" + build_dir = "_build_internal" + loglevel = "info" + clean = false + + # BuildExe run mode + mode = "script" + + # Target information + name = "build.helloworld" + type = "executable" + relative_to_root = "" + srcs = ["build.helloworld.cpp"] + + [script] + configs = ["build.toml"] + +Write your ``build.toml`` file ++++++++++++++++++++++++++++++++ + +.. code-block:: toml + :linenos: + :caption: build.toml + + # Root + root_dir = "" + build_dir = "_build" + loglevel = "debug" + + # Project + clean = false + + # Toolchain + [toolchain.gcc] + build = true + test = false From 6f2e08fc1b07326c129e1927ca96a5ea4722a551 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 6 Jan 2022 22:39:08 -0800 Subject: [PATCH 43/65] Update build.cpp --- example/hybrid/single/build.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/hybrid/single/build.cpp b/example/hybrid/single/build.cpp index a94fb512..3abace55 100644 --- a/example/hybrid/single/build.cpp +++ b/example/hybrid/single/build.cpp @@ -24,11 +24,11 @@ int main(int argc, char **argv) { // 4. Build steps // Explicit toolchain - target pairs Toolchain_gcc gcc; - - ExecutableTarget_gcc hello_world("hello_world", gcc, ""); auto verified_toolchains = gcc.Verify(); env::assert_fatal(!verified_toolchains.empty(), "GCC Toolchain not found"); + ExecutableTarget_gcc hello_world("hello_world", gcc, ""); + // Select your builds and tests using the .toml files reg.Build(arg_gcc.state, hello_world_build_cb, hello_world); From f233ac5e123318aeeb6b342576c389ccac322672 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 01:13:42 -0800 Subject: [PATCH 44/65] Update usage_buildexe.rst --- .../source/getting_started/usage_buildexe.rst | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/source/getting_started/usage_buildexe.rst b/docs/source/getting_started/usage_buildexe.rst index 0bea4513..b6a9890a 100644 --- a/docs/source/getting_started/usage_buildexe.rst +++ b/docs/source/getting_started/usage_buildexe.rst @@ -1,5 +1,5 @@ -Usage through BuildExe -====================== +Getting started with BuildExe +============================= Basic Procedure ---------------- @@ -39,6 +39,8 @@ Helloworld example ./buildexe --config compile.toml --config $BUILDCC_HOME/host/host_toolchain.toml +* Your target will now be present in ``[build_dir]/[toolchain_name]/[target_name]`` (taken from ``build.toml`` and ``build.helloworld.cpp``) + Directory structure ++++++++++++++++++++ @@ -56,8 +58,24 @@ Directory structure Write your C++ "script" ++++++++++++++++++++++++ +From the "script" below we can see that we have a few lines of **boilerplate** + +* Setup args +* Setup register (pre and post callback requirements) + +We then setup our main **toolchain**-**target** pairs. Highlighted below + +* Specify your toolchain + * Verify the toolchain existance on your machine by using the ``.Verify`` API + * If multiple similar toolchains are detected (due to multiple installations), the first found toolchain is picked + * You can pass in the ``VerifyToolchainConfig`` to narrow down your search and verification. +* Specify your compatible target + * Every specific target is meant to use a specific target. + * For example: ``ExecutableTarget_gcc`` specialized target can use the ``Toolchain_gcc`` specialized toolchain but not ``Toolchain_msvc``. + .. code-block:: cpp :linenos: + :emphasize-lines: 25,26,27,29,30 :caption: build.helloworld.cpp #include "buildcc.h" @@ -83,6 +101,7 @@ Write your C++ "script" reg.Clean(clean_cb); // Step 4. Build steps + // Main setup Toolchain_gcc gcc; auto verified_gcc_toolchains = gcc.Verify(); env::assert_fatal(!verified_gcc_toolchains.empty(), "GCC toolchain not found"); From bd4e7692e0b754c3613efba1f196a02c8d715b9a Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 01:24:10 -0800 Subject: [PATCH 45/65] Renamed file --- .../{usage_buildexe.rst => buildexe_getting_started.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/source/getting_started/{usage_buildexe.rst => buildexe_getting_started.rst} (100%) diff --git a/docs/source/getting_started/usage_buildexe.rst b/docs/source/getting_started/buildexe_getting_started.rst similarity index 100% rename from docs/source/getting_started/usage_buildexe.rst rename to docs/source/getting_started/buildexe_getting_started.rst From b85e1a56f4f35a7352dd9676ea8d4e7fbec04852 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 01:28:25 -0800 Subject: [PATCH 46/65] Update buildexe_getting_started.rst --- docs/source/getting_started/buildexe_getting_started.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/source/getting_started/buildexe_getting_started.rst b/docs/source/getting_started/buildexe_getting_started.rst index b6a9890a..110f5cb5 100644 --- a/docs/source/getting_started/buildexe_getting_started.rst +++ b/docs/source/getting_started/buildexe_getting_started.rst @@ -15,12 +15,11 @@ Since we are writing our scripts in C++ we first need to **compile** our "script usecase "build.toml" as build_toml rectangle "./buildexe" as buildexe_exe - artifact "./hello_world" as hello_world_exe - compile_toml -up-> build_cpp - host_toolchain_toml -up-> build_cpp build_cpp -right-> buildexe_exe + compile_toml -up-> buildexe_exe + host_toolchain_toml -up-> buildexe_exe buildexe_exe -right-> build_project_exe build_toml -up-> build_project_exe build_project_exe -right-> hello_world_exe From 1de0baafc820dfe097a60139f5cd891103ca9d07 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 01:47:18 -0800 Subject: [PATCH 47/65] Update toc.rst --- docs/source/getting_started/toc.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/source/getting_started/toc.rst b/docs/source/getting_started/toc.rst index 81d25567..5177d942 100644 --- a/docs/source/getting_started/toc.rst +++ b/docs/source/getting_started/toc.rst @@ -4,9 +4,7 @@ Getting Started .. toctree:: setup - usage_buildexe - - + buildexe_getting_started Usage through CMake ------------------- From 5b36ef640f94fa19ad0e7ff512f8a442a83a7a4d Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 01:58:56 -0800 Subject: [PATCH 48/65] Added all_compile_options and all_build_options --- .../getting_started/all_compile_options.rst | 47 +++++++++++++++++++ .../all_default_build_options.rst | 3 ++ docs/source/getting_started/toc.rst | 2 + 3 files changed, 52 insertions(+) create mode 100644 docs/source/getting_started/all_compile_options.rst create mode 100644 docs/source/getting_started/all_default_build_options.rst diff --git a/docs/source/getting_started/all_compile_options.rst b/docs/source/getting_started/all_compile_options.rst new file mode 100644 index 00000000..0a5dda95 --- /dev/null +++ b/docs/source/getting_started/all_compile_options.rst @@ -0,0 +1,47 @@ +Compile Options for BuildExe +============================ + +We can pass in configuration parameters through the Command Line but writing them inside a ``.toml`` file and passing it through the ``--config`` flag is much easiler. + +.. code-block:: shell + + BuildCC buildsystem + Usage: buildexe [OPTIONS] [SUBCOMMAND] + + Options: + -h,--help Print this help message and exit + --help-all Expand individual options. + --config Read .toml files. + --mode ENUM:value in {script->1,immediate->0} OR {1,0} REQUIRED + Provide BuildExe run mode + --name TEXT REQUIRED Provide Target name + --type ENUM:value in {dynamicLibrary->2,staticLibrary->1,executable->0} OR {2,1,0} REQUIRED + Provide Target Type + --relative_to_root TEXT REQUIRED + Provide Target relative to root + --srcs TEXT ... Provide source files + --includes TEXT ... Provide include dirs + --lib_dirs TEXT ... Provide lib dirs + --external_libs TEXT ... Provide external libs + --preprocessor_flags TEXT ... + Provide Preprocessor flags + --common_compile_flags TEXT ... + Provide CommonCompile Flags + --asm_compile_flags TEXT ... + Provide AsmCompile Flags + --c_compile_flags TEXT ... Provide CCompile Flags + --cpp_compile_flags TEXT ... + Provide CppCompile Flags + --link_flags TEXT ... Provide Link Flags + + + Root: + --clean Clean artifacts + --loglevel ENUM:value in {warning->3,info->2,debug->1,critical->5,trace->0} OR {3,2,1,5,0} + LogLevel settings + --root_dir TEXT REQUIRED Project root directory (relative to current directory) + --build_dir TEXT REQUIRED Project build dir (relative to current directory) + + Subcommands: + toolchain Select Toolchain + target Select Target diff --git a/docs/source/getting_started/all_default_build_options.rst b/docs/source/getting_started/all_default_build_options.rst new file mode 100644 index 00000000..b1e8d970 --- /dev/null +++ b/docs/source/getting_started/all_default_build_options.rst @@ -0,0 +1,3 @@ +Build Options for "scripts" +============================ + diff --git a/docs/source/getting_started/toc.rst b/docs/source/getting_started/toc.rst index 5177d942..695eb044 100644 --- a/docs/source/getting_started/toc.rst +++ b/docs/source/getting_started/toc.rst @@ -5,6 +5,8 @@ Getting Started setup buildexe_getting_started + all_compile_options + all_default_build_options Usage through CMake ------------------- From f8305001f237535f156f237772033a4a45663d60 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 05:07:49 -0800 Subject: [PATCH 49/65] Update args.cpp --- buildcc/lib/args/src/args.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/buildcc/lib/args/src/args.cpp b/buildcc/lib/args/src/args.cpp index a4642c01..c9ab18cb 100644 --- a/buildcc/lib/args/src/args.cpp +++ b/buildcc/lib/args/src/args.cpp @@ -137,19 +137,17 @@ void Args::RootArgs() { ->expected(kMinFiles, kMaxFiles); // Root flags + auto *root_group = app_.add_option_group(kRootGroup); - app_.add_flag(kCleanParam, clean_, kCleanDesc)->group(kRootGroup); - app_.add_option(kLoglevelParam, loglevel_, kLoglevelDesc) - ->transform(CLI::CheckedTransformer(kLogLevelMap, CLI::ignore_case)) - ->group(kRootGroup); + root_group->add_flag(kCleanParam, clean_, kCleanDesc); + root_group->add_option(kLoglevelParam, loglevel_, kLoglevelDesc) + ->transform(CLI::CheckedTransformer(kLogLevelMap, CLI::ignore_case)); // Dir flags - app_.add_option(kRootDirParam, project_root_dir_, kRootDirDesc) - ->required() - ->group(kRootGroup); - app_.add_option(kBuildDirParam, project_build_dir_, kBuildDirDesc) - ->required() - ->group(kRootGroup); + root_group->add_option(kRootDirParam, project_root_dir_, kRootDirDesc) + ->required(); + root_group->add_option(kBuildDirParam, project_build_dir_, kBuildDirDesc) + ->required(); } } // namespace buildcc From d978a560105c2bd3c83bcc70fd51be55216806e9 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 05:08:40 -0800 Subject: [PATCH 50/65] Update args_setup.cpp --- buildexe/src/args_setup.cpp | 56 ++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/buildexe/src/args_setup.cpp b/buildexe/src/args_setup.cpp index 4c175e4f..c69c9be6 100644 --- a/buildexe/src/args_setup.cpp +++ b/buildexe/src/args_setup.cpp @@ -38,42 +38,54 @@ void setup_arg_buildexe_mode(Args &args, BuildExeMode &out) { // TODO, Add subcommand [build.info] void setup_arg_target_info(Args &args, ArgTargetInfo &out) { + constexpr const char *const kProjectInfo = "Project Info"; auto &app = args.Ref(); - app.add_option("--name", out.name, "Provide Target name")->required(); + auto *project_info_app = app.add_option_group(kProjectInfo); - app.add_option("--type", out.type, "Provide Target Type") + project_info_app->add_option("--name", out.name, "Provide Target name") + ->required(); + + project_info_app->add_option("--type", out.type, "Provide Target Type") ->transform(CLI::CheckedTransformer(kTargetTypeMap, CLI::ignore_case)) ->required(); - app.add_option("--relative_to_root", out.relative_to_root, - "Provide Target relative to root") + project_info_app + ->add_option("--relative_to_root", out.relative_to_root, + "Provide Target relative to root") ->required(); } // TODO, Add subcommand [build.inputs] // TODO, Add group, group by sources, headers, inncludes on CLI void setup_arg_target_inputs(Args &args, ArgTargetInputs &out) { + constexpr const char *const kTargetInputs = "Target Inputs"; auto &app = args.Ref(); - app.add_option("--srcs", out.source_files, "Provide source files"); - app.add_option("--includes", out.include_dirs, "Provide include dirs"); - - app.add_option("--lib_dirs", out.lib_dirs, "Provide lib dirs"); - app.add_option("--external_libs", out.external_lib_deps, - "Provide external libs"); - - app.add_option("--preprocessor_flags", out.preprocessor_flags, - "Provide Preprocessor flags"); - app.add_option("--common_compile_flags", out.common_compile_flags, - "Provide CommonCompile Flags"); - app.add_option("--asm_compile_flags", out.asm_compile_flags, - "Provide AsmCompile Flags"); - app.add_option("--c_compile_flags", out.c_compile_flags, - "Provide CCompile Flags"); - app.add_option("--cpp_compile_flags", out.cpp_compile_flags, - "Provide CppCompile Flags"); - app.add_option("--link_flags", out.link_flags, "Provide Link Flags"); + auto *target_inputs_app = app.add_option_group(kTargetInputs); + + target_inputs_app->add_option("--srcs", out.source_files, + "Provide source files"); + target_inputs_app->add_option("--includes", out.include_dirs, + "Provide include dirs"); + + target_inputs_app->add_option("--lib_dirs", out.lib_dirs, "Provide lib dirs"); + target_inputs_app->add_option("--external_libs", out.external_lib_deps, + "Provide external libs"); + + target_inputs_app->add_option("--preprocessor_flags", out.preprocessor_flags, + "Provide Preprocessor flags"); + target_inputs_app->add_option("--common_compile_flags", + out.common_compile_flags, + "Provide CommonCompile Flags"); + target_inputs_app->add_option("--asm_compile_flags", out.asm_compile_flags, + "Provide AsmCompile Flags"); + target_inputs_app->add_option("--c_compile_flags", out.c_compile_flags, + "Provide CCompile Flags"); + target_inputs_app->add_option("--cpp_compile_flags", out.cpp_compile_flags, + "Provide CppCompile Flags"); + target_inputs_app->add_option("--link_flags", out.link_flags, + "Provide Link Flags"); } void setup_arg_script_mode(Args &args, ArgScriptInfo &out) { From 27da98eec789e958abcccd76d76212d9372267bd Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 05:08:45 -0800 Subject: [PATCH 51/65] Update buildexe.cpp --- buildexe/buildexe.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/buildexe/buildexe.cpp b/buildexe/buildexe.cpp index ed2c0fb3..1c4aff44 100644 --- a/buildexe/buildexe.cpp +++ b/buildexe/buildexe.cpp @@ -34,7 +34,6 @@ constexpr const char *const kTag = "BuildExe"; static void clean_cb(); -// TODO, Add BuildExeMode::Script usage int main(int argc, char **argv) { Args args; From d2f2c14e291eb57c4659502a83cc0cc9733c0f45 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 05:28:34 -0800 Subject: [PATCH 52/65] Update all_compile_options.rst --- .../getting_started/all_compile_options.rst | 123 +++++++++++++----- 1 file changed, 93 insertions(+), 30 deletions(-) diff --git a/docs/source/getting_started/all_compile_options.rst b/docs/source/getting_started/all_compile_options.rst index 0a5dda95..1365a592 100644 --- a/docs/source/getting_started/all_compile_options.rst +++ b/docs/source/getting_started/all_compile_options.rst @@ -1,7 +1,7 @@ Compile Options for BuildExe ============================ -We can pass in configuration parameters through the Command Line but writing them inside a ``.toml`` file and passing it through the ``--config`` flag is much easiler. +We can pass in configuration parameters through the Command Line but writing them inside a ``.toml`` file and passing it through the ``--config`` flag is much easier. .. code-block:: shell @@ -14,34 +14,97 @@ We can pass in configuration parameters through the Command Line but writing the --config Read .toml files. --mode ENUM:value in {script->1,immediate->0} OR {1,0} REQUIRED Provide BuildExe run mode - --name TEXT REQUIRED Provide Target name - --type ENUM:value in {dynamicLibrary->2,staticLibrary->1,executable->0} OR {2,1,0} REQUIRED - Provide Target Type - --relative_to_root TEXT REQUIRED - Provide Target relative to root - --srcs TEXT ... Provide source files - --includes TEXT ... Provide include dirs - --lib_dirs TEXT ... Provide lib dirs - --external_libs TEXT ... Provide external libs - --preprocessor_flags TEXT ... - Provide Preprocessor flags - --common_compile_flags TEXT ... - Provide CommonCompile Flags - --asm_compile_flags TEXT ... - Provide AsmCompile Flags - --c_compile_flags TEXT ... Provide CCompile Flags - --cpp_compile_flags TEXT ... - Provide CppCompile Flags - --link_flags TEXT ... Provide Link Flags - - - Root: - --clean Clean artifacts - --loglevel ENUM:value in {warning->3,info->2,debug->1,critical->5,trace->0} OR {3,2,1,5,0} - LogLevel settings - --root_dir TEXT REQUIRED Project root directory (relative to current directory) - --build_dir TEXT REQUIRED Project build dir (relative to current directory) + [Option Group: Root] + Options: + --clean Clean artifacts + --loglevel ENUM:value in {warning->3,info->2,debug->1,critical->5,trace->0} OR {3,2,1,5,0} + LogLevel settings + --root_dir TEXT REQUIRED Project root directory (relative to current directory) + --build_dir TEXT REQUIRED Project build dir (relative to current directory) + [Option Group: Project Info] + Options: + --name TEXT REQUIRED Provide Target name + --type ENUM:value in {dynamicLibrary->2,staticLibrary->1,executable->0} OR {2,1,0} REQUIRED + Provide Target Type + --relative_to_root TEXT REQUIRED + Provide Target relative to root + [Option Group: Target Inputs] + Options: + --srcs TEXT ... Provide source files + --includes TEXT ... Provide include dirs + --lib_dirs TEXT ... Provide lib dirs + --external_libs TEXT ... Provide external libs + --preprocessor_flags TEXT ... + Provide Preprocessor flags + --common_compile_flags TEXT ... + Provide CommonCompile Flags + --asm_compile_flags TEXT ... + Provide AsmCompile Flags + --c_compile_flags TEXT ... Provide CCompile Flags + --cpp_compile_flags TEXT ... + Provide CppCompile Flags + --link_flags TEXT ... Provide Link Flags Subcommands: - toolchain Select Toolchain - target Select Target + toolchain + Select Toolchain + Supported Toolchains: + host Host Toolchain + + target + Select Target + + script + Options: + --configs TEXT ... Config files for script mode + +**TOML** file equivalent. You can also read `CLI11 README `_ + +.. code-block:: toml + + # Default (ungrouped) Options + mode = "script" # REQUIRED script, immediate + + # Root Options + clean = true # true, false + loglevel = "trace" # "trace", "debug", "info", "warning", "critical" + root_dir = "" # REQUIRED + build_dir = "" # REQUIRED + + # Target Info Options + name = "" # REQUIRED + type = "executable" # REQUIRED, executable, staticLibrary, dynamicLibrary + relative_to_root = "" # REQUIRED + + # Target Inputs Options + srcs = [""] + includes = [""] + lib_dirs = [""] + external_libs = [""] + preprocessor_flags = [""] + common_compile_flags = [""] + asm_compile_flags = [""] + c_compile_flags = [""] + cpp_compile_flags = [""] + link_flags = [""] + + # Subcommand + + # Host Toolchain Options + [toolchain.host] # ALWAYS + build = true # ALWAYS + test = false # ALWAYS + + id = "gcc" + name = "x86_64-linux-gnu" + asm_compiler = "as" + c_compiler = "gcc" + cpp_compiler = "g++" + archiver = "ar" + linker = "ld" + + # TODO, Add more options to narrow down search when multiple toolchains are installed + + # Script Options + [script] + configs = ["build.toml", "custom_toolchain.toml"] # Converted to --config build.toml --config custom_toolchain.toml From b54639454e5b486c2ba046169783b8eb4071b9ce Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 05:31:59 -0800 Subject: [PATCH 53/65] Update buildexe_getting_started.rst --- docs/source/getting_started/buildexe_getting_started.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/getting_started/buildexe_getting_started.rst b/docs/source/getting_started/buildexe_getting_started.rst index 110f5cb5..f736f13d 100644 --- a/docs/source/getting_started/buildexe_getting_started.rst +++ b/docs/source/getting_started/buildexe_getting_started.rst @@ -24,8 +24,8 @@ Since we are writing our scripts in C++ we first need to **compile** our "script build_toml -up-> build_project_exe build_project_exe -right-> hello_world_exe -Helloworld example ------------------- +Helloworld "script" example +--------------------------- * Write your C++ "script" * Write your ``compile.toml`` file From 21f0f707010675a92ec5b194d5be40336f904bc1 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 05:32:04 -0800 Subject: [PATCH 54/65] Update all_compile_options.rst --- docs/source/getting_started/all_compile_options.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/source/getting_started/all_compile_options.rst b/docs/source/getting_started/all_compile_options.rst index 1365a592..e9a0412d 100644 --- a/docs/source/getting_started/all_compile_options.rst +++ b/docs/source/getting_started/all_compile_options.rst @@ -3,6 +3,9 @@ Compile Options for BuildExe We can pass in configuration parameters through the Command Line but writing them inside a ``.toml`` file and passing it through the ``--config`` flag is much easier. +Command Line options +--------------------- + .. code-block:: shell BuildCC buildsystem @@ -58,7 +61,12 @@ We can pass in configuration parameters through the Command Line but writing the Options: --configs TEXT ... Config files for script mode -**TOML** file equivalent. You can also read `CLI11 README `_ +TOML file options +------------------- + +Relate the options below with the **Command Line options** above. + +You can also read the `CLI11 README `_ .. code-block:: toml From 51458ba40c373b291fc5a367b34fbbbab9edfefb Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 06:16:43 -0800 Subject: [PATCH 55/65] Updated all_default_build_options --- .../getting_started/all_compile_options.rst | 3 - .../all_default_build_options.rst | 75 +++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/docs/source/getting_started/all_compile_options.rst b/docs/source/getting_started/all_compile_options.rst index e9a0412d..cfcad3d7 100644 --- a/docs/source/getting_started/all_compile_options.rst +++ b/docs/source/getting_started/all_compile_options.rst @@ -8,9 +8,6 @@ Command Line options .. code-block:: shell - BuildCC buildsystem - Usage: buildexe [OPTIONS] [SUBCOMMAND] - Options: -h,--help Print this help message and exit --help-all Expand individual options. diff --git a/docs/source/getting_started/all_default_build_options.rst b/docs/source/getting_started/all_default_build_options.rst index b1e8d970..4d17c8e0 100644 --- a/docs/source/getting_started/all_default_build_options.rst +++ b/docs/source/getting_started/all_default_build_options.rst @@ -1,3 +1,78 @@ Build Options for "scripts" ============================ +We can pass in configuration parameters through the Command Line but writing them inside a ``.toml`` file and passing it through the ``--config`` flag is much easier. + +Command Line options +--------------------- + +.. code-block:: shell + + Options: + -h,--help Print this help message and exit + --help-all Expand individual options. + --config Read .toml files. + [Option Group: Root] + Options: + --clean Clean artifacts + --loglevel ENUM:value in {warning->3,info->2,debug->1,critical->5,trace->0} OR {3,2,1,5,0} + LogLevel settings + --root_dir TEXT REQUIRED Project root directory (relative to current directory) + --build_dir TEXT REQUIRED Project build dir (relative to current directory) + + Subcommands: + toolchain + Select Toolchain + Supported Toolchains: + gcc Generic gcc toolchain + + target + Select Target + +TOML file options +------------------- + +Relate the options below with the **Command Line options** above. + +You can also read the `CLI11 README `_ + +.. code-block:: toml + + # Root Options + clean = true # true, false + loglevel = "trace" # "trace", "debug", "info", "warning", "critical" + root_dir = "" # REQUIRED + build_dir = "" # REQUIRED + + # Subcommand + + # Host Toolchain Options + [toolchain.gcc] # DEPENDS on user + + # Run time way to select your build and test options during registration + # Valid options + # build = false, test = false, target not built or tested + # build = true, test = false, target built but not tested + # build = true, test = true, target built and tested (users responsiblity for a testable target) + build = true # REQUIRED + test = true # REQUIRED + + # Run time way to change the compiler on the fly + # Not recommended + # Prefer to use the specialized Toolchains during Compile time (See build.cpp in examples) + # id = "gcc" + # name = "x86_64-linux-gnu" + # asm_compiler = "as" + # c_compiler = "gcc" + # cpp_compiler = "g++" + # archiver = "ar" + # linker = "ld" + + # TODO, Add more options to narrow down search when multiple toolchains are installed + + +.. note:: These are the default build options during "script" mode. + + Users can also add custom arguments using CLI11 using the ``.Ref()`` API and using them in the ``.toml`` file. + + Please make sure to read the `CLI11 README `_ for those APIs. From 30349a7392e29d8eba8c6531b25bfebaceada790 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 06:18:40 -0800 Subject: [PATCH 56/65] Updated heading naming --- docs/source/getting_started/buildexe_getting_started.rst | 2 +- docs/source/getting_started/setup.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/getting_started/buildexe_getting_started.rst b/docs/source/getting_started/buildexe_getting_started.rst index f736f13d..04651f88 100644 --- a/docs/source/getting_started/buildexe_getting_started.rst +++ b/docs/source/getting_started/buildexe_getting_started.rst @@ -1,4 +1,4 @@ -Getting started with BuildExe +BuildExe "Script" example ============================= Basic Procedure diff --git a/docs/source/getting_started/setup.rst b/docs/source/getting_started/setup.rst index 1ae1edcd..dd06ac93 100644 --- a/docs/source/getting_started/setup.rst +++ b/docs/source/getting_started/setup.rst @@ -1,5 +1,5 @@ -Setup -======== +BuildExe Setup +============== ENV[BUILDCC_HOME] ----------------- From 425ec4e25d81696ac501f80f7aec95c4bb5314eb Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 06:19:16 -0800 Subject: [PATCH 57/65] Renamed file --- docs/source/getting_started/{setup.rst => buildexe_setup.rst} | 0 docs/source/getting_started/toc.rst | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename docs/source/getting_started/{setup.rst => buildexe_setup.rst} (100%) diff --git a/docs/source/getting_started/setup.rst b/docs/source/getting_started/buildexe_setup.rst similarity index 100% rename from docs/source/getting_started/setup.rst rename to docs/source/getting_started/buildexe_setup.rst diff --git a/docs/source/getting_started/toc.rst b/docs/source/getting_started/toc.rst index 695eb044..171893b2 100644 --- a/docs/source/getting_started/toc.rst +++ b/docs/source/getting_started/toc.rst @@ -3,7 +3,7 @@ Getting Started .. toctree:: - setup + buildexe_setup buildexe_getting_started all_compile_options all_default_build_options From 0f2146e90f8f06513631a2bf587daf99c7b13f5b Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 06:19:42 -0800 Subject: [PATCH 58/65] Renamed file --- ...buildexe_getting_started.rst => buildexe_script_example.rst} | 0 docs/source/getting_started/toc.rst | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename docs/source/getting_started/{buildexe_getting_started.rst => buildexe_script_example.rst} (100%) diff --git a/docs/source/getting_started/buildexe_getting_started.rst b/docs/source/getting_started/buildexe_script_example.rst similarity index 100% rename from docs/source/getting_started/buildexe_getting_started.rst rename to docs/source/getting_started/buildexe_script_example.rst diff --git a/docs/source/getting_started/toc.rst b/docs/source/getting_started/toc.rst index 171893b2..719b75c0 100644 --- a/docs/source/getting_started/toc.rst +++ b/docs/source/getting_started/toc.rst @@ -4,7 +4,7 @@ Getting Started .. toctree:: buildexe_setup - buildexe_getting_started + buildexe_script_example all_compile_options all_default_build_options From a9708fb7ed4840f71f0956acbbfd35172e707605 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 06:22:14 -0800 Subject: [PATCH 59/65] Added buildexe_immediate_example file --- docs/source/getting_started/buildexe_immediate_example.rst | 2 ++ docs/source/getting_started/toc.rst | 1 + 2 files changed, 3 insertions(+) create mode 100644 docs/source/getting_started/buildexe_immediate_example.rst diff --git a/docs/source/getting_started/buildexe_immediate_example.rst b/docs/source/getting_started/buildexe_immediate_example.rst new file mode 100644 index 00000000..e9360953 --- /dev/null +++ b/docs/source/getting_started/buildexe_immediate_example.rst @@ -0,0 +1,2 @@ +BuildExe "Immediate" example +============================= diff --git a/docs/source/getting_started/toc.rst b/docs/source/getting_started/toc.rst index 719b75c0..8cc3fae0 100644 --- a/docs/source/getting_started/toc.rst +++ b/docs/source/getting_started/toc.rst @@ -5,6 +5,7 @@ Getting Started buildexe_setup buildexe_script_example + buildexe_immediate_example all_compile_options all_default_build_options From a49aa49a52b155a95d38852cef45d42fe72bcffe Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 06:24:25 -0800 Subject: [PATCH 60/65] Update toc.rst --- docs/source/getting_started/toc.rst | 8 -------- 1 file changed, 8 deletions(-) diff --git a/docs/source/getting_started/toc.rst b/docs/source/getting_started/toc.rst index 8cc3fae0..e75570d6 100644 --- a/docs/source/getting_started/toc.rst +++ b/docs/source/getting_started/toc.rst @@ -8,11 +8,3 @@ Getting Started buildexe_immediate_example all_compile_options all_default_build_options - -Usage through CMake -------------------- - -Walkthroughs -------------- - -.. note:: Add walkthroughs and example snippets of increasing complexity From fc6d20cc4bf3f19b80961c12a7d17423fe322980 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 06:55:18 -0800 Subject: [PATCH 61/65] Update buildexe_script_example.rst --- .../buildexe_script_example.rst | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/source/getting_started/buildexe_script_example.rst b/docs/source/getting_started/buildexe_script_example.rst index 04651f88..f7cfded2 100644 --- a/docs/source/getting_started/buildexe_script_example.rst +++ b/docs/source/getting_started/buildexe_script_example.rst @@ -71,6 +71,10 @@ We then setup our main **toolchain**-**target** pairs. Highlighted below * Specify your compatible target * Every specific target is meant to use a specific target. * For example: ``ExecutableTarget_gcc`` specialized target can use the ``Toolchain_gcc`` specialized toolchain but not ``Toolchain_msvc``. +* Use the Register ``.Build`` API. We use callbacks here to avoid cluttering our ``int main`` function. + * ``arg_gcc.state`` contains our ``build`` and ``test`` values passed in from ``build.toml`` (see below). The ``.Build`` API conditionally selects the target at run time. + * **IMPORTANT** Please do not forget to invoke the Target ``.Build`` API. This API registers the various ``CompileCommandTasks`` and ``LinkCommandTasks``. + * **IMPORTANT** In line with the above statement, Once the Target ``.Build`` API has been executed (tasks have been registered), do not attempt to add more information to the Targets. Internally the ``.Build`` API locks the target from accepting further input and any attempt to do so will ``std::terminate`` your program (this is by design). .. code-block:: cpp :linenos: @@ -155,6 +159,21 @@ Write your ``compile.toml`` file [script] configs = ["build.toml"] +* ``root_dir`` tells BuildExe your project root directory relative from where it is invoked and ``build_dir`` tells BuildExe that the built artifacts should be inserted in this directory relative from where it is invoked. +* ``clean`` deletes your ``build_dir`` completely for a fresh setup. +* ``mode`` consists of **script** and **immediate** mode. See the **Basic Procedure** uml diagrams for a better understanding of the differences and purpose. + * Script Mode: :doc:`buildexe_script_example` + * Immediate Mode: :doc:`buildexe_immediate_example` +* Setup your target information + * ``name`` of your compiled "script" executable + * ``type`` MUST always be **executable** in script mode + * ``relative_to_root`` is a QOL feature to point to a path inside your root where the build "scripts" reside. + * ``srcs`` and equivalent are files that you want to compile. Please see :doc:`all_compile_options` for a full list of target options and inputs for script mode +* [script] submodule + * ``configs`` are .toml files passed to our compiled "script" executable. Please see :doc:`all_default_build_options` for a full list of default build options. + * The values inside ``configs`` are converted to ``--config [file].toml --config [file2].toml`` and so on and passed with the generated executable. + * In this example: ``./build.helloworld --config build.toml`` is run which generates your targets. + Write your ``build.toml`` file +++++++++++++++++++++++++++++++ @@ -174,3 +193,15 @@ Write your ``build.toml`` file [toolchain.gcc] build = true test = false + +* Please see the ``.cpp`` example above and correlate with these options. +* ``root_dir`` tells BuildExe your project root directory relative from where it is invoked and ``build_dir`` tells BuildExe that the built artifacts should be inserted in this directory relative from where it is invoked. +* ``clean`` invokes your ``clean_cb`` which determines how your build must be cleaned. In this example we delete the ``build_dir`` for a fresh setup. + +* [toolchain.gcc] submodule + * This is a nested submodule of ``toolchain`` -> ``gcc`` -> ``--build``, ``--test`` options and so on. + * The naming convention follows ``toolchain.[name]`` provided when using the ``.AddToolchain`` API. + * In our example: ``args.AddToolchain("gcc", "GCC toolchain", arg_gcc);`` + * The ``build`` and ``test`` values are used by the ``Register`` module. + * In our example ``arg_gcc.state.build`` and ``arg_gcc.state.test`` + * **REASONING** The reason why this has been done is because Buildcc allows your to mix multiple toolchains in a single script. We can now conditionally (at run time) choose the toolchains with which we would want to compile our targets. From 5b4fc75261f4d7cdc59d1ad47481c648fb1afec9 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 07:16:40 -0800 Subject: [PATCH 62/65] Update buildexe_script_example.rst --- docs/source/getting_started/buildexe_script_example.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/source/getting_started/buildexe_script_example.rst b/docs/source/getting_started/buildexe_script_example.rst index f7cfded2..23a3f211 100644 --- a/docs/source/getting_started/buildexe_script_example.rst +++ b/docs/source/getting_started/buildexe_script_example.rst @@ -24,6 +24,12 @@ Since we are writing our scripts in C++ we first need to **compile** our "script build_toml -up-> build_project_exe build_project_exe -right-> hello_world_exe + +.. attention:: Limitation of **script** mode + + We need to compile our build "script" using a **HOST** toolchain. + We cannot use a cross compiler here. + Helloworld "script" example --------------------------- From 3885ae7a0019837cc8f12ed299c2e0a4fe584ba0 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 07:20:57 -0800 Subject: [PATCH 63/65] Update buildexe_immediate_example.rst --- .../buildexe_immediate_example.rst | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/docs/source/getting_started/buildexe_immediate_example.rst b/docs/source/getting_started/buildexe_immediate_example.rst index e9360953..359bf4bb 100644 --- a/docs/source/getting_started/buildexe_immediate_example.rst +++ b/docs/source/getting_started/buildexe_immediate_example.rst @@ -1,2 +1,47 @@ BuildExe "Immediate" example ============================= + +Basic Procedure +---------------- + +BuildExe has an "immediate" mode where it can directly provide us the Target (singular) without going through the intermediate steps that we followed in the "script" mode. + +.. uml:: + + usecase "main.cpp" as main_cpp + usecase "compile.toml" as compile_toml + usecase "host_or_cross_toolchain.toml" as host_or_cross_toolchain + + rectangle "./buildexe" as buildexe_exe + artifact "./hello_world" as hello_world_exe + + main_cpp -right-> buildexe_exe + compile_toml -up-> buildexe_exe + host_or_cross_toolchain -up-> buildexe_exe + buildexe_exe -right-> hello_world_exe + + +What is the point of the "script" mode then? +++++++++++++++++++++++++++++++++++++++++++++ + +The "immediate" mode has a lot of limitations but it is also useful in certain scenarios + +**Limitations** + +* Cannot build more than one target at a time +* No customizability allowed. + * Which means that apart from just building the target you cannot do anything else. + * For example: Setting dependencies between targets, running custom generators, running static analysis tools and so on. + +**Usecase** + +* Simple way to build one target. +* Completely run time dependent. Change your ``build.toml`` file and you can build a new target. +* Very easy to know how a particular target is built. + * For example. In a large project it might be very hard to visualize how a single target is built due to various code generation and library / target dependencies. + * Since .toml is easily readable, we can understand the sources, search directories and flags that the target requires at a glance. +* Can be shipped to customers for a pain free build process i.e removes technical debt. + * Building your artifact is as simple as ``buildexe --config build.toml --config %BUILDCC_HOME/host/host_or_cross_toolchain.toml`` + * build.toml contains the target information. + * host_or_cross_toolchain.toml contains the host/cross toolchain information + * We can combine the two into one .toml file. From ee946df202a8cd5a04203e18ac40032ccdc24671 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 07:26:15 -0800 Subject: [PATCH 64/65] Update buildexe_immediate_example.rst --- .../buildexe_immediate_example.rst | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/docs/source/getting_started/buildexe_immediate_example.rst b/docs/source/getting_started/buildexe_immediate_example.rst index 359bf4bb..9b0e882b 100644 --- a/docs/source/getting_started/buildexe_immediate_example.rst +++ b/docs/source/getting_started/buildexe_immediate_example.rst @@ -45,3 +45,50 @@ The "immediate" mode has a lot of limitations but it is also useful in certain s * build.toml contains the target information. * host_or_cross_toolchain.toml contains the host/cross toolchain information * We can combine the two into one .toml file. + + +Helloworld "immediate" example +------------------------------ + +* Write your ``build.toml`` file +* Invoke ``buildexe`` from the command line from the **[workspace]** folder + * Pay attention to the ``root_dir`` and ``build_dir`` parameters set in your ``build.toml`` file. + * These directories are relative to the directory from which you **invoke** buildexe + +.. code-block:: bash + + ./buildexe --config build.toml --config $BUILDCC_HOME/host/host_toolchain.toml + +* Your target will now be present in ``[build_dir]/[toolchain_name]/[target_name]`` (taken from ``build.toml``) + +Directory structure +++++++++++++++++++++ + +.. uml:: + + @startmindmap + * [workspace] + ** [src] + *** main.cpp + ** build.toml + @endmindmap + +Write your ``build.toml`` file ++++++++++++++++++++++++++++++++ + +.. code-block:: toml + + # Settings + root_dir = "" + build_dir = "_build" + loglevel = "info" + clean = false + + # BuildExe run mode + mode = "immediate" + + # Target information + name = "hello_world" + type = "executable" + relative_to_root = "src" + srcs = ["main.cpp"] From deabae47b72ed6cd414e8080415d86836e3acc8d Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sat, 8 Jan 2022 07:29:56 -0800 Subject: [PATCH 65/65] Added walkthroughs --- docs/source/getting_started/toc.rst | 1 + docs/source/getting_started/walkthroughs.rst | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 docs/source/getting_started/walkthroughs.rst diff --git a/docs/source/getting_started/toc.rst b/docs/source/getting_started/toc.rst index e75570d6..3657d28f 100644 --- a/docs/source/getting_started/toc.rst +++ b/docs/source/getting_started/toc.rst @@ -6,5 +6,6 @@ Getting Started buildexe_setup buildexe_script_example buildexe_immediate_example + walkthroughs all_compile_options all_default_build_options diff --git a/docs/source/getting_started/walkthroughs.rst b/docs/source/getting_started/walkthroughs.rst new file mode 100644 index 00000000..7046f895 --- /dev/null +++ b/docs/source/getting_started/walkthroughs.rst @@ -0,0 +1,13 @@ +Walkthrough Examples +===================== + +.. note:: Provide a gist of the various APIs and features present in BuildCC + +* Simple +* IncludeDirs +* LibDeps +* Flags (Preprocessor, Compile and Link flags) +* Generators +* Target Info +* Custom Targets +* Custom Arguments