From aa1365442b30981dd8109b7b7c7f6880eb9d02f2 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 21:30:56 -0800 Subject: [PATCH 01/62] Update CMakeLists.txt --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ce6173b..7d1368be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,8 @@ option(BUILDCC_FLATBUFFERS_FLATC "Build Flatbuffer::Flatc Compiler" ON) option(BUILDCC_BUILD_AS_SINGLE_LIB "Build all internal libs and modules as part of the buildcc library" ON) option(BUILDCC_BUILD_AS_INTERFACE "Build all internal libs and modules seperately and link" OFF) +option(BUILDCC_BOOTSTRAP_THROUGH_CMAKE "Bootstrap lib buildcc through CMake" OFF) + # NOTE, Conflict with Clang-Tidy on certain compilers option(BUILDCC_PRECOMPILE_HEADERS "Enable Buildcc precompile headers" OFF) option(BUILDCC_EXAMPLES "Enable Buildcc Examples" OFF) @@ -117,3 +119,7 @@ if (${BUILDCC_EXAMPLES}) add_subdirectory(example/hybrid/dep_chaining) add_subdirectory(example/hybrid/target_info) endif() + +if (${BUILDCC_BOOTSTRAP_THROUGH_CMAKE}) + add_subdirectory(bootstrap) +endif() From 623d2e8cd38519da696668b0a4708a94ba326e12 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 21:33:02 -0800 Subject: [PATCH 02/62] Update CMakeLists.txt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d1368be..5e13b906 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ option(BUILDCC_FLATBUFFERS_FLATC "Build Flatbuffer::Flatc Compiler" ON) option(BUILDCC_BUILD_AS_SINGLE_LIB "Build all internal libs and modules as part of the buildcc library" ON) option(BUILDCC_BUILD_AS_INTERFACE "Build all internal libs and modules seperately and link" OFF) -option(BUILDCC_BOOTSTRAP_THROUGH_CMAKE "Bootstrap lib buildcc through CMake" OFF) +option(BUILDCC_BOOTSTRAP_THROUGH_CMAKE "Bootstrap buildcc through CMake" OFF) # NOTE, Conflict with Clang-Tidy on certain compilers option(BUILDCC_PRECOMPILE_HEADERS "Enable Buildcc precompile headers" OFF) From a61a2dae2d7093cdcfe8fd86dbed8742e3a1f173 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 21:33:59 -0800 Subject: [PATCH 03/62] Update CMakeLists.txt --- CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e13b906..dc0fc26b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,15 +72,10 @@ include(cmake/tool/doxygen.cmake) # Libraries include(cmake/target/flatbuffers.cmake) - include(cmake/target/fmt.cmake) - include(cmake/target/spdlog.cmake) - include(cmake/target/cli11.cmake) - include(cmake/target/taskflow.cmake) - include(cmake/target/tpl.cmake) if (${TESTING}) From 25eb74bfce325026dca0c7d8c84221417ac49712 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 21:39:52 -0800 Subject: [PATCH 04/62] Added main.buildcc.cpp and config_linux.toml --- bootstrap/CMakeLists.txt | 19 ++ bootstrap/config_linux.toml | 9 + bootstrap/main.buildcc.cpp | 430 ++++++++++++++++++++++++++++++++++++ 3 files changed, 458 insertions(+) create mode 100644 bootstrap/CMakeLists.txt create mode 100644 bootstrap/config_linux.toml create mode 100644 bootstrap/main.buildcc.cpp diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt new file mode 100644 index 00000000..af4f13d4 --- /dev/null +++ b/bootstrap/CMakeLists.txt @@ -0,0 +1,19 @@ +add_executable(buildcc_lib_bootstrap + main.buildcc.cpp +) +target_link_libraries(buildcc_lib_bootstrap PRIVATE buildcc) +# TODO, Add this only if MINGW is used +# https://github.com/msys2/MINGW-packages/issues/2303 +# Similar issue when adding the Taskflow library +if (${MINGW}) + message(WARNING "-Wl,--allow-multiple-definition for MINGW") + target_link_options(buildcc_lib_bootstrap PRIVATE -Wl,--allow-multiple-definition) +endif() + +add_custom_target(run_buildcc_lib_bootstrap_linux + COMMAND buildcc_lib_bootstrap --help-all + COMMAND buildcc_lib_bootstrap --config ${CMAKE_CURRENT_SOURCE_DIR}/config_linux.toml + # COMMAND dot -Tpng graph.dot -o graph.PNG + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + VERBATIM USES_TERMINAL +) diff --git a/bootstrap/config_linux.toml b/bootstrap/config_linux.toml new file mode 100644 index 00000000..4697c723 --- /dev/null +++ b/bootstrap/config_linux.toml @@ -0,0 +1,9 @@ +root_dir=".." +build_dir="../_build_bootstrap" + +loglevel="trace" +clean=false + +[toolchain.gcc] +build = true +test = true diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp new file mode 100644 index 00000000..3c4a7ed4 --- /dev/null +++ b/bootstrap/main.buildcc.cpp @@ -0,0 +1,430 @@ +#include "buildcc.h" +#include "env/host_compiler.h" +#include "env/host_os.h" +#include "target/generator.h" +#include "targets/target_generic.h" + +using namespace buildcc; + +static void clean_cb(); + +static void flatc_cb(BaseTarget &target); +static void schema_gen_cb(base::Generator &generator, + const BaseTarget &flatc_exe); + +static void flatbuffers_ho_cb(TargetInfo &info); +static void cli11_ho_cb(TargetInfo &info); +static void fmt_ho_cb(TargetInfo &info); +static void spdlog_ho_cb(TargetInfo &info); +static void taskflow_ho_cb(TargetInfo &info); +static void tpl_cb(BaseTarget &target); + +static void buildcc_cb(BaseTarget &target, const base::Generator &schema_gen, + const TargetInfo &flatbuffers_ho, + const TargetInfo &fmt_ho, const TargetInfo &spdlog_ho, + const TargetInfo &cli11_ho, + const TargetInfo &taskflow_ho, const BaseTarget &tpl); + +static void hybrid_simple_example_cb(BaseTarget &target, + const BaseTarget &libbuildcc); + +int main(int argc, char **argv) noexcept { + Args args; + Args::ToolchainArg arg_gcc; + args.AddToolchain("gcc", "Host GCC Toolchain", arg_gcc); + args.Parse(argc, argv); + + Register reg(args); + reg.Clean(clean_cb); + + Toolchain_gcc gcc; + + // Flatc Executable + ExecutableTarget_generic flatc_exe("flatc", gcc, "third_party/flatbuffers"); + reg.Build(arg_gcc.state, flatc_cb, flatc_exe); + + // Schema + base::Generator schema_gen("schema_gen", "buildcc/schema"); + reg.Build(schema_gen_cb, schema_gen, flatc_exe); + reg.Dep(schema_gen, flatc_exe); + + // Flatbuffers HO lib + TargetInfo flatbuffers_ho_lib("third_party/flatbuffers"); + reg.Callback(flatbuffers_ho_cb, flatbuffers_ho_lib); + + // CLI11 HO lib + TargetInfo cli11_ho_lib("third_party/CLI11"); + reg.Callback(cli11_ho_cb, cli11_ho_lib); + + // fmt HO lib + TargetInfo fmt_ho_lib("third_party/fmt"); + reg.Callback(fmt_ho_cb, fmt_ho_lib); + + // spdlog HO lib + TargetInfo spdlog_ho_lib("third_party/spdlog"); + reg.Callback(spdlog_ho_cb, spdlog_ho_lib); + + // taskflow HO lib + TargetInfo taskflow_ho_lib("third_party/taskflow"); + reg.Callback(taskflow_ho_cb, taskflow_ho_lib); + + // Tiny-process-library lib + // TODO, Make this a generic selection between StaticTarget and DynamicTarget + StaticTarget_generic tpl_lib("libtpl", gcc, + "third_party/tiny-process-library"); + reg.Build(arg_gcc.state, tpl_cb, tpl_lib); + + // TODO, Make this a generic selection between StaticTarget and DynamicTarget + StaticTarget_generic buildcc_lib("libbuildcc", gcc, "buildcc"); + reg.Build(arg_gcc.state, buildcc_cb, buildcc_lib, schema_gen, + flatbuffers_ho_lib, fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib, + taskflow_ho_lib, tpl_lib); + reg.Dep(buildcc_lib, schema_gen); + reg.Dep(buildcc_lib, tpl_lib); + + ExecutableTarget_generic buildcc_hybrid_simple_example( + "buildcc_hybrid_simple_example", gcc, "example/hybrid/simple"); + reg.Build(arg_gcc.state, hybrid_simple_example_cb, + buildcc_hybrid_simple_example, buildcc_lib); + reg.Dep(buildcc_hybrid_simple_example, buildcc_lib); + + // reg.Test(arg_gcc.state, "{executable} --help", + // buildcc_hybrid_simple_example, + // { + // {"example_folder", + // buildcc_hybrid_simple_example.GetTargetRootDir().string()}, + // }); + reg.Test(arg_gcc.state, + "{executable} --config {example_folder}/build_linux.toml", + buildcc_hybrid_simple_example, + TestConfig( + { + {"example_folder", + buildcc_hybrid_simple_example.GetTargetRootDir().string()}, + }, + buildcc_hybrid_simple_example.GetTargetRootDir())); + + // ExecutableTarget_generic tpl_io_test("tpl_io_test", gcc, + // "third_party/tiny-process-library"); + // reg.Build( + // arg_gcc.state, + // [](BaseTarget &target, const BaseTarget &tpl_lib) { + // // target.AddSource("tests/io_test.cpp"); + // target.AddSource("tests/multithread_test.cpp"); + + // for (const auto &idir : tpl_lib.GetCurrentIncludeDirs()) { + // target.AddIncludeDir(idir); + // } + // target.AddLibDep(tpl_lib); + // target.Build(); + // }, + // tpl_io_test, tpl_lib); + // reg.Dep(tpl_io_test, tpl_lib); + // reg.Test(arg_gcc.state, "{executable}", tpl_io_test); + + reg.RunBuild(); + + // fs::current_path(buildcc_hybrid_simple_example.GetTargetRootDir()); + reg.RunTest(); + // fs::current_path(env::get_project_root_dir()); + + // - Clang Compile Commands + plugin::ClangCompileCommands({&buildcc_lib}).Generate(); + + // - Plugin Graph + std::string output = reg.GetTaskflow().dump(); + const bool saved = env::save_file("graph.dot", output, false); + env::assert_fatal(saved, "Could not save graph.dot file"); + + return 0; + + return 0; +} + +static void clean_cb() {} + +static void flatc_cb(BaseTarget &target) { + std::vector sources{ + "code_generators.cpp", + "flatc_main.cpp", + "flatc.cpp", + "idl_gen_cpp.cpp", + "idl_gen_csharp.cpp", + "idl_gen_dart.cpp", + "idl_gen_fbs.cpp", + "idl_gen_go.cpp", + "idl_gen_grpc.cpp", + "idl_gen_java.cpp", + "idl_gen_json_schema.cpp", + "idl_gen_kotlin.cpp", + "idl_gen_lobster.cpp", + "idl_gen_lua.cpp", + "idl_gen_php.cpp", + "idl_gen_python.cpp", + "idl_gen_rust.cpp", + "idl_gen_swift.cpp", + "idl_gen_text.cpp", + "idl_gen_ts.cpp", + "idl_parser.cpp", + "reflection.cpp", + "util.cpp", + }; + std::for_each(sources.cbegin(), sources.cend(), + [&](const auto &s) { target.AddSource(s, "src"); }); + target.GlobSources("grpc/src/compiler"); + + target.AddIncludeDir("include"); + target.AddIncludeDir("grpc"); + + target.GlobHeaders("include/flatbuffers"); + target.GlobHeaders("grpc/src/compiler"); + + std::vector preprocessor_flags{ + "-DFLATBUFFERS_LOCALE_INDEPENDENT=0", + "-DNDEBUG", + }; + + std::for_each(preprocessor_flags.cbegin(), preprocessor_flags.cend(), + [&](const auto &f) { target.AddPreprocessorFlag(f); }); + + std::vector cpp_compile_flags{ + "-std=c++17", + "-Os", + "-Wall", + "-pedantic", + "-Werror", + "-Wextra", + "-Werror=shadow", + "-faligned-new", + "-Werror=implicit-fallthrough=2", + "-Wunused-result", + "-Werror=unused-result", + "-Wunused-parameter", + "-Werror=unused-parameter", + "-fsigned-char", + "-Wold-style-cast", + "-Winvalid-pch", + }; + + std::for_each(cpp_compile_flags.cbegin(), cpp_compile_flags.cend(), + [&](const auto &f) { target.AddCppCompileFlag(f); }); + + // TODO, PCH here + + target.Build(); +} + +static void schema_gen_cb(base::Generator &generator, + const BaseTarget &flatc_exe) { + generator.AddInput("{gen_root_dir}/path.fbs", "path_fbs"); + generator.AddInput("{gen_root_dir}/generator.fbs", "generator_fbs"); + generator.AddInput("{gen_root_dir}/target.fbs", "target_fbs"); + + generator.AddOutput("{gen_build_dir}/path_generated.h"); + generator.AddOutput("{gen_build_dir}/generator_generated.h"); + generator.AddOutput("{gen_build_dir}/target_generated.h"); + + generator.AddDefaultArguments({ + {"flatc_compiler", fmt::format("{}", flatc_exe.GetTargetPath())}, + }); + // generator.AddCommand("{flatc_compiler} --help"); + generator.AddCommand( + "{flatc_compiler} -o {gen_build_dir} -I {gen_root_dir} --gen-object-api " + "--cpp {path_fbs} {generator_fbs} {target_fbs}"); + + generator.Build(); +} + +static void flatbuffers_ho_cb(TargetInfo &info) { + info.AddIncludeDir("include"); + info.GlobHeaders("include/flatbuffers"); + // TODO, Add PCH +} + +static void cli11_ho_cb(TargetInfo &info) { + info.AddIncludeDir("include"); + info.GlobHeaders("include/CLI"); + // TODO, Add PCH +} + +static void fmt_ho_cb(TargetInfo &info) { + info.AddIncludeDir("include"); + info.GlobHeaders("include/fmt"); +} + +static void spdlog_ho_cb(TargetInfo &info) { + info.AddIncludeDir("include"); + info.GlobHeaders("include/spdlog"); + info.GlobHeaders("include/spdlog/cfg"); + info.GlobHeaders("include/spdlog/details"); + info.GlobHeaders("include/spdlog/fmt"); + info.GlobHeaders("include/spdlog/sinks"); +} + +static void taskflow_ho_cb(TargetInfo &info) { + info.AddIncludeDir(""); + info.GlobHeaders("taskflow"); + info.GlobHeaders("taskflow/core"); + info.GlobHeaders("taskflow/core/algorithm"); + // TODO, Track more header files +} + +static void tpl_cb(BaseTarget &target) { + target.AddSource("process.cpp"); + target.AddIncludeDir(""); + target.AddHeader("process.hpp"); + + // MinGW (GCC), MSVC, Clang + if constexpr (env::is_win()) { + target.AddSource("process_win.cpp"); + // TODO, MSVC + // TODO, Clang + switch (target.GetToolchain().GetId()) { + case ToolchainId::Gcc: + case ToolchainId::MinGW: + target.AddCppCompileFlag("-std=c++17"); + target.AddCppCompileFlag("-Wall"); + target.AddCppCompileFlag("-Wextra"); + break; + default: + break; + } + } + + if constexpr (env::is_linux()) { + // TODO, GCC + // TODO, Clang + } + + // LOG DUMP + for (const auto &d : target.GetCurrentSourceFiles()) { + env::log_info(__FUNCTION__, d.string()); + } + + target.Build(); +} + +static void buildcc_cb(BaseTarget &target, const base::Generator &schema_gen, + const TargetInfo &flatbuffers_ho, + const TargetInfo &fmt_ho, const TargetInfo &spdlog_ho, + const TargetInfo &cli11_ho, + const TargetInfo &taskflow_ho, const BaseTarget &tpl) { + // NOTE, Build as single lib + target.AddIncludeDir("", true); + const std::string &schema_build_dir = + schema_gen.GetValueByIdentifier("gen_build_dir"); + target.AddIncludeDirAbsolute(schema_build_dir, true); + + // ENV + target.GlobSources("lib/env/src"); + target.AddIncludeDir("lib/env/include"); + target.GlobHeaders("lib/env/include/env"); + + // COMMAND + target.GlobSources("lib/command/src"); + target.AddIncludeDir("lib/command/include"); + target.GlobHeaders("lib/command/include/command"); + + // TOOLCHAIN + target.AddIncludeDir("lib/toolchain/include"); + target.GlobHeaders("lib/toolchain/include/toolchain"); + + // TARGET + target.GlobSources("lib/target/src/common"); + target.GlobSources("lib/target/src/generator"); + target.GlobSources("lib/target/src/api"); + target.GlobSources("lib/target/src/target"); + target.GlobSources("lib/target/src/target/friend"); + + target.AddIncludeDir("lib/target/include"); + target.GlobHeaders("lib/target/include/target"); + target.GlobHeaders("lib/target/include/target/api"); + target.GlobHeaders("lib/target/include/target/base"); + target.GlobHeaders("lib/target/include/target/common"); + target.GlobHeaders("lib/target/include/target/friend"); + target.GlobHeaders("lib/target/include/target/interface"); + target.GlobHeaders("lib/target/include/target/private"); + + // ARGS + target.GlobSources("lib/args/src"); + target.AddIncludeDir("lib/args/include"); + target.GlobHeaders("lib/args/include/args"); + + // Specialized Toolchains + target.AddIncludeDir("toolchains/include"); + target.GlobHeaders("toolchains/include/toolchains"); + + // Specialized Targets + target.AddIncludeDir("targets/include"); + target.GlobHeaders("targets/include/targets"); + + // Plugins + target.GlobSources("plugins/src"); + target.AddIncludeDir("plugins/include"); + target.GlobHeaders("plugins/include/plugins"); + + // Third Party libraries + + const std::initializer_list kInsertOptions{ + SyncOption::IncludeDirs, + SyncOption::HeaderFiles, + }; + + // FLATBUFFERS HO + target.Insert(flatbuffers_ho, kInsertOptions); + + // FMT HO + target.Insert(fmt_ho, kInsertOptions); + + // SPDLOG HO + target.Insert(spdlog_ho, kInsertOptions); + + // CLI11 HO + target.Insert(cli11_ho, kInsertOptions); + + // TASKFLOW HO + target.Insert(taskflow_ho, kInsertOptions); + + // TPL LIB + target.AddLibDep(tpl); + target.Insert(tpl, kInsertOptions); + + // TODO, ADD GCC flags + // TODO, ADD MSVC flags + if constexpr (env::is_win()) { + if (target.GetToolchain().GetId() == ToolchainId::Gcc) { + target.AddLinkFlag("-Wl,--allow-multiple-definition"); + } + } + + switch (target.GetToolchain().GetId()) { + case ToolchainId::Gcc: { + target.AddPreprocessorFlag("-DFMT_HEADER_ONLY=1"); + target.AddPreprocessorFlag("-DSPDLOG_FMT_EXTERNAL"); + target.AddCppCompileFlag("-std=c++17"); + target.AddCppCompileFlag("-Wall"); + target.AddCppCompileFlag("-Wextra"); + } break; + case ToolchainId::Msvc: { + } break; + default: + break; + } + + target.Build(); +} + +static void hybrid_simple_example_cb(BaseTarget &target, + const BaseTarget &libbuildcc) { + target.Insert(libbuildcc, { + SyncOption::PreprocessorFlags, + SyncOption::CppCompileFlags, + SyncOption::LinkFlags, + SyncOption::HeaderFiles, + SyncOption::IncludeDirs, + SyncOption::LibDeps, + }); + target.AddSource("build.cpp"); + target.AddLibDep(libbuildcc); + target.Build(); +} From b2ae334e887b9a9b715cb413764fa067dd4593e7 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 21:40:34 -0800 Subject: [PATCH 05/62] Create .gitignore --- bootstrap/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 bootstrap/.gitignore diff --git a/bootstrap/.gitignore b/bootstrap/.gitignore new file mode 100644 index 00000000..cf658897 --- /dev/null +++ b/bootstrap/.gitignore @@ -0,0 +1 @@ +*.dot From f216384a15aaa23abe1408626562a193bd2b5191 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 21:44:36 -0800 Subject: [PATCH 06/62] Update main.buildcc.cpp --- bootstrap/main.buildcc.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index 3c4a7ed4..abbacc3b 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -1,14 +1,25 @@ +/* + * Copyright 2021 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" -#include "env/host_compiler.h" -#include "env/host_os.h" -#include "target/generator.h" -#include "targets/target_generic.h" using namespace buildcc; static void clean_cb(); -static void flatc_cb(BaseTarget &target); static void schema_gen_cb(base::Generator &generator, const BaseTarget &flatc_exe); From e366be512b3a832beb9b69728e847c1f791823f2 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 21:51:45 -0800 Subject: [PATCH 07/62] Shifted flatc_cb to build_flatbuffers.cpp --- bootstrap/CMakeLists.txt | 7 ++ .../include/bootstrap/buildcc_flatbuffers.h | 23 +++++ bootstrap/main.buildcc.cpp | 73 +------------- bootstrap/src/build_flatbuffers.cpp | 98 +++++++++++++++++++ 4 files changed, 130 insertions(+), 71 deletions(-) create mode 100644 bootstrap/include/bootstrap/buildcc_flatbuffers.h create mode 100644 bootstrap/src/build_flatbuffers.cpp diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt index af4f13d4..96e6912b 100644 --- a/bootstrap/CMakeLists.txt +++ b/bootstrap/CMakeLists.txt @@ -1,7 +1,14 @@ add_executable(buildcc_lib_bootstrap main.buildcc.cpp ) +target_sources(buildcc_lib_bootstrap PRIVATE + src/build_flatbuffers.cpp +) +target_include_directories(buildcc_lib_bootstrap PRIVATE + include +) target_link_libraries(buildcc_lib_bootstrap PRIVATE buildcc) + # TODO, Add this only if MINGW is used # https://github.com/msys2/MINGW-packages/issues/2303 # Similar issue when adding the Taskflow library diff --git a/bootstrap/include/bootstrap/buildcc_flatbuffers.h b/bootstrap/include/bootstrap/buildcc_flatbuffers.h new file mode 100644 index 00000000..9a7d0c03 --- /dev/null +++ b/bootstrap/include/bootstrap/buildcc_flatbuffers.h @@ -0,0 +1,23 @@ +/* + * Copyright 2021 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 flatc_cb(BaseTarget &target); + +} diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index abbacc3b..9f88c2ef 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -16,6 +16,8 @@ #include "buildcc.h" +#include "bootstrap/buildcc_flatbuffers.h" + using namespace buildcc; static void clean_cb(); @@ -154,77 +156,6 @@ int main(int argc, char **argv) noexcept { static void clean_cb() {} -static void flatc_cb(BaseTarget &target) { - std::vector sources{ - "code_generators.cpp", - "flatc_main.cpp", - "flatc.cpp", - "idl_gen_cpp.cpp", - "idl_gen_csharp.cpp", - "idl_gen_dart.cpp", - "idl_gen_fbs.cpp", - "idl_gen_go.cpp", - "idl_gen_grpc.cpp", - "idl_gen_java.cpp", - "idl_gen_json_schema.cpp", - "idl_gen_kotlin.cpp", - "idl_gen_lobster.cpp", - "idl_gen_lua.cpp", - "idl_gen_php.cpp", - "idl_gen_python.cpp", - "idl_gen_rust.cpp", - "idl_gen_swift.cpp", - "idl_gen_text.cpp", - "idl_gen_ts.cpp", - "idl_parser.cpp", - "reflection.cpp", - "util.cpp", - }; - std::for_each(sources.cbegin(), sources.cend(), - [&](const auto &s) { target.AddSource(s, "src"); }); - target.GlobSources("grpc/src/compiler"); - - target.AddIncludeDir("include"); - target.AddIncludeDir("grpc"); - - target.GlobHeaders("include/flatbuffers"); - target.GlobHeaders("grpc/src/compiler"); - - std::vector preprocessor_flags{ - "-DFLATBUFFERS_LOCALE_INDEPENDENT=0", - "-DNDEBUG", - }; - - std::for_each(preprocessor_flags.cbegin(), preprocessor_flags.cend(), - [&](const auto &f) { target.AddPreprocessorFlag(f); }); - - std::vector cpp_compile_flags{ - "-std=c++17", - "-Os", - "-Wall", - "-pedantic", - "-Werror", - "-Wextra", - "-Werror=shadow", - "-faligned-new", - "-Werror=implicit-fallthrough=2", - "-Wunused-result", - "-Werror=unused-result", - "-Wunused-parameter", - "-Werror=unused-parameter", - "-fsigned-char", - "-Wold-style-cast", - "-Winvalid-pch", - }; - - std::for_each(cpp_compile_flags.cbegin(), cpp_compile_flags.cend(), - [&](const auto &f) { target.AddCppCompileFlag(f); }); - - // TODO, PCH here - - target.Build(); -} - static void schema_gen_cb(base::Generator &generator, const BaseTarget &flatc_exe) { generator.AddInput("{gen_root_dir}/path.fbs", "path_fbs"); diff --git a/bootstrap/src/build_flatbuffers.cpp b/bootstrap/src/build_flatbuffers.cpp new file mode 100644 index 00000000..74476d03 --- /dev/null +++ b/bootstrap/src/build_flatbuffers.cpp @@ -0,0 +1,98 @@ +/* + * Copyright 2021 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 "bootstrap/buildcc_flatbuffers.h" + +namespace { + +const std::vector kFlatcSources{ + "code_generators.cpp", + "flatc_main.cpp", + "flatc.cpp", + "idl_gen_cpp.cpp", + "idl_gen_csharp.cpp", + "idl_gen_dart.cpp", + "idl_gen_fbs.cpp", + "idl_gen_go.cpp", + "idl_gen_grpc.cpp", + "idl_gen_java.cpp", + "idl_gen_json_schema.cpp", + "idl_gen_kotlin.cpp", + "idl_gen_lobster.cpp", + "idl_gen_lua.cpp", + "idl_gen_php.cpp", + "idl_gen_python.cpp", + "idl_gen_rust.cpp", + "idl_gen_swift.cpp", + "idl_gen_text.cpp", + "idl_gen_ts.cpp", + "idl_parser.cpp", + "reflection.cpp", + "util.cpp", +}; + +const std::vector kFlatcPreprocessorFlags{ + "-DFLATBUFFERS_LOCALE_INDEPENDENT=0", + "-DNDEBUG", +}; + +const std::vector kFlatcCppCompileFlags{ + "-std=c++17", + "-Os", + "-Wall", + "-pedantic", + "-Werror", + "-Wextra", + "-Werror=shadow", + "-faligned-new", + "-Werror=implicit-fallthrough=2", + "-Wunused-result", + "-Werror=unused-result", + "-Wunused-parameter", + "-Werror=unused-parameter", + "-fsigned-char", + "-Wold-style-cast", + "-Winvalid-pch", +}; + +} // namespace + +namespace buildcc { + +void flatc_cb(BaseTarget &target) { + std::for_each(kFlatcSources.cbegin(), kFlatcSources.cend(), + [&](const auto &s) { target.AddSource(s, "src"); }); + target.GlobSources("grpc/src/compiler"); + + target.AddIncludeDir("include"); + target.AddIncludeDir("grpc"); + + target.GlobHeaders("include/flatbuffers"); + target.GlobHeaders("grpc/src/compiler"); + + std::for_each(kFlatcPreprocessorFlags.cbegin(), + kFlatcPreprocessorFlags.cend(), + [&](const auto &f) { target.AddPreprocessorFlag(f); }); + + std::for_each(kFlatcCppCompileFlags.cbegin(), kFlatcCppCompileFlags.cend(), + [&](const auto &f) { target.AddCppCompileFlag(f); }); + + // TODO, PCH here + + target.Build(); +} + +} // namespace buildcc From 02c7044844c9c6cce7e99e83b1dd35af100d9312 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 21:52:40 -0800 Subject: [PATCH 08/62] Renamed to build_flatc_exe_cb --- bootstrap/include/bootstrap/buildcc_flatbuffers.h | 2 +- bootstrap/main.buildcc.cpp | 2 +- bootstrap/src/build_flatbuffers.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bootstrap/include/bootstrap/buildcc_flatbuffers.h b/bootstrap/include/bootstrap/buildcc_flatbuffers.h index 9a7d0c03..78201fe9 100644 --- a/bootstrap/include/bootstrap/buildcc_flatbuffers.h +++ b/bootstrap/include/bootstrap/buildcc_flatbuffers.h @@ -18,6 +18,6 @@ namespace buildcc { -void flatc_cb(BaseTarget &target); +void build_flatc_exe_cb(BaseTarget &target); } diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index 9f88c2ef..251e41b2 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -54,7 +54,7 @@ int main(int argc, char **argv) noexcept { // Flatc Executable ExecutableTarget_generic flatc_exe("flatc", gcc, "third_party/flatbuffers"); - reg.Build(arg_gcc.state, flatc_cb, flatc_exe); + reg.Build(arg_gcc.state, build_flatc_exe_cb, flatc_exe); // Schema base::Generator schema_gen("schema_gen", "buildcc/schema"); diff --git a/bootstrap/src/build_flatbuffers.cpp b/bootstrap/src/build_flatbuffers.cpp index 74476d03..acd83969 100644 --- a/bootstrap/src/build_flatbuffers.cpp +++ b/bootstrap/src/build_flatbuffers.cpp @@ -72,7 +72,7 @@ const std::vector kFlatcCppCompileFlags{ namespace buildcc { -void flatc_cb(BaseTarget &target) { +void build_flatc_exe_cb(BaseTarget &target) { std::for_each(kFlatcSources.cbegin(), kFlatcSources.cend(), [&](const auto &s) { target.AddSource(s, "src"); }); target.GlobSources("grpc/src/compiler"); From c315f99b57309b176c629d4eeac46156bf4beeed Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 21:54:52 -0800 Subject: [PATCH 09/62] Shifted flatbuffers_ho_cb to buildcc_flatbuffers.h --- bootstrap/include/bootstrap/buildcc_flatbuffers.h | 3 ++- bootstrap/main.buildcc.cpp | 7 ------- bootstrap/src/build_flatbuffers.cpp | 8 +++++++- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bootstrap/include/bootstrap/buildcc_flatbuffers.h b/bootstrap/include/bootstrap/buildcc_flatbuffers.h index 78201fe9..bd2a09c6 100644 --- a/bootstrap/include/bootstrap/buildcc_flatbuffers.h +++ b/bootstrap/include/bootstrap/buildcc_flatbuffers.h @@ -19,5 +19,6 @@ namespace buildcc { void build_flatc_exe_cb(BaseTarget &target); +void flatbuffers_ho_cb(TargetInfo &info); -} +} // namespace buildcc diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index 251e41b2..d694a78c 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -25,7 +25,6 @@ static void clean_cb(); static void schema_gen_cb(base::Generator &generator, const BaseTarget &flatc_exe); -static void flatbuffers_ho_cb(TargetInfo &info); static void cli11_ho_cb(TargetInfo &info); static void fmt_ho_cb(TargetInfo &info); static void spdlog_ho_cb(TargetInfo &info); @@ -177,12 +176,6 @@ static void schema_gen_cb(base::Generator &generator, generator.Build(); } -static void flatbuffers_ho_cb(TargetInfo &info) { - info.AddIncludeDir("include"); - info.GlobHeaders("include/flatbuffers"); - // TODO, Add PCH -} - static void cli11_ho_cb(TargetInfo &info) { info.AddIncludeDir("include"); info.GlobHeaders("include/CLI"); diff --git a/bootstrap/src/build_flatbuffers.cpp b/bootstrap/src/build_flatbuffers.cpp index acd83969..e39a9b2a 100644 --- a/bootstrap/src/build_flatbuffers.cpp +++ b/bootstrap/src/build_flatbuffers.cpp @@ -90,9 +90,15 @@ void build_flatc_exe_cb(BaseTarget &target) { std::for_each(kFlatcCppCompileFlags.cbegin(), kFlatcCppCompileFlags.cend(), [&](const auto &f) { target.AddCppCompileFlag(f); }); - // TODO, PCH here + // TODO, Add PCH target.Build(); } +void flatbuffers_ho_cb(TargetInfo &info) { + info.AddIncludeDir("include"); + info.GlobHeaders("include/flatbuffers"); + // TODO, Add PCH +} + } // namespace buildcc From 438abcba13a516443cbdbae3d9c25683cd79bf0c Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 21:58:14 -0800 Subject: [PATCH 10/62] Update buildcc_flatbuffers.h --- bootstrap/include/bootstrap/buildcc_flatbuffers.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bootstrap/include/bootstrap/buildcc_flatbuffers.h b/bootstrap/include/bootstrap/buildcc_flatbuffers.h index bd2a09c6..e9e60e69 100644 --- a/bootstrap/include/bootstrap/buildcc_flatbuffers.h +++ b/bootstrap/include/bootstrap/buildcc_flatbuffers.h @@ -14,6 +14,9 @@ * limitations under the License. */ +#ifndef BOOTSTRAP_BUILDCC_FLATBUFFERS_H_ +#define BOOTSTRAP_BUILDCC_FLATBUFFERS_H_ + #include "buildcc.h" namespace buildcc { @@ -22,3 +25,5 @@ void build_flatc_exe_cb(BaseTarget &target); void flatbuffers_ho_cb(TargetInfo &info); } // namespace buildcc + +#endif From e4ead8219daddb8adea87b5e679e664c6e952d8f Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 22:01:59 -0800 Subject: [PATCH 11/62] Added buildcc_cli11 --- bootstrap/CMakeLists.txt | 1 + bootstrap/include/bootstrap/buildcc_cli11.h | 28 +++++++++++++++++++++ bootstrap/main.buildcc.cpp | 8 +----- bootstrap/src/buildcc_cli11.cpp | 25 ++++++++++++++++++ 4 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 bootstrap/include/bootstrap/buildcc_cli11.h create mode 100644 bootstrap/src/buildcc_cli11.cpp diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt index 96e6912b..e3538764 100644 --- a/bootstrap/CMakeLists.txt +++ b/bootstrap/CMakeLists.txt @@ -3,6 +3,7 @@ add_executable(buildcc_lib_bootstrap ) target_sources(buildcc_lib_bootstrap PRIVATE src/build_flatbuffers.cpp + src/buildcc_cli11.cpp ) target_include_directories(buildcc_lib_bootstrap PRIVATE include diff --git a/bootstrap/include/bootstrap/buildcc_cli11.h b/bootstrap/include/bootstrap/buildcc_cli11.h new file mode 100644 index 00000000..2313a58d --- /dev/null +++ b/bootstrap/include/bootstrap/buildcc_cli11.h @@ -0,0 +1,28 @@ +/* + * Copyright 2021 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 BOOTSTRAP_BUILDCC_CLI11_H_ +#define BOOTSTRAP_BUILDCC_CLI11_H_ + +#include "buildcc.h" + +namespace buildcc { + +void cli11_ho_cb(TargetInfo &info); + +} // namespace buildcc + +#endif diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index d694a78c..638a566f 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -16,6 +16,7 @@ #include "buildcc.h" +#include "bootstrap/buildcc_cli11.h" #include "bootstrap/buildcc_flatbuffers.h" using namespace buildcc; @@ -25,7 +26,6 @@ static void clean_cb(); static void schema_gen_cb(base::Generator &generator, const BaseTarget &flatc_exe); -static void cli11_ho_cb(TargetInfo &info); static void fmt_ho_cb(TargetInfo &info); static void spdlog_ho_cb(TargetInfo &info); static void taskflow_ho_cb(TargetInfo &info); @@ -176,12 +176,6 @@ static void schema_gen_cb(base::Generator &generator, generator.Build(); } -static void cli11_ho_cb(TargetInfo &info) { - info.AddIncludeDir("include"); - info.GlobHeaders("include/CLI"); - // TODO, Add PCH -} - static void fmt_ho_cb(TargetInfo &info) { info.AddIncludeDir("include"); info.GlobHeaders("include/fmt"); diff --git a/bootstrap/src/buildcc_cli11.cpp b/bootstrap/src/buildcc_cli11.cpp new file mode 100644 index 00000000..21dc6df5 --- /dev/null +++ b/bootstrap/src/buildcc_cli11.cpp @@ -0,0 +1,25 @@ +/* + * Copyright 2021 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 cli11_ho_cb(TargetInfo &info) { + info.AddIncludeDir("include"); + info.GlobHeaders("include/CLI"); + // TODO, Add PCH +} + +} // namespace buildcc From d42e9d5783165cf30133fd932c29c615830a44c3 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 22:02:30 -0800 Subject: [PATCH 12/62] Renamed to buildcc_flatbuffers.cpp --- bootstrap/CMakeLists.txt | 2 +- .../src/{build_flatbuffers.cpp => buildcc_flatbuffers.cpp} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename bootstrap/src/{build_flatbuffers.cpp => buildcc_flatbuffers.cpp} (100%) diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt index e3538764..b5180479 100644 --- a/bootstrap/CMakeLists.txt +++ b/bootstrap/CMakeLists.txt @@ -2,7 +2,7 @@ add_executable(buildcc_lib_bootstrap main.buildcc.cpp ) target_sources(buildcc_lib_bootstrap PRIVATE - src/build_flatbuffers.cpp + src/buildcc_flatbuffers.cpp src/buildcc_cli11.cpp ) target_include_directories(buildcc_lib_bootstrap PRIVATE diff --git a/bootstrap/src/build_flatbuffers.cpp b/bootstrap/src/buildcc_flatbuffers.cpp similarity index 100% rename from bootstrap/src/build_flatbuffers.cpp rename to bootstrap/src/buildcc_flatbuffers.cpp From d0822aeee9723cc896907ee24018e9dca8186cdf Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 22:07:13 -0800 Subject: [PATCH 13/62] Update buildcc_cli11.cpp --- bootstrap/src/buildcc_cli11.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bootstrap/src/buildcc_cli11.cpp b/bootstrap/src/buildcc_cli11.cpp index 21dc6df5..a46907bc 100644 --- a/bootstrap/src/buildcc_cli11.cpp +++ b/bootstrap/src/buildcc_cli11.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "bootstrap/buildcc_cli11.h" + namespace buildcc { void cli11_ho_cb(TargetInfo &info) { From e5d2552a82daf35f76ee76d76140119b80b9fa3f Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 22:07:38 -0800 Subject: [PATCH 14/62] Added buildcc_fmtlib --- bootstrap/CMakeLists.txt | 1 + bootstrap/include/bootstrap/buildcc_fmtlib.h | 28 ++++++++++++++++++++ bootstrap/src/buildcc_fmtlib.cpp | 26 ++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 bootstrap/include/bootstrap/buildcc_fmtlib.h create mode 100644 bootstrap/src/buildcc_fmtlib.cpp diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt index b5180479..e883d799 100644 --- a/bootstrap/CMakeLists.txt +++ b/bootstrap/CMakeLists.txt @@ -4,6 +4,7 @@ add_executable(buildcc_lib_bootstrap target_sources(buildcc_lib_bootstrap PRIVATE src/buildcc_flatbuffers.cpp src/buildcc_cli11.cpp + src/buildcc_fmtlib.cpp ) target_include_directories(buildcc_lib_bootstrap PRIVATE include diff --git a/bootstrap/include/bootstrap/buildcc_fmtlib.h b/bootstrap/include/bootstrap/buildcc_fmtlib.h new file mode 100644 index 00000000..a198ff2a --- /dev/null +++ b/bootstrap/include/bootstrap/buildcc_fmtlib.h @@ -0,0 +1,28 @@ +/* + * Copyright 2021 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 BOOTSTRAP_BUILDCC_FMTLIB_H_ +#define BOOTSTRAP_BUILDCC_FMTLIB_H_ + +#include "buildcc.h" + +namespace buildcc { + +void fmt_ho_cb(TargetInfo &info); + +} // namespace buildcc + +#endif diff --git a/bootstrap/src/buildcc_fmtlib.cpp b/bootstrap/src/buildcc_fmtlib.cpp new file mode 100644 index 00000000..c56e4d92 --- /dev/null +++ b/bootstrap/src/buildcc_fmtlib.cpp @@ -0,0 +1,26 @@ +/* + * Copyright 2021 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 "bootstrap/buildcc_fmtlib.h" + +namespace buildcc { + +void fmt_ho_cb(TargetInfo &info) { + info.AddIncludeDir("include"); + info.GlobHeaders("include/fmt"); +} + +} // namespace buildcc From 5be82b9082d60a1b94f9ef51a10498f97dc720df Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 22:08:31 -0800 Subject: [PATCH 15/62] Added buildcc_spdlog --- bootstrap/CMakeLists.txt | 1 + bootstrap/include/bootstrap/buildcc_spdlog.h | 28 ++++++++++++++++++ bootstrap/src/buildcc_spdlog.cpp | 30 ++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 bootstrap/include/bootstrap/buildcc_spdlog.h create mode 100644 bootstrap/src/buildcc_spdlog.cpp diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt index e883d799..66b3bc94 100644 --- a/bootstrap/CMakeLists.txt +++ b/bootstrap/CMakeLists.txt @@ -5,6 +5,7 @@ target_sources(buildcc_lib_bootstrap PRIVATE src/buildcc_flatbuffers.cpp src/buildcc_cli11.cpp src/buildcc_fmtlib.cpp + src/buildcc_spdlog.cpp ) target_include_directories(buildcc_lib_bootstrap PRIVATE include diff --git a/bootstrap/include/bootstrap/buildcc_spdlog.h b/bootstrap/include/bootstrap/buildcc_spdlog.h new file mode 100644 index 00000000..1f18cecb --- /dev/null +++ b/bootstrap/include/bootstrap/buildcc_spdlog.h @@ -0,0 +1,28 @@ +/* + * Copyright 2021 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 BOOTSTRAP_BUILDCC_SPDLOG_H_ +#define BOOTSTRAP_BUILDCC_SPDLOG_H_ + +#include "buildcc.h" + +namespace buildcc { + +void spdlog_ho_cb(TargetInfo &info); + +} // namespace buildcc + +#endif diff --git a/bootstrap/src/buildcc_spdlog.cpp b/bootstrap/src/buildcc_spdlog.cpp new file mode 100644 index 00000000..667546d5 --- /dev/null +++ b/bootstrap/src/buildcc_spdlog.cpp @@ -0,0 +1,30 @@ +/* + * Copyright 2021 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 "bootstrap/buildcc_spdlog.h" + +namespace buildcc { + +void spdlog_ho_cb(TargetInfo &info) { + info.AddIncludeDir("include"); + info.GlobHeaders("include/spdlog"); + info.GlobHeaders("include/spdlog/cfg"); + info.GlobHeaders("include/spdlog/details"); + info.GlobHeaders("include/spdlog/fmt"); + info.GlobHeaders("include/spdlog/sinks"); +} + +} // namespace buildcc From b19b7a5f0c2e2d47c4071e627022aa72498b127d Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 22:09:19 -0800 Subject: [PATCH 16/62] Added buildcc_taskflow --- bootstrap/CMakeLists.txt | 1 + .../include/bootstrap/buildcc_taskflow.h | 28 ++++++++++++++++++ bootstrap/src/buildcc_taskflow.cpp | 29 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 bootstrap/include/bootstrap/buildcc_taskflow.h create mode 100644 bootstrap/src/buildcc_taskflow.cpp diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt index 66b3bc94..80a9339b 100644 --- a/bootstrap/CMakeLists.txt +++ b/bootstrap/CMakeLists.txt @@ -6,6 +6,7 @@ target_sources(buildcc_lib_bootstrap PRIVATE src/buildcc_cli11.cpp src/buildcc_fmtlib.cpp src/buildcc_spdlog.cpp + src/buildcc_taskflow.cpp ) target_include_directories(buildcc_lib_bootstrap PRIVATE include diff --git a/bootstrap/include/bootstrap/buildcc_taskflow.h b/bootstrap/include/bootstrap/buildcc_taskflow.h new file mode 100644 index 00000000..caf119fe --- /dev/null +++ b/bootstrap/include/bootstrap/buildcc_taskflow.h @@ -0,0 +1,28 @@ +/* + * Copyright 2021 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 BOOTSTRAP_BUILDCC_TASKFLOW_H_ +#define BOOTSTRAP_BUILDCC_TASKFLOW_H_ + +#include "buildcc.h" + +namespace buildcc { + +void taskflow_ho_cb(TargetInfo &info); + +} // namespace buildcc + +#endif diff --git a/bootstrap/src/buildcc_taskflow.cpp b/bootstrap/src/buildcc_taskflow.cpp new file mode 100644 index 00000000..ca439998 --- /dev/null +++ b/bootstrap/src/buildcc_taskflow.cpp @@ -0,0 +1,29 @@ +/* + * Copyright 2021 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 "bootstrap/buildcc_taskflow.h" + +namespace buildcc { + +void taskflow_ho_cb(TargetInfo &info) { + info.AddIncludeDir(""); + info.GlobHeaders("taskflow"); + info.GlobHeaders("taskflow/core"); + info.GlobHeaders("taskflow/core/algorithm"); + // TODO, Track more header files +} + +} // namespace buildcc From 283cebb0b26ff1b145556f1576c95f376280e708 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 22:10:54 -0800 Subject: [PATCH 17/62] Added buildcc_tpl.cpp --- bootstrap/CMakeLists.txt | 1 + bootstrap/include/bootstrap/buildcc_tpl.h | 28 ++++++++++++ bootstrap/src/buildcc_tpl.cpp | 56 +++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 bootstrap/include/bootstrap/buildcc_tpl.h create mode 100644 bootstrap/src/buildcc_tpl.cpp diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt index 80a9339b..31b99408 100644 --- a/bootstrap/CMakeLists.txt +++ b/bootstrap/CMakeLists.txt @@ -7,6 +7,7 @@ target_sources(buildcc_lib_bootstrap PRIVATE src/buildcc_fmtlib.cpp src/buildcc_spdlog.cpp src/buildcc_taskflow.cpp + src/buildcc_tpl.cpp ) target_include_directories(buildcc_lib_bootstrap PRIVATE include diff --git a/bootstrap/include/bootstrap/buildcc_tpl.h b/bootstrap/include/bootstrap/buildcc_tpl.h new file mode 100644 index 00000000..f1319294 --- /dev/null +++ b/bootstrap/include/bootstrap/buildcc_tpl.h @@ -0,0 +1,28 @@ +/* + * Copyright 2021 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 BOOTSTRAP_BUILDCC_TPL_H_ +#define BOOTSTRAP_BUILDCC_TPL_H_ + +#include "buildcc.h" + +namespace buildcc { + +void tpl_cb(BaseTarget &target); + +} // namespace buildcc + +#endif diff --git a/bootstrap/src/buildcc_tpl.cpp b/bootstrap/src/buildcc_tpl.cpp new file mode 100644 index 00000000..39537485 --- /dev/null +++ b/bootstrap/src/buildcc_tpl.cpp @@ -0,0 +1,56 @@ +/* + * Copyright 2021 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 "bootstrap/buildcc_tpl.h" + +namespace buildcc { + +static void tpl_cb(BaseTarget &target) { + target.AddSource("process.cpp"); + target.AddIncludeDir(""); + target.AddHeader("process.hpp"); + + // MinGW (GCC), MSVC, Clang + if constexpr (env::is_win()) { + target.AddSource("process_win.cpp"); + // TODO, MSVC + // TODO, Clang + switch (target.GetToolchain().GetId()) { + case ToolchainId::Gcc: + case ToolchainId::MinGW: + target.AddCppCompileFlag("-std=c++17"); + target.AddCppCompileFlag("-Wall"); + target.AddCppCompileFlag("-Wextra"); + break; + default: + break; + } + } + + if constexpr (env::is_linux()) { + // TODO, GCC + // TODO, Clang + } + + // LOG DUMP + for (const auto &d : target.GetCurrentSourceFiles()) { + env::log_info(__FUNCTION__, d.string()); + } + + target.Build(); +} + +} // namespace buildcc From 9d1cff85632e0a39440dd66f3328f322705f0e09 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 22:12:43 -0800 Subject: [PATCH 18/62] Update buildcc_tpl.cpp --- bootstrap/src/buildcc_tpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/src/buildcc_tpl.cpp b/bootstrap/src/buildcc_tpl.cpp index 39537485..074bbf0d 100644 --- a/bootstrap/src/buildcc_tpl.cpp +++ b/bootstrap/src/buildcc_tpl.cpp @@ -18,7 +18,7 @@ namespace buildcc { -static void tpl_cb(BaseTarget &target) { +void tpl_cb(BaseTarget &target) { target.AddSource("process.cpp"); target.AddIncludeDir(""); target.AddHeader("process.hpp"); From 94d855e94dddf1aa6a0a1c031b46a5a502d13320 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 22:12:46 -0800 Subject: [PATCH 19/62] Update main.buildcc.cpp --- bootstrap/main.buildcc.cpp | 66 +++----------------------------------- 1 file changed, 4 insertions(+), 62 deletions(-) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index 638a566f..9e93e01d 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -18,6 +18,10 @@ #include "bootstrap/buildcc_cli11.h" #include "bootstrap/buildcc_flatbuffers.h" +#include "bootstrap/buildcc_fmtlib.h" +#include "bootstrap/buildcc_spdlog.h" +#include "bootstrap/buildcc_taskflow.h" +#include "bootstrap/buildcc_tpl.h" using namespace buildcc; @@ -26,11 +30,6 @@ static void clean_cb(); static void schema_gen_cb(base::Generator &generator, const BaseTarget &flatc_exe); -static void fmt_ho_cb(TargetInfo &info); -static void spdlog_ho_cb(TargetInfo &info); -static void taskflow_ho_cb(TargetInfo &info); -static void tpl_cb(BaseTarget &target); - static void buildcc_cb(BaseTarget &target, const base::Generator &schema_gen, const TargetInfo &flatbuffers_ho, const TargetInfo &fmt_ho, const TargetInfo &spdlog_ho, @@ -176,63 +175,6 @@ static void schema_gen_cb(base::Generator &generator, generator.Build(); } -static void fmt_ho_cb(TargetInfo &info) { - info.AddIncludeDir("include"); - info.GlobHeaders("include/fmt"); -} - -static void spdlog_ho_cb(TargetInfo &info) { - info.AddIncludeDir("include"); - info.GlobHeaders("include/spdlog"); - info.GlobHeaders("include/spdlog/cfg"); - info.GlobHeaders("include/spdlog/details"); - info.GlobHeaders("include/spdlog/fmt"); - info.GlobHeaders("include/spdlog/sinks"); -} - -static void taskflow_ho_cb(TargetInfo &info) { - info.AddIncludeDir(""); - info.GlobHeaders("taskflow"); - info.GlobHeaders("taskflow/core"); - info.GlobHeaders("taskflow/core/algorithm"); - // TODO, Track more header files -} - -static void tpl_cb(BaseTarget &target) { - target.AddSource("process.cpp"); - target.AddIncludeDir(""); - target.AddHeader("process.hpp"); - - // MinGW (GCC), MSVC, Clang - if constexpr (env::is_win()) { - target.AddSource("process_win.cpp"); - // TODO, MSVC - // TODO, Clang - switch (target.GetToolchain().GetId()) { - case ToolchainId::Gcc: - case ToolchainId::MinGW: - target.AddCppCompileFlag("-std=c++17"); - target.AddCppCompileFlag("-Wall"); - target.AddCppCompileFlag("-Wextra"); - break; - default: - break; - } - } - - if constexpr (env::is_linux()) { - // TODO, GCC - // TODO, Clang - } - - // LOG DUMP - for (const auto &d : target.GetCurrentSourceFiles()) { - env::log_info(__FUNCTION__, d.string()); - } - - target.Build(); -} - static void buildcc_cb(BaseTarget &target, const base::Generator &schema_gen, const TargetInfo &flatbuffers_ho, const TargetInfo &fmt_ho, const TargetInfo &spdlog_ho, From bdcd1f32586c7d14b2b8b0a787d49c048d0e7866 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 22:15:27 -0800 Subject: [PATCH 20/62] Update main.buildcc.cpp --- bootstrap/main.buildcc.cpp | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index 9e93e01d..c008c7d3 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -99,45 +99,9 @@ int main(int argc, char **argv) noexcept { buildcc_hybrid_simple_example, buildcc_lib); reg.Dep(buildcc_hybrid_simple_example, buildcc_lib); - // reg.Test(arg_gcc.state, "{executable} --help", - // buildcc_hybrid_simple_example, - // { - // {"example_folder", - // buildcc_hybrid_simple_example.GetTargetRootDir().string()}, - // }); - reg.Test(arg_gcc.state, - "{executable} --config {example_folder}/build_linux.toml", - buildcc_hybrid_simple_example, - TestConfig( - { - {"example_folder", - buildcc_hybrid_simple_example.GetTargetRootDir().string()}, - }, - buildcc_hybrid_simple_example.GetTargetRootDir())); - - // ExecutableTarget_generic tpl_io_test("tpl_io_test", gcc, - // "third_party/tiny-process-library"); - // reg.Build( - // arg_gcc.state, - // [](BaseTarget &target, const BaseTarget &tpl_lib) { - // // target.AddSource("tests/io_test.cpp"); - // target.AddSource("tests/multithread_test.cpp"); - - // for (const auto &idir : tpl_lib.GetCurrentIncludeDirs()) { - // target.AddIncludeDir(idir); - // } - // target.AddLibDep(tpl_lib); - // target.Build(); - // }, - // tpl_io_test, tpl_lib); - // reg.Dep(tpl_io_test, tpl_lib); - // reg.Test(arg_gcc.state, "{executable}", tpl_io_test); - reg.RunBuild(); - // fs::current_path(buildcc_hybrid_simple_example.GetTargetRootDir()); reg.RunTest(); - // fs::current_path(env::get_project_root_dir()); // - Clang Compile Commands plugin::ClangCompileCommands({&buildcc_lib}).Generate(); @@ -148,8 +112,6 @@ int main(int argc, char **argv) noexcept { env::assert_fatal(saved, "Could not save graph.dot file"); return 0; - - return 0; } static void clean_cb() {} From 3b5fa4e4bf470caa62e6a5db5d90c876dc5d1a03 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Tue, 30 Nov 2021 22:34:39 -0800 Subject: [PATCH 21/62] Updated config_linux with generic toolchain --- bootstrap/config_linux.toml | 10 +++++++++- bootstrap/main.buildcc.cpp | 25 +++++++++++++------------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/bootstrap/config_linux.toml b/bootstrap/config_linux.toml index 4697c723..75b7222d 100644 --- a/bootstrap/config_linux.toml +++ b/bootstrap/config_linux.toml @@ -4,6 +4,14 @@ build_dir="../_build_bootstrap" loglevel="trace" clean=false -[toolchain.gcc] +[toolchain.custom] build = true test = true + +id = "gcc" +name = "gcc" +asm_compiler = "as" +c_compiler = "gcc" +cpp_compiler = "g++" +archiver = "ar" +linker = "ld" diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index c008c7d3..970146cd 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -39,20 +39,21 @@ static void buildcc_cb(BaseTarget &target, const base::Generator &schema_gen, static void hybrid_simple_example_cb(BaseTarget &target, const BaseTarget &libbuildcc); -int main(int argc, char **argv) noexcept { +int main(int argc, char **argv) { Args args; - Args::ToolchainArg arg_gcc; - args.AddToolchain("gcc", "Host GCC Toolchain", arg_gcc); + Args::ToolchainArg arg_toolchain; + args.AddToolchain("custom", "Host Toolchain", arg_toolchain); args.Parse(argc, argv); Register reg(args); reg.Clean(clean_cb); - Toolchain_gcc gcc; + BaseToolchain toolchain = arg_toolchain.ConstructToolchain(); // Flatc Executable - ExecutableTarget_generic flatc_exe("flatc", gcc, "third_party/flatbuffers"); - reg.Build(arg_gcc.state, build_flatc_exe_cb, flatc_exe); + ExecutableTarget_generic flatc_exe("flatc", toolchain, + "third_party/flatbuffers"); + reg.Build(arg_toolchain.state, build_flatc_exe_cb, flatc_exe); // Schema base::Generator schema_gen("schema_gen", "buildcc/schema"); @@ -81,21 +82,21 @@ int main(int argc, char **argv) noexcept { // Tiny-process-library lib // TODO, Make this a generic selection between StaticTarget and DynamicTarget - StaticTarget_generic tpl_lib("libtpl", gcc, + StaticTarget_generic tpl_lib("libtpl", toolchain, "third_party/tiny-process-library"); - reg.Build(arg_gcc.state, tpl_cb, tpl_lib); + reg.Build(arg_toolchain.state, tpl_cb, tpl_lib); // TODO, Make this a generic selection between StaticTarget and DynamicTarget - StaticTarget_generic buildcc_lib("libbuildcc", gcc, "buildcc"); - reg.Build(arg_gcc.state, buildcc_cb, buildcc_lib, schema_gen, + StaticTarget_generic buildcc_lib("libbuildcc", toolchain, "buildcc"); + reg.Build(arg_toolchain.state, buildcc_cb, buildcc_lib, schema_gen, flatbuffers_ho_lib, fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib, taskflow_ho_lib, tpl_lib); reg.Dep(buildcc_lib, schema_gen); reg.Dep(buildcc_lib, tpl_lib); ExecutableTarget_generic buildcc_hybrid_simple_example( - "buildcc_hybrid_simple_example", gcc, "example/hybrid/simple"); - reg.Build(arg_gcc.state, hybrid_simple_example_cb, + "buildcc_hybrid_simple_example", toolchain, "example/hybrid/simple"); + reg.Build(arg_toolchain.state, hybrid_simple_example_cb, buildcc_hybrid_simple_example, buildcc_lib); reg.Dep(buildcc_hybrid_simple_example, buildcc_lib); From 9be5b5b4df2488220045def2de508e164329c033 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 01:27:53 -0800 Subject: [PATCH 22/62] Update main.buildcc.cpp --- bootstrap/main.buildcc.cpp | 49 ++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index 970146cd..de42b90d 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -223,26 +223,44 @@ static void buildcc_cb(BaseTarget &target, const base::Generator &schema_gen, target.AddLibDep(tpl); target.Insert(tpl, kInsertOptions); - // TODO, ADD GCC flags - // TODO, ADD MSVC flags if constexpr (env::is_win()) { - if (target.GetToolchain().GetId() == ToolchainId::Gcc) { + // TODO, Clang + switch (target.GetToolchain().GetId()) { + case ToolchainId::Gcc: + case ToolchainId::MinGW: { + target.AddPreprocessorFlag("-DFMT_HEADER_ONLY=1"); + target.AddPreprocessorFlag("-DSPDLOG_FMT_EXTERNAL"); + target.AddCppCompileFlag("-std=c++17"); + target.AddCppCompileFlag("-Wall"); + target.AddCppCompileFlag("-Wextra"); + // For MINGW target.AddLinkFlag("-Wl,--allow-multiple-definition"); + } break; + case ToolchainId::Msvc: { + target.AddPreprocessorFlag("/DFMT_HEADER_ONLY=1"); + target.AddPreprocessorFlag("/DSPDLOG_FMT_EXTERNAL"); + target.AddCppCompileFlag("/std:c++17"); + } break; + default: + break; } } - switch (target.GetToolchain().GetId()) { - case ToolchainId::Gcc: { - target.AddPreprocessorFlag("-DFMT_HEADER_ONLY=1"); - target.AddPreprocessorFlag("-DSPDLOG_FMT_EXTERNAL"); - target.AddCppCompileFlag("-std=c++17"); - target.AddCppCompileFlag("-Wall"); - target.AddCppCompileFlag("-Wextra"); - } break; - case ToolchainId::Msvc: { - } break; - default: - break; + if constexpr (env::is_linux()) { + // TODO, Clang + switch (target.GetToolchain().GetId()) { + case ToolchainId::Gcc: { + target.AddPreprocessorFlag("-DFMT_HEADER_ONLY=1"); + target.AddPreprocessorFlag("-DSPDLOG_FMT_EXTERNAL"); + target.AddCppCompileFlag("-std=c++17"); + target.AddCppCompileFlag("-Wall"); + target.AddCppCompileFlag("-Wextra"); + target.AddLinkFlag("-Wl,--allow-multiple-definition"); + target.AddLibDep("-lpthread"); + } break; + default: + break; + } } target.Build(); @@ -257,6 +275,7 @@ static void hybrid_simple_example_cb(BaseTarget &target, SyncOption::HeaderFiles, SyncOption::IncludeDirs, SyncOption::LibDeps, + SyncOption::ExternalLibDeps, }); target.AddSource("build.cpp"); target.AddLibDep(libbuildcc); From 15da75ec17f3d636b7b7ceeaa2de1afa7bdb9ae4 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 01:29:49 -0800 Subject: [PATCH 23/62] Update buildcc_tpl.cpp --- bootstrap/src/buildcc_tpl.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/bootstrap/src/buildcc_tpl.cpp b/bootstrap/src/buildcc_tpl.cpp index 074bbf0d..eb6154a3 100644 --- a/bootstrap/src/buildcc_tpl.cpp +++ b/bootstrap/src/buildcc_tpl.cpp @@ -26,7 +26,6 @@ void tpl_cb(BaseTarget &target) { // MinGW (GCC), MSVC, Clang if constexpr (env::is_win()) { target.AddSource("process_win.cpp"); - // TODO, MSVC // TODO, Clang switch (target.GetToolchain().GetId()) { case ToolchainId::Gcc: @@ -35,19 +34,25 @@ void tpl_cb(BaseTarget &target) { target.AddCppCompileFlag("-Wall"); target.AddCppCompileFlag("-Wextra"); break; + case ToolchainId::Msvc: + target.AddCppCompileFlag("/std:c++17"); default: break; } } if constexpr (env::is_linux()) { - // TODO, GCC + target.AddSource("process_unix.cpp"); // TODO, Clang - } - - // LOG DUMP - for (const auto &d : target.GetCurrentSourceFiles()) { - env::log_info(__FUNCTION__, d.string()); + switch (target.GetToolchain().GetId()) { + case ToolchainId::Gcc: + target.AddCppCompileFlag("-std=c++17"); + target.AddCppCompileFlag("-Wall"); + target.AddCppCompileFlag("-Wextra"); + break; + default: + break; + } } target.Build(); From 2f1f8e78e7c37feb8fc88591317d49a1a8438dfa Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 01:36:39 -0800 Subject: [PATCH 24/62] Renamed config_linux to config_default --- bootstrap/config_default.toml | 17 +++++++++++++++++ bootstrap/config_linux.toml | 17 ----------------- 2 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 bootstrap/config_default.toml delete mode 100644 bootstrap/config_linux.toml diff --git a/bootstrap/config_default.toml b/bootstrap/config_default.toml new file mode 100644 index 00000000..ecaeb577 --- /dev/null +++ b/bootstrap/config_default.toml @@ -0,0 +1,17 @@ +root_dir=".." +build_dir="../_build_bootstrap" + +loglevel="trace" +clean=false + +# [toolchain.custom] +# build = true +# test = true + +# id = "msvc" +# name = "msvc" +# asm_compiler = "cl" +# c_compiler = "cl" +# cpp_compiler = "cl" +# archiver = "lib" +# linker = "link" diff --git a/bootstrap/config_linux.toml b/bootstrap/config_linux.toml deleted file mode 100644 index 75b7222d..00000000 --- a/bootstrap/config_linux.toml +++ /dev/null @@ -1,17 +0,0 @@ -root_dir=".." -build_dir="../_build_bootstrap" - -loglevel="trace" -clean=false - -[toolchain.custom] -build = true -test = true - -id = "gcc" -name = "gcc" -asm_compiler = "as" -c_compiler = "gcc" -cpp_compiler = "g++" -archiver = "ar" -linker = "ld" From 9072d22dae3fc1b13068d89aa9860856394d3894 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 01:47:03 -0800 Subject: [PATCH 25/62] Added toolchain files for gcc_win and gcc_linux --- bootstrap/CMakeLists.txt | 14 +++++++++++--- bootstrap/config/toolchain_gcc_linux.toml | 11 +++++++++++ bootstrap/config/toolchain_gcc_win.toml | 11 +++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 bootstrap/config/toolchain_gcc_linux.toml create mode 100644 bootstrap/config/toolchain_gcc_win.toml diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt index 31b99408..769a5b1d 100644 --- a/bootstrap/CMakeLists.txt +++ b/bootstrap/CMakeLists.txt @@ -22,10 +22,18 @@ if (${MINGW}) target_link_options(buildcc_lib_bootstrap PRIVATE -Wl,--allow-multiple-definition) endif() -add_custom_target(run_buildcc_lib_bootstrap_linux +# Linux GCC +add_custom_target(run_buildcc_lib_bootstrap_linux_gcc COMMAND buildcc_lib_bootstrap --help-all - COMMAND buildcc_lib_bootstrap --config ${CMAKE_CURRENT_SOURCE_DIR}/config_linux.toml - # COMMAND dot -Tpng graph.dot -o graph.PNG + COMMAND buildcc_lib_bootstrap --config ${CMAKE_CURRENT_SOURCE_DIR}/config_default.toml --config ${CMAKE_CURRENT_SOURCE_DIR}/config/toolchain_gcc_linux.toml + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + VERBATIM USES_TERMINAL +) + +# Win GCC/MINGW +add_custom_target(run_buildcc_lib_bootstrap_win_gcc + COMMAND buildcc_lib_bootstrap --help-all + COMMAND buildcc_lib_bootstrap --config ${CMAKE_CURRENT_SOURCE_DIR}/config_default.toml --config ${CMAKE_CURRENT_SOURCE_DIR}/config/toolchain_gcc_win.toml WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} VERBATIM USES_TERMINAL ) diff --git a/bootstrap/config/toolchain_gcc_linux.toml b/bootstrap/config/toolchain_gcc_linux.toml new file mode 100644 index 00000000..6ac3dd34 --- /dev/null +++ b/bootstrap/config/toolchain_gcc_linux.toml @@ -0,0 +1,11 @@ +[toolchain.custom] +build = true +test = true + +id = "gcc" +name = "x86_64-linux-gnu" +asm_compiler = "as" +c_compiler = "gcc" +cpp_compiler = "g++" +archiver = "ar" +linker = "ld" diff --git a/bootstrap/config/toolchain_gcc_win.toml b/bootstrap/config/toolchain_gcc_win.toml new file mode 100644 index 00000000..dfd67809 --- /dev/null +++ b/bootstrap/config/toolchain_gcc_win.toml @@ -0,0 +1,11 @@ +[toolchain.custom] +build = true +test = true + +id = "gcc" +name = "x86_64-w64-mingw32" +asm_compiler = "as" +c_compiler = "gcc" +cpp_compiler = "g++" +archiver = "ar" +linker = "ld" From 92e5fb8c02c7817a7e8c447714d01d32a7248a62 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 01:47:16 -0800 Subject: [PATCH 26/62] Update buildcc_flatbuffers.cpp --- bootstrap/src/buildcc_flatbuffers.cpp | 40 +++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/bootstrap/src/buildcc_flatbuffers.cpp b/bootstrap/src/buildcc_flatbuffers.cpp index e39a9b2a..1b355da2 100644 --- a/bootstrap/src/buildcc_flatbuffers.cpp +++ b/bootstrap/src/buildcc_flatbuffers.cpp @@ -49,7 +49,7 @@ const std::vector kFlatcPreprocessorFlags{ "-DNDEBUG", }; -const std::vector kFlatcCppCompileFlags{ +const std::vector kFlatcGccCppCompileFlags{ "-std=c++17", "-Os", "-Wall", @@ -68,6 +68,13 @@ const std::vector kFlatcCppCompileFlags{ "-Winvalid-pch", }; +// TODO, Understand these options +const std::vector kFlatcMsvcCppCompileFlags{ + "/std:c++17", "/W4", "/WX", "/MP", "/O2", + "/Ob2", "/MT", "/GS", "/fp:precise", "/Zc:wchar_t", + "/Zc:forScope", "/Zc:inline", "/GR", +}; + } // namespace namespace buildcc { @@ -87,8 +94,35 @@ void build_flatc_exe_cb(BaseTarget &target) { kFlatcPreprocessorFlags.cend(), [&](const auto &f) { target.AddPreprocessorFlag(f); }); - std::for_each(kFlatcCppCompileFlags.cbegin(), kFlatcCppCompileFlags.cend(), - [&](const auto &f) { target.AddCppCompileFlag(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; + } + } + + 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 From ed826caf6be5b6c0c3c837fc20076d0b7610ab54 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 04:26:58 -0800 Subject: [PATCH 27/62] Update buildcc_flatbuffers.cpp --- bootstrap/src/buildcc_flatbuffers.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bootstrap/src/buildcc_flatbuffers.cpp b/bootstrap/src/buildcc_flatbuffers.cpp index 1b355da2..b7a991cb 100644 --- a/bootstrap/src/buildcc_flatbuffers.cpp +++ b/bootstrap/src/buildcc_flatbuffers.cpp @@ -68,11 +68,10 @@ const std::vector kFlatcGccCppCompileFlags{ "-Winvalid-pch", }; -// TODO, Understand these options const std::vector kFlatcMsvcCppCompileFlags{ - "/std:c++17", "/W4", "/WX", "/MP", "/O2", - "/Ob2", "/MT", "/GS", "/fp:precise", "/Zc:wchar_t", - "/Zc:forScope", "/Zc:inline", "/GR", + "/std:c++17", "/W4", "/WX", "/MP", + "/Ot", "/MT", "/GS", "/fp:precise", + "/Zc:wchar_t", "/Zc:forScope", "/Zc:inline", "/GR", }; } // namespace From 5ed46a38873051488945c29aa1a1d3cb6e616f89 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 04:32:51 -0800 Subject: [PATCH 28/62] Added toolchain msvc --- bootstrap/CMakeLists.txt | 8 ++++++++ bootstrap/config/toolchain_msvc_win.toml | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 bootstrap/config/toolchain_msvc_win.toml diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt index 769a5b1d..cabb8fdd 100644 --- a/bootstrap/CMakeLists.txt +++ b/bootstrap/CMakeLists.txt @@ -37,3 +37,11 @@ add_custom_target(run_buildcc_lib_bootstrap_win_gcc WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} VERBATIM USES_TERMINAL ) + +# Win MSVC +add_custom_target(run_buildcc_lib_bootstrap_win_msvc + COMMAND buildcc_lib_bootstrap --help-all + COMMAND buildcc_lib_bootstrap --config ${CMAKE_CURRENT_SOURCE_DIR}/config_default.toml --config ${CMAKE_CURRENT_SOURCE_DIR}/config/toolchain_msvc_win.toml + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + VERBATIM USES_TERMINAL +) diff --git a/bootstrap/config/toolchain_msvc_win.toml b/bootstrap/config/toolchain_msvc_win.toml new file mode 100644 index 00000000..f14f51e5 --- /dev/null +++ b/bootstrap/config/toolchain_msvc_win.toml @@ -0,0 +1,11 @@ +[toolchain.custom] +build = true +test = true + +id = "msvc" +name = "msvc_x64" +asm_compiler = "cl" +c_compiler = "cl" +cpp_compiler = "cl" +archiver = "lib" +linker = "link" From 4d98cdf40d29cbdb31f5cf39c758e11de05858a7 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 04:49:21 -0800 Subject: [PATCH 29/62] Updated tpl and buildcc with global defaults --- bootstrap/main.buildcc.cpp | 34 ++++++++++++++++++++++++++-------- bootstrap/src/buildcc_tpl.cpp | 28 +--------------------------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index de42b90d..b628cdb8 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -27,6 +27,9 @@ using namespace buildcc; static void clean_cb(); +static void global_flags_cb(TargetInfo &global_info, + const BaseToolchain &toolchain); + static void schema_gen_cb(base::Generator &generator, const BaseTarget &flatc_exe); @@ -84,10 +87,12 @@ int main(int argc, char **argv) { // TODO, Make this a generic selection between StaticTarget and DynamicTarget StaticTarget_generic tpl_lib("libtpl", toolchain, "third_party/tiny-process-library"); + reg.CallbackIf(arg_toolchain.state, global_flags_cb, tpl_lib, toolchain); reg.Build(arg_toolchain.state, tpl_cb, tpl_lib); // TODO, Make this a generic selection between StaticTarget and DynamicTarget StaticTarget_generic buildcc_lib("libbuildcc", toolchain, "buildcc"); + reg.CallbackIf(arg_toolchain.state, global_flags_cb, buildcc_lib, toolchain); reg.Build(arg_toolchain.state, buildcc_cb, buildcc_lib, schema_gen, flatbuffers_ho_lib, fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib, taskflow_ho_lib, tpl_lib); @@ -117,6 +122,25 @@ int main(int argc, char **argv) { static void clean_cb() {} +static void global_flags_cb(TargetInfo &global_info, + const BaseToolchain &toolchain) { + // TODO, Clang + switch (toolchain.GetId()) { + case ToolchainId::Gcc: + case ToolchainId::MinGW: + global_info.AddCppCompileFlag("-std=c++17"); + global_info.AddCppCompileFlag("-Os"); + global_info.AddCppCompileFlag("-Wall"); + global_info.AddCppCompileFlag("-Wextra"); + break; + case ToolchainId::Msvc: + global_info.AddCppCompileFlag("/std:c++17"); + global_info.AddCppCompileFlag("/Ot"); + default: + break; + } +} + static void schema_gen_cb(base::Generator &generator, const BaseTarget &flatc_exe) { generator.AddInput("{gen_root_dir}/path.fbs", "path_fbs"); @@ -230,16 +254,12 @@ static void buildcc_cb(BaseTarget &target, const base::Generator &schema_gen, case ToolchainId::MinGW: { target.AddPreprocessorFlag("-DFMT_HEADER_ONLY=1"); target.AddPreprocessorFlag("-DSPDLOG_FMT_EXTERNAL"); - target.AddCppCompileFlag("-std=c++17"); - target.AddCppCompileFlag("-Wall"); - target.AddCppCompileFlag("-Wextra"); // For MINGW target.AddLinkFlag("-Wl,--allow-multiple-definition"); } break; case ToolchainId::Msvc: { target.AddPreprocessorFlag("/DFMT_HEADER_ONLY=1"); target.AddPreprocessorFlag("/DSPDLOG_FMT_EXTERNAL"); - target.AddCppCompileFlag("/std:c++17"); } break; default: break; @@ -252,10 +272,6 @@ static void buildcc_cb(BaseTarget &target, const base::Generator &schema_gen, case ToolchainId::Gcc: { target.AddPreprocessorFlag("-DFMT_HEADER_ONLY=1"); target.AddPreprocessorFlag("-DSPDLOG_FMT_EXTERNAL"); - target.AddCppCompileFlag("-std=c++17"); - target.AddCppCompileFlag("-Wall"); - target.AddCppCompileFlag("-Wextra"); - target.AddLinkFlag("-Wl,--allow-multiple-definition"); target.AddLibDep("-lpthread"); } break; default: @@ -263,6 +279,8 @@ static void buildcc_cb(BaseTarget &target, const base::Generator &schema_gen, } } + // TODO, Other OS's + target.Build(); } diff --git a/bootstrap/src/buildcc_tpl.cpp b/bootstrap/src/buildcc_tpl.cpp index eb6154a3..b55cac9f 100644 --- a/bootstrap/src/buildcc_tpl.cpp +++ b/bootstrap/src/buildcc_tpl.cpp @@ -23,36 +23,10 @@ void tpl_cb(BaseTarget &target) { target.AddIncludeDir(""); target.AddHeader("process.hpp"); - // MinGW (GCC), MSVC, Clang if constexpr (env::is_win()) { target.AddSource("process_win.cpp"); - // TODO, Clang - switch (target.GetToolchain().GetId()) { - case ToolchainId::Gcc: - case ToolchainId::MinGW: - target.AddCppCompileFlag("-std=c++17"); - target.AddCppCompileFlag("-Wall"); - target.AddCppCompileFlag("-Wextra"); - break; - case ToolchainId::Msvc: - target.AddCppCompileFlag("/std:c++17"); - default: - break; - } - } - - if constexpr (env::is_linux()) { + } else { target.AddSource("process_unix.cpp"); - // TODO, Clang - switch (target.GetToolchain().GetId()) { - case ToolchainId::Gcc: - target.AddCppCompileFlag("-std=c++17"); - target.AddCppCompileFlag("-Wall"); - target.AddCppCompileFlag("-Wextra"); - break; - default: - break; - } } target.Build(); From 5db0a1fa762ee48b02788b887bbb02bf9e07f004 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 04:58:54 -0800 Subject: [PATCH 30/62] Updated global_flags_cb --- bootstrap/main.buildcc.cpp | 4 ++++ bootstrap/src/buildcc_flatbuffers.cpp | 23 ++++++----------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index b628cdb8..345bdaaf 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -56,6 +56,7 @@ int main(int argc, char **argv) { // Flatc Executable ExecutableTarget_generic flatc_exe("flatc", toolchain, "third_party/flatbuffers"); + reg.CallbackIf(arg_toolchain.state, global_flags_cb, flatc_exe, toolchain); reg.Build(arg_toolchain.state, build_flatc_exe_cb, flatc_exe); // Schema @@ -132,10 +133,13 @@ static void global_flags_cb(TargetInfo &global_info, global_info.AddCppCompileFlag("-Os"); global_info.AddCppCompileFlag("-Wall"); global_info.AddCppCompileFlag("-Wextra"); + global_info.AddCppCompileFlag("-Werror"); break; case ToolchainId::Msvc: global_info.AddCppCompileFlag("/std:c++17"); global_info.AddCppCompileFlag("/Ot"); + global_info.AddCppCompileFlag("/W4"); + global_info.AddCppCompileFlag("/WX"); default: break; } diff --git a/bootstrap/src/buildcc_flatbuffers.cpp b/bootstrap/src/buildcc_flatbuffers.cpp index b7a991cb..2ff902a5 100644 --- a/bootstrap/src/buildcc_flatbuffers.cpp +++ b/bootstrap/src/buildcc_flatbuffers.cpp @@ -50,27 +50,16 @@ const std::vector kFlatcPreprocessorFlags{ }; const std::vector kFlatcGccCppCompileFlags{ - "-std=c++17", - "-Os", - "-Wall", - "-pedantic", - "-Werror", - "-Wextra", - "-Werror=shadow", - "-faligned-new", - "-Werror=implicit-fallthrough=2", - "-Wunused-result", - "-Werror=unused-result", - "-Wunused-parameter", - "-Werror=unused-parameter", - "-fsigned-char", - "-Wold-style-cast", + "-pedantic", "-Werror=shadow", + "-faligned-new", "-Werror=implicit-fallthrough=2", + "-Wunused-result", "-Werror=unused-result", + "-Wunused-parameter", "-Werror=unused-parameter", + "-fsigned-char", "-Wold-style-cast", "-Winvalid-pch", }; const std::vector kFlatcMsvcCppCompileFlags{ - "/std:c++17", "/W4", "/WX", "/MP", - "/Ot", "/MT", "/GS", "/fp:precise", + "/MP", "/MT", "/GS", "/fp:precise", "/Zc:wchar_t", "/Zc:forScope", "/Zc:inline", "/GR", }; From a93ef8afa7ac40e22a8e48caaa4b15b8129979c9 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 05:05:49 -0800 Subject: [PATCH 31/62] Renamed buildcc_* to build_* --- bootstrap/CMakeLists.txt | 12 ++++++------ .../bootstrap/{buildcc_cli11.h => build_cli11.h} | 4 ++-- .../{buildcc_flatbuffers.h => build_flatbuffers.h} | 4 ++-- .../bootstrap/{buildcc_fmtlib.h => build_fmtlib.h} | 4 ++-- .../bootstrap/{buildcc_spdlog.h => build_spdlog.h} | 4 ++-- .../{buildcc_taskflow.h => build_taskflow.h} | 4 ++-- .../include/bootstrap/{buildcc_tpl.h => build_tpl.h} | 4 ++-- bootstrap/src/{buildcc_cli11.cpp => build_cli11.cpp} | 2 +- ...buildcc_flatbuffers.cpp => build_flatbuffers.cpp} | 2 +- .../src/{buildcc_fmtlib.cpp => build_fmtlib.cpp} | 2 +- .../src/{buildcc_spdlog.cpp => build_spdlog.cpp} | 2 +- .../src/{buildcc_taskflow.cpp => build_taskflow.cpp} | 2 +- bootstrap/src/{buildcc_tpl.cpp => build_tpl.cpp} | 2 +- 13 files changed, 24 insertions(+), 24 deletions(-) rename bootstrap/include/bootstrap/{buildcc_cli11.h => build_cli11.h} (91%) rename bootstrap/include/bootstrap/{buildcc_flatbuffers.h => build_flatbuffers.h} (90%) rename bootstrap/include/bootstrap/{buildcc_fmtlib.h => build_fmtlib.h} (91%) rename bootstrap/include/bootstrap/{buildcc_spdlog.h => build_spdlog.h} (91%) rename bootstrap/include/bootstrap/{buildcc_taskflow.h => build_taskflow.h} (90%) rename bootstrap/include/bootstrap/{buildcc_tpl.h => build_tpl.h} (91%) rename bootstrap/src/{buildcc_cli11.cpp => build_cli11.cpp} (95%) rename bootstrap/src/{buildcc_flatbuffers.cpp => build_flatbuffers.cpp} (98%) rename bootstrap/src/{buildcc_fmtlib.cpp => build_fmtlib.cpp} (95%) rename bootstrap/src/{buildcc_spdlog.cpp => build_spdlog.cpp} (96%) rename bootstrap/src/{buildcc_taskflow.cpp => build_taskflow.cpp} (95%) rename bootstrap/src/{buildcc_tpl.cpp => build_tpl.cpp} (96%) diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt index cabb8fdd..2567fdee 100644 --- a/bootstrap/CMakeLists.txt +++ b/bootstrap/CMakeLists.txt @@ -2,12 +2,12 @@ add_executable(buildcc_lib_bootstrap main.buildcc.cpp ) target_sources(buildcc_lib_bootstrap PRIVATE - src/buildcc_flatbuffers.cpp - src/buildcc_cli11.cpp - src/buildcc_fmtlib.cpp - src/buildcc_spdlog.cpp - src/buildcc_taskflow.cpp - src/buildcc_tpl.cpp + src/build_flatbuffers.cpp + src/build_cli11.cpp + src/build_fmtlib.cpp + src/build_spdlog.cpp + src/build_taskflow.cpp + src/build_tpl.cpp ) target_include_directories(buildcc_lib_bootstrap PRIVATE include diff --git a/bootstrap/include/bootstrap/buildcc_cli11.h b/bootstrap/include/bootstrap/build_cli11.h similarity index 91% rename from bootstrap/include/bootstrap/buildcc_cli11.h rename to bootstrap/include/bootstrap/build_cli11.h index 2313a58d..2f0d0952 100644 --- a/bootstrap/include/bootstrap/buildcc_cli11.h +++ b/bootstrap/include/bootstrap/build_cli11.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef BOOTSTRAP_BUILDCC_CLI11_H_ -#define BOOTSTRAP_BUILDCC_CLI11_H_ +#ifndef BOOTSTRAP_BUILD_CLI11_H_ +#define BOOTSTRAP_BUILD_CLI11_H_ #include "buildcc.h" diff --git a/bootstrap/include/bootstrap/buildcc_flatbuffers.h b/bootstrap/include/bootstrap/build_flatbuffers.h similarity index 90% rename from bootstrap/include/bootstrap/buildcc_flatbuffers.h rename to bootstrap/include/bootstrap/build_flatbuffers.h index e9e60e69..d0adf845 100644 --- a/bootstrap/include/bootstrap/buildcc_flatbuffers.h +++ b/bootstrap/include/bootstrap/build_flatbuffers.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef BOOTSTRAP_BUILDCC_FLATBUFFERS_H_ -#define BOOTSTRAP_BUILDCC_FLATBUFFERS_H_ +#ifndef BOOTSTRAP_BUILD_FLATBUFFERS_H_ +#define BOOTSTRAP_BUILD_FLATBUFFERS_H_ #include "buildcc.h" diff --git a/bootstrap/include/bootstrap/buildcc_fmtlib.h b/bootstrap/include/bootstrap/build_fmtlib.h similarity index 91% rename from bootstrap/include/bootstrap/buildcc_fmtlib.h rename to bootstrap/include/bootstrap/build_fmtlib.h index a198ff2a..a09fd383 100644 --- a/bootstrap/include/bootstrap/buildcc_fmtlib.h +++ b/bootstrap/include/bootstrap/build_fmtlib.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef BOOTSTRAP_BUILDCC_FMTLIB_H_ -#define BOOTSTRAP_BUILDCC_FMTLIB_H_ +#ifndef BOOTSTRAP_BUILD_FMTLIB_H_ +#define BOOTSTRAP_BUILD_FMTLIB_H_ #include "buildcc.h" diff --git a/bootstrap/include/bootstrap/buildcc_spdlog.h b/bootstrap/include/bootstrap/build_spdlog.h similarity index 91% rename from bootstrap/include/bootstrap/buildcc_spdlog.h rename to bootstrap/include/bootstrap/build_spdlog.h index 1f18cecb..f71dab43 100644 --- a/bootstrap/include/bootstrap/buildcc_spdlog.h +++ b/bootstrap/include/bootstrap/build_spdlog.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef BOOTSTRAP_BUILDCC_SPDLOG_H_ -#define BOOTSTRAP_BUILDCC_SPDLOG_H_ +#ifndef BOOTSTRAP_BUILD_SPDLOG_H_ +#define BOOTSTRAP_BUILD_SPDLOG_H_ #include "buildcc.h" diff --git a/bootstrap/include/bootstrap/buildcc_taskflow.h b/bootstrap/include/bootstrap/build_taskflow.h similarity index 90% rename from bootstrap/include/bootstrap/buildcc_taskflow.h rename to bootstrap/include/bootstrap/build_taskflow.h index caf119fe..f0a70250 100644 --- a/bootstrap/include/bootstrap/buildcc_taskflow.h +++ b/bootstrap/include/bootstrap/build_taskflow.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef BOOTSTRAP_BUILDCC_TASKFLOW_H_ -#define BOOTSTRAP_BUILDCC_TASKFLOW_H_ +#ifndef BOOTSTRAP_BUILD_TASKFLOW_H_ +#define BOOTSTRAP_BUILD_TASKFLOW_H_ #include "buildcc.h" diff --git a/bootstrap/include/bootstrap/buildcc_tpl.h b/bootstrap/include/bootstrap/build_tpl.h similarity index 91% rename from bootstrap/include/bootstrap/buildcc_tpl.h rename to bootstrap/include/bootstrap/build_tpl.h index f1319294..5ac24653 100644 --- a/bootstrap/include/bootstrap/buildcc_tpl.h +++ b/bootstrap/include/bootstrap/build_tpl.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef BOOTSTRAP_BUILDCC_TPL_H_ -#define BOOTSTRAP_BUILDCC_TPL_H_ +#ifndef BOOTSTRAP_BUILD_TPL_H_ +#define BOOTSTRAP_BUILD_TPL_H_ #include "buildcc.h" diff --git a/bootstrap/src/buildcc_cli11.cpp b/bootstrap/src/build_cli11.cpp similarity index 95% rename from bootstrap/src/buildcc_cli11.cpp rename to bootstrap/src/build_cli11.cpp index a46907bc..fa900aa7 100644 --- a/bootstrap/src/buildcc_cli11.cpp +++ b/bootstrap/src/build_cli11.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "bootstrap/buildcc_cli11.h" +#include "bootstrap/build_cli11.h" namespace buildcc { diff --git a/bootstrap/src/buildcc_flatbuffers.cpp b/bootstrap/src/build_flatbuffers.cpp similarity index 98% rename from bootstrap/src/buildcc_flatbuffers.cpp rename to bootstrap/src/build_flatbuffers.cpp index 2ff902a5..64291bdd 100644 --- a/bootstrap/src/buildcc_flatbuffers.cpp +++ b/bootstrap/src/build_flatbuffers.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "bootstrap/buildcc_flatbuffers.h" +#include "bootstrap/build_flatbuffers.h" namespace { diff --git a/bootstrap/src/buildcc_fmtlib.cpp b/bootstrap/src/build_fmtlib.cpp similarity index 95% rename from bootstrap/src/buildcc_fmtlib.cpp rename to bootstrap/src/build_fmtlib.cpp index c56e4d92..0ce2aa34 100644 --- a/bootstrap/src/buildcc_fmtlib.cpp +++ b/bootstrap/src/build_fmtlib.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "bootstrap/buildcc_fmtlib.h" +#include "bootstrap/build_fmtlib.h" namespace buildcc { diff --git a/bootstrap/src/buildcc_spdlog.cpp b/bootstrap/src/build_spdlog.cpp similarity index 96% rename from bootstrap/src/buildcc_spdlog.cpp rename to bootstrap/src/build_spdlog.cpp index 667546d5..483807fe 100644 --- a/bootstrap/src/buildcc_spdlog.cpp +++ b/bootstrap/src/build_spdlog.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "bootstrap/buildcc_spdlog.h" +#include "bootstrap/build_spdlog.h" namespace buildcc { diff --git a/bootstrap/src/buildcc_taskflow.cpp b/bootstrap/src/build_taskflow.cpp similarity index 95% rename from bootstrap/src/buildcc_taskflow.cpp rename to bootstrap/src/build_taskflow.cpp index ca439998..9d945194 100644 --- a/bootstrap/src/buildcc_taskflow.cpp +++ b/bootstrap/src/build_taskflow.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "bootstrap/buildcc_taskflow.h" +#include "bootstrap/build_taskflow.h" namespace buildcc { diff --git a/bootstrap/src/buildcc_tpl.cpp b/bootstrap/src/build_tpl.cpp similarity index 96% rename from bootstrap/src/buildcc_tpl.cpp rename to bootstrap/src/build_tpl.cpp index b55cac9f..5fbdf513 100644 --- a/bootstrap/src/buildcc_tpl.cpp +++ b/bootstrap/src/build_tpl.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "bootstrap/buildcc_tpl.h" +#include "bootstrap/build_tpl.h" namespace buildcc { From 324945bc311981d923cf46a621f4329df143ce86 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 05:06:24 -0800 Subject: [PATCH 32/62] Update main.buildcc.cpp --- bootstrap/main.buildcc.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index 345bdaaf..2b1bb896 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -16,12 +16,12 @@ #include "buildcc.h" -#include "bootstrap/buildcc_cli11.h" -#include "bootstrap/buildcc_flatbuffers.h" -#include "bootstrap/buildcc_fmtlib.h" -#include "bootstrap/buildcc_spdlog.h" -#include "bootstrap/buildcc_taskflow.h" -#include "bootstrap/buildcc_tpl.h" +#include "bootstrap/build_cli11.h" +#include "bootstrap/build_flatbuffers.h" +#include "bootstrap/build_fmtlib.h" +#include "bootstrap/build_spdlog.h" +#include "bootstrap/build_taskflow.h" +#include "bootstrap/build_tpl.h" using namespace buildcc; From 0c7a82b2444ac1dcdd33e23a8f6ab527c4000adf Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 05:11:58 -0800 Subject: [PATCH 33/62] Added build_buildcc files --- bootstrap/CMakeLists.txt | 2 ++ bootstrap/include/bootstrap/build_buildcc.h | 35 +++++++++++++++++++++ bootstrap/src/build_buildcc.cpp | 29 +++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 bootstrap/include/bootstrap/build_buildcc.h create mode 100644 bootstrap/src/build_buildcc.cpp diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt index 2567fdee..42e62912 100644 --- a/bootstrap/CMakeLists.txt +++ b/bootstrap/CMakeLists.txt @@ -8,6 +8,8 @@ target_sources(buildcc_lib_bootstrap PRIVATE src/build_spdlog.cpp src/build_taskflow.cpp src/build_tpl.cpp + + src/build_buildcc.cpp ) target_include_directories(buildcc_lib_bootstrap PRIVATE include diff --git a/bootstrap/include/bootstrap/build_buildcc.h b/bootstrap/include/bootstrap/build_buildcc.h new file mode 100644 index 00000000..c9605747 --- /dev/null +++ b/bootstrap/include/bootstrap/build_buildcc.h @@ -0,0 +1,35 @@ +/* + * Copyright 2021 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 BOOTSTRAP_BUILD_BUILDCC_H_ +#define BOOTSTRAP_BUILD_BUILDCC_H_ + +#include "buildcc.h" + +namespace buildcc { + +// TODO, Remove schema_gen +void buildcc_use_existing_cb( + BaseTarget &target, const base::Generator &schema_gen, + const TargetInfo &flatbuffers_ho, const TargetInfo &fmt_ho, + const TargetInfo &spdlog_ho, const TargetInfo &cli11_ho, + const TargetInfo &taskflow_ho, const BaseTarget &tpl); + +void buildcc_cb(BaseTarget &target); + +} // namespace buildcc + +#endif diff --git a/bootstrap/src/build_buildcc.cpp b/bootstrap/src/build_buildcc.cpp new file mode 100644 index 00000000..f14b2bb4 --- /dev/null +++ b/bootstrap/src/build_buildcc.cpp @@ -0,0 +1,29 @@ +/* + * Copyright 2021 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 "bootstrap/build_buildcc.h" + +namespace buildcc { + +void buildcc_use_existing_cb( + BaseTarget &target, const base::Generator &schema_gen, + const TargetInfo &flatbuffers_ho, const TargetInfo &fmt_ho, + const TargetInfo &spdlog_ho, const TargetInfo &cli11_ho, + const TargetInfo &taskflow_ho, const BaseTarget &tpl) {} + +void buildcc_cb(BaseTarget &target) {} + +} // namespace buildcc From f68469c0ad9cd0576737b4f1feb9524204633136 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 05:16:59 -0800 Subject: [PATCH 34/62] Shifted schema gen dir to build_buildcc --- bootstrap/include/bootstrap/build_buildcc.h | 7 +- bootstrap/main.buildcc.cpp | 164 +------------------- bootstrap/src/build_buildcc.cpp | 140 ++++++++++++++++- 3 files changed, 146 insertions(+), 165 deletions(-) diff --git a/bootstrap/include/bootstrap/build_buildcc.h b/bootstrap/include/bootstrap/build_buildcc.h index c9605747..d0a910f4 100644 --- a/bootstrap/include/bootstrap/build_buildcc.h +++ b/bootstrap/include/bootstrap/build_buildcc.h @@ -21,15 +21,14 @@ namespace buildcc { -// TODO, Remove schema_gen -void buildcc_use_existing_cb( +void schema_gen_cb(base::Generator &generator, const BaseTarget &flatc_exe); + +void buildcc_use_existing_targets_cb( BaseTarget &target, const base::Generator &schema_gen, const TargetInfo &flatbuffers_ho, const TargetInfo &fmt_ho, const TargetInfo &spdlog_ho, const TargetInfo &cli11_ho, const TargetInfo &taskflow_ho, const BaseTarget &tpl); -void buildcc_cb(BaseTarget &target); - } // namespace buildcc #endif diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index 2b1bb896..746f7b7a 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -23,22 +23,13 @@ #include "bootstrap/build_taskflow.h" #include "bootstrap/build_tpl.h" +#include "bootstrap/build_buildcc.h" + using namespace buildcc; static void clean_cb(); - static void global_flags_cb(TargetInfo &global_info, const BaseToolchain &toolchain); - -static void schema_gen_cb(base::Generator &generator, - const BaseTarget &flatc_exe); - -static void buildcc_cb(BaseTarget &target, const base::Generator &schema_gen, - const TargetInfo &flatbuffers_ho, - const TargetInfo &fmt_ho, const TargetInfo &spdlog_ho, - const TargetInfo &cli11_ho, - const TargetInfo &taskflow_ho, const BaseTarget &tpl); - static void hybrid_simple_example_cb(BaseTarget &target, const BaseTarget &libbuildcc); @@ -94,9 +85,9 @@ int main(int argc, char **argv) { // TODO, Make this a generic selection between StaticTarget and DynamicTarget StaticTarget_generic buildcc_lib("libbuildcc", toolchain, "buildcc"); reg.CallbackIf(arg_toolchain.state, global_flags_cb, buildcc_lib, toolchain); - reg.Build(arg_toolchain.state, buildcc_cb, buildcc_lib, schema_gen, - flatbuffers_ho_lib, fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib, - taskflow_ho_lib, tpl_lib); + reg.Build(arg_toolchain.state, buildcc_use_existing_targets_cb, buildcc_lib, + schema_gen, flatbuffers_ho_lib, fmt_ho_lib, spdlog_ho_lib, + cli11_ho_lib, taskflow_ho_lib, tpl_lib); reg.Dep(buildcc_lib, schema_gen); reg.Dep(buildcc_lib, tpl_lib); @@ -106,8 +97,8 @@ int main(int argc, char **argv) { buildcc_hybrid_simple_example, buildcc_lib); reg.Dep(buildcc_hybrid_simple_example, buildcc_lib); + // Runners reg.RunBuild(); - reg.RunTest(); // - Clang Compile Commands @@ -145,149 +136,6 @@ static void global_flags_cb(TargetInfo &global_info, } } -static void schema_gen_cb(base::Generator &generator, - const BaseTarget &flatc_exe) { - generator.AddInput("{gen_root_dir}/path.fbs", "path_fbs"); - generator.AddInput("{gen_root_dir}/generator.fbs", "generator_fbs"); - generator.AddInput("{gen_root_dir}/target.fbs", "target_fbs"); - - generator.AddOutput("{gen_build_dir}/path_generated.h"); - generator.AddOutput("{gen_build_dir}/generator_generated.h"); - generator.AddOutput("{gen_build_dir}/target_generated.h"); - - generator.AddDefaultArguments({ - {"flatc_compiler", fmt::format("{}", flatc_exe.GetTargetPath())}, - }); - // generator.AddCommand("{flatc_compiler} --help"); - generator.AddCommand( - "{flatc_compiler} -o {gen_build_dir} -I {gen_root_dir} --gen-object-api " - "--cpp {path_fbs} {generator_fbs} {target_fbs}"); - - generator.Build(); -} - -static void buildcc_cb(BaseTarget &target, const base::Generator &schema_gen, - const TargetInfo &flatbuffers_ho, - const TargetInfo &fmt_ho, const TargetInfo &spdlog_ho, - const TargetInfo &cli11_ho, - const TargetInfo &taskflow_ho, const BaseTarget &tpl) { - // NOTE, Build as single lib - target.AddIncludeDir("", true); - const std::string &schema_build_dir = - schema_gen.GetValueByIdentifier("gen_build_dir"); - target.AddIncludeDirAbsolute(schema_build_dir, true); - - // ENV - target.GlobSources("lib/env/src"); - target.AddIncludeDir("lib/env/include"); - target.GlobHeaders("lib/env/include/env"); - - // COMMAND - target.GlobSources("lib/command/src"); - target.AddIncludeDir("lib/command/include"); - target.GlobHeaders("lib/command/include/command"); - - // TOOLCHAIN - target.AddIncludeDir("lib/toolchain/include"); - target.GlobHeaders("lib/toolchain/include/toolchain"); - - // TARGET - target.GlobSources("lib/target/src/common"); - target.GlobSources("lib/target/src/generator"); - target.GlobSources("lib/target/src/api"); - target.GlobSources("lib/target/src/target"); - target.GlobSources("lib/target/src/target/friend"); - - target.AddIncludeDir("lib/target/include"); - target.GlobHeaders("lib/target/include/target"); - target.GlobHeaders("lib/target/include/target/api"); - target.GlobHeaders("lib/target/include/target/base"); - target.GlobHeaders("lib/target/include/target/common"); - target.GlobHeaders("lib/target/include/target/friend"); - target.GlobHeaders("lib/target/include/target/interface"); - target.GlobHeaders("lib/target/include/target/private"); - - // ARGS - target.GlobSources("lib/args/src"); - target.AddIncludeDir("lib/args/include"); - target.GlobHeaders("lib/args/include/args"); - - // Specialized Toolchains - target.AddIncludeDir("toolchains/include"); - target.GlobHeaders("toolchains/include/toolchains"); - - // Specialized Targets - target.AddIncludeDir("targets/include"); - target.GlobHeaders("targets/include/targets"); - - // Plugins - target.GlobSources("plugins/src"); - target.AddIncludeDir("plugins/include"); - target.GlobHeaders("plugins/include/plugins"); - - // Third Party libraries - - const std::initializer_list kInsertOptions{ - SyncOption::IncludeDirs, - SyncOption::HeaderFiles, - }; - - // FLATBUFFERS HO - target.Insert(flatbuffers_ho, kInsertOptions); - - // FMT HO - target.Insert(fmt_ho, kInsertOptions); - - // SPDLOG HO - target.Insert(spdlog_ho, kInsertOptions); - - // CLI11 HO - target.Insert(cli11_ho, kInsertOptions); - - // TASKFLOW HO - target.Insert(taskflow_ho, kInsertOptions); - - // TPL LIB - target.AddLibDep(tpl); - target.Insert(tpl, kInsertOptions); - - if constexpr (env::is_win()) { - // TODO, Clang - switch (target.GetToolchain().GetId()) { - case ToolchainId::Gcc: - case ToolchainId::MinGW: { - target.AddPreprocessorFlag("-DFMT_HEADER_ONLY=1"); - target.AddPreprocessorFlag("-DSPDLOG_FMT_EXTERNAL"); - // For MINGW - target.AddLinkFlag("-Wl,--allow-multiple-definition"); - } break; - case ToolchainId::Msvc: { - target.AddPreprocessorFlag("/DFMT_HEADER_ONLY=1"); - target.AddPreprocessorFlag("/DSPDLOG_FMT_EXTERNAL"); - } break; - default: - break; - } - } - - if constexpr (env::is_linux()) { - // TODO, Clang - switch (target.GetToolchain().GetId()) { - case ToolchainId::Gcc: { - target.AddPreprocessorFlag("-DFMT_HEADER_ONLY=1"); - target.AddPreprocessorFlag("-DSPDLOG_FMT_EXTERNAL"); - target.AddLibDep("-lpthread"); - } break; - default: - break; - } - } - - // TODO, Other OS's - - target.Build(); -} - static void hybrid_simple_example_cb(BaseTarget &target, const BaseTarget &libbuildcc) { target.Insert(libbuildcc, { diff --git a/bootstrap/src/build_buildcc.cpp b/bootstrap/src/build_buildcc.cpp index f14b2bb4..845adafd 100644 --- a/bootstrap/src/build_buildcc.cpp +++ b/bootstrap/src/build_buildcc.cpp @@ -18,12 +18,146 @@ namespace buildcc { -void buildcc_use_existing_cb( +void schema_gen_cb(base::Generator &generator, const BaseTarget &flatc_exe) { + generator.AddInput("{gen_root_dir}/path.fbs", "path_fbs"); + generator.AddInput("{gen_root_dir}/generator.fbs", "generator_fbs"); + generator.AddInput("{gen_root_dir}/target.fbs", "target_fbs"); + + generator.AddOutput("{gen_build_dir}/path_generated.h"); + generator.AddOutput("{gen_build_dir}/generator_generated.h"); + generator.AddOutput("{gen_build_dir}/target_generated.h"); + + generator.AddDefaultArguments({ + {"flatc_compiler", fmt::format("{}", flatc_exe.GetTargetPath())}, + }); + // generator.AddCommand("{flatc_compiler} --help"); + generator.AddCommand( + "{flatc_compiler} -o {gen_build_dir} -I {gen_root_dir} --gen-object-api " + "--cpp {path_fbs} {generator_fbs} {target_fbs}"); + + generator.Build(); +} + +void buildcc_use_existing_targets_cb( BaseTarget &target, const base::Generator &schema_gen, const TargetInfo &flatbuffers_ho, const TargetInfo &fmt_ho, const TargetInfo &spdlog_ho, const TargetInfo &cli11_ho, - const TargetInfo &taskflow_ho, const BaseTarget &tpl) {} + const TargetInfo &taskflow_ho, const BaseTarget &tpl) { + // NOTE, Build as single lib + target.AddIncludeDir("", true); + const std::string &schema_build_dir = + schema_gen.GetValueByIdentifier("gen_build_dir"); + target.AddIncludeDirAbsolute(schema_build_dir, true); + + // ENV + target.GlobSources("lib/env/src"); + target.AddIncludeDir("lib/env/include"); + target.GlobHeaders("lib/env/include/env"); + + // COMMAND + target.GlobSources("lib/command/src"); + target.AddIncludeDir("lib/command/include"); + target.GlobHeaders("lib/command/include/command"); + + // TOOLCHAIN + target.AddIncludeDir("lib/toolchain/include"); + target.GlobHeaders("lib/toolchain/include/toolchain"); + + // TARGET + target.GlobSources("lib/target/src/common"); + target.GlobSources("lib/target/src/generator"); + target.GlobSources("lib/target/src/api"); + target.GlobSources("lib/target/src/target"); + target.GlobSources("lib/target/src/target/friend"); + + target.AddIncludeDir("lib/target/include"); + target.GlobHeaders("lib/target/include/target"); + target.GlobHeaders("lib/target/include/target/api"); + target.GlobHeaders("lib/target/include/target/base"); + target.GlobHeaders("lib/target/include/target/common"); + target.GlobHeaders("lib/target/include/target/friend"); + target.GlobHeaders("lib/target/include/target/interface"); + target.GlobHeaders("lib/target/include/target/private"); + + // ARGS + target.GlobSources("lib/args/src"); + target.AddIncludeDir("lib/args/include"); + target.GlobHeaders("lib/args/include/args"); + + // Specialized Toolchains + target.AddIncludeDir("toolchains/include"); + target.GlobHeaders("toolchains/include/toolchains"); + + // Specialized Targets + target.AddIncludeDir("targets/include"); + target.GlobHeaders("targets/include/targets"); + + // Plugins + target.GlobSources("plugins/src"); + target.AddIncludeDir("plugins/include"); + target.GlobHeaders("plugins/include/plugins"); + + // Third Party libraries + + const std::initializer_list kInsertOptions{ + SyncOption::IncludeDirs, + SyncOption::HeaderFiles, + }; + + // FLATBUFFERS HO + target.Insert(flatbuffers_ho, kInsertOptions); + + // FMT HO + target.Insert(fmt_ho, kInsertOptions); + + // SPDLOG HO + target.Insert(spdlog_ho, kInsertOptions); + + // CLI11 HO + target.Insert(cli11_ho, kInsertOptions); + + // TASKFLOW HO + target.Insert(taskflow_ho, kInsertOptions); + + // TPL LIB + target.AddLibDep(tpl); + target.Insert(tpl, kInsertOptions); + + if constexpr (env::is_win()) { + // TODO, Clang + switch (target.GetToolchain().GetId()) { + case ToolchainId::Gcc: + case ToolchainId::MinGW: { + target.AddPreprocessorFlag("-DFMT_HEADER_ONLY=1"); + target.AddPreprocessorFlag("-DSPDLOG_FMT_EXTERNAL"); + // For MINGW + target.AddLinkFlag("-Wl,--allow-multiple-definition"); + } break; + case ToolchainId::Msvc: { + target.AddPreprocessorFlag("/DFMT_HEADER_ONLY=1"); + target.AddPreprocessorFlag("/DSPDLOG_FMT_EXTERNAL"); + } break; + default: + break; + } + } + + if constexpr (env::is_linux()) { + // TODO, Clang + switch (target.GetToolchain().GetId()) { + case ToolchainId::Gcc: { + target.AddPreprocessorFlag("-DFMT_HEADER_ONLY=1"); + target.AddPreprocessorFlag("-DSPDLOG_FMT_EXTERNAL"); + target.AddLibDep("-lpthread"); + } break; + default: + break; + } + } + + // TODO, Other OS's -void buildcc_cb(BaseTarget &target) {} + target.Build(); +} } // namespace buildcc From 9173b95644e97ddd20593b1d3ccb7a08e2874e8d Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 05:22:27 -0800 Subject: [PATCH 35/62] Update main.buildcc.cpp --- bootstrap/main.buildcc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index 746f7b7a..0bbceb8e 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -127,6 +127,7 @@ static void global_flags_cb(TargetInfo &global_info, global_info.AddCppCompileFlag("-Werror"); break; case ToolchainId::Msvc: + global_info.AddPreprocessorFlag("/D_CRT_SECURE_NO_WARNINGS"); global_info.AddCppCompileFlag("/std:c++17"); global_info.AddCppCompileFlag("/Ot"); global_info.AddCppCompileFlag("/W4"); From a32e2c52d5bc18286f03c249c2ea5cf86f43806a Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 05:23:52 -0800 Subject: [PATCH 36/62] Rename base::Generator to BaseGenerator --- bootstrap/include/bootstrap/build_buildcc.h | 4 ++-- bootstrap/main.buildcc.cpp | 2 +- bootstrap/src/build_buildcc.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bootstrap/include/bootstrap/build_buildcc.h b/bootstrap/include/bootstrap/build_buildcc.h index d0a910f4..77c34ec3 100644 --- a/bootstrap/include/bootstrap/build_buildcc.h +++ b/bootstrap/include/bootstrap/build_buildcc.h @@ -21,10 +21,10 @@ namespace buildcc { -void schema_gen_cb(base::Generator &generator, const BaseTarget &flatc_exe); +void schema_gen_cb(BaseGenerator &generator, const BaseTarget &flatc_exe); void buildcc_use_existing_targets_cb( - BaseTarget &target, const base::Generator &schema_gen, + BaseTarget &target, const BaseGenerator &schema_gen, const TargetInfo &flatbuffers_ho, const TargetInfo &fmt_ho, const TargetInfo &spdlog_ho, const TargetInfo &cli11_ho, const TargetInfo &taskflow_ho, const BaseTarget &tpl); diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index 0bbceb8e..637dc93b 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -51,7 +51,7 @@ int main(int argc, char **argv) { reg.Build(arg_toolchain.state, build_flatc_exe_cb, flatc_exe); // Schema - base::Generator schema_gen("schema_gen", "buildcc/schema"); + BaseGenerator schema_gen("schema_gen", "buildcc/schema"); reg.Build(schema_gen_cb, schema_gen, flatc_exe); reg.Dep(schema_gen, flatc_exe); diff --git a/bootstrap/src/build_buildcc.cpp b/bootstrap/src/build_buildcc.cpp index 845adafd..4c735366 100644 --- a/bootstrap/src/build_buildcc.cpp +++ b/bootstrap/src/build_buildcc.cpp @@ -18,7 +18,7 @@ namespace buildcc { -void schema_gen_cb(base::Generator &generator, const BaseTarget &flatc_exe) { +void schema_gen_cb(BaseGenerator &generator, const BaseTarget &flatc_exe) { generator.AddInput("{gen_root_dir}/path.fbs", "path_fbs"); generator.AddInput("{gen_root_dir}/generator.fbs", "generator_fbs"); generator.AddInput("{gen_root_dir}/target.fbs", "target_fbs"); @@ -39,7 +39,7 @@ void schema_gen_cb(base::Generator &generator, const BaseTarget &flatc_exe) { } void buildcc_use_existing_targets_cb( - BaseTarget &target, const base::Generator &schema_gen, + BaseTarget &target, const BaseGenerator &schema_gen, const TargetInfo &flatbuffers_ho, const TargetInfo &fmt_ho, const TargetInfo &spdlog_ho, const TargetInfo &cli11_ho, const TargetInfo &taskflow_ho, const BaseTarget &tpl) { From 441d76c28f6c887bc94d8a78141054b2debb0109 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 05:29:41 -0800 Subject: [PATCH 37/62] Update config_default.toml --- bootstrap/config_default.toml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/bootstrap/config_default.toml b/bootstrap/config_default.toml index ecaeb577..a3134757 100644 --- a/bootstrap/config_default.toml +++ b/bootstrap/config_default.toml @@ -3,15 +3,3 @@ build_dir="../_build_bootstrap" loglevel="trace" clean=false - -# [toolchain.custom] -# build = true -# test = true - -# id = "msvc" -# name = "msvc" -# asm_compiler = "cl" -# c_compiler = "cl" -# cpp_compiler = "cl" -# archiver = "lib" -# linker = "link" From 912c9460c501d8db9f19087152d1af8928b0dffe Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 05:36:54 -0800 Subject: [PATCH 38/62] Update build_flatbuffers.cpp --- bootstrap/src/build_flatbuffers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrap/src/build_flatbuffers.cpp b/bootstrap/src/build_flatbuffers.cpp index 64291bdd..01039ae0 100644 --- a/bootstrap/src/build_flatbuffers.cpp +++ b/bootstrap/src/build_flatbuffers.cpp @@ -59,8 +59,8 @@ const std::vector kFlatcGccCppCompileFlags{ }; const std::vector kFlatcMsvcCppCompileFlags{ - "/MP", "/MT", "/GS", "/fp:precise", - "/Zc:wchar_t", "/Zc:forScope", "/Zc:inline", "/GR", + "/MP", "/MT", "/GS", "/GR", + "/fp:precise", "/Zc:wchar_t", "/Zc:forScope", "/Zc:inline", }; } // namespace From 4d846c5909933d5dd3d49101466f4104fc74fe08 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 05:43:12 -0800 Subject: [PATCH 39/62] Updated naming --- bootstrap/include/bootstrap/build_buildcc.h | 9 ++++----- bootstrap/main.buildcc.cpp | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bootstrap/include/bootstrap/build_buildcc.h b/bootstrap/include/bootstrap/build_buildcc.h index 77c34ec3..a0c37e09 100644 --- a/bootstrap/include/bootstrap/build_buildcc.h +++ b/bootstrap/include/bootstrap/build_buildcc.h @@ -23,11 +23,10 @@ namespace buildcc { void schema_gen_cb(BaseGenerator &generator, const BaseTarget &flatc_exe); -void buildcc_use_existing_targets_cb( - BaseTarget &target, const BaseGenerator &schema_gen, - const TargetInfo &flatbuffers_ho, const TargetInfo &fmt_ho, - const TargetInfo &spdlog_ho, const TargetInfo &cli11_ho, - const TargetInfo &taskflow_ho, const BaseTarget &tpl); +void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen, + const TargetInfo &flatbuffers_ho, const TargetInfo &fmt_ho, + const TargetInfo &spdlog_ho, const TargetInfo &cli11_ho, + const TargetInfo &taskflow_ho, const BaseTarget &tpl); } // namespace buildcc diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index 637dc93b..04c88fc5 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -85,9 +85,9 @@ int main(int argc, char **argv) { // TODO, Make this a generic selection between StaticTarget and DynamicTarget StaticTarget_generic buildcc_lib("libbuildcc", toolchain, "buildcc"); reg.CallbackIf(arg_toolchain.state, global_flags_cb, buildcc_lib, toolchain); - reg.Build(arg_toolchain.state, buildcc_use_existing_targets_cb, buildcc_lib, - schema_gen, flatbuffers_ho_lib, fmt_ho_lib, spdlog_ho_lib, - cli11_ho_lib, taskflow_ho_lib, tpl_lib); + reg.Build(arg_toolchain.state, buildcc_cb, buildcc_lib, schema_gen, + flatbuffers_ho_lib, fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib, + taskflow_ho_lib, tpl_lib); reg.Dep(buildcc_lib, schema_gen); reg.Dep(buildcc_lib, tpl_lib); From 675f0cb48159ad31b9cbba7d6c2eea9315e3f74f Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 06:00:26 -0800 Subject: [PATCH 40/62] Update build_buildcc.cpp --- bootstrap/src/build_buildcc.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bootstrap/src/build_buildcc.cpp b/bootstrap/src/build_buildcc.cpp index 4c735366..7432964a 100644 --- a/bootstrap/src/build_buildcc.cpp +++ b/bootstrap/src/build_buildcc.cpp @@ -38,11 +38,10 @@ void schema_gen_cb(BaseGenerator &generator, const BaseTarget &flatc_exe) { generator.Build(); } -void buildcc_use_existing_targets_cb( - BaseTarget &target, const BaseGenerator &schema_gen, - const TargetInfo &flatbuffers_ho, const TargetInfo &fmt_ho, - const TargetInfo &spdlog_ho, const TargetInfo &cli11_ho, - const TargetInfo &taskflow_ho, const BaseTarget &tpl) { +void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen, + const TargetInfo &flatbuffers_ho, const TargetInfo &fmt_ho, + const TargetInfo &spdlog_ho, const TargetInfo &cli11_ho, + const TargetInfo &taskflow_ho, const BaseTarget &tpl) { // NOTE, Build as single lib target.AddIncludeDir("", true); const std::string &schema_build_dir = From 8ea658fc58fee586ba6d56db8fe4f3b74bfe8d05 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 08:00:50 -0800 Subject: [PATCH 41/62] Update main.buildcc.cpp --- bootstrap/main.buildcc.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index 04c88fc5..d7107e2f 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -35,20 +35,21 @@ static void hybrid_simple_example_cb(BaseTarget &target, int main(int argc, char **argv) { Args args; - Args::ToolchainArg arg_toolchain; - args.AddToolchain("custom", "Host Toolchain", arg_toolchain); + Args::ToolchainArg custom_toolchain_arg; + args.AddToolchain("custom", "Host Toolchain", custom_toolchain_arg); args.Parse(argc, argv); Register reg(args); reg.Clean(clean_cb); - BaseToolchain toolchain = arg_toolchain.ConstructToolchain(); + BaseToolchain toolchain = custom_toolchain_arg.ConstructToolchain(); // Flatc Executable ExecutableTarget_generic flatc_exe("flatc", toolchain, "third_party/flatbuffers"); - reg.CallbackIf(arg_toolchain.state, global_flags_cb, flatc_exe, toolchain); - reg.Build(arg_toolchain.state, build_flatc_exe_cb, flatc_exe); + reg.CallbackIf(custom_toolchain_arg.state, global_flags_cb, flatc_exe, + toolchain); + reg.Build(custom_toolchain_arg.state, build_flatc_exe_cb, flatc_exe); // Schema BaseGenerator schema_gen("schema_gen", "buildcc/schema"); @@ -79,13 +80,15 @@ int main(int argc, char **argv) { // TODO, Make this a generic selection between StaticTarget and DynamicTarget StaticTarget_generic tpl_lib("libtpl", toolchain, "third_party/tiny-process-library"); - reg.CallbackIf(arg_toolchain.state, global_flags_cb, tpl_lib, toolchain); - reg.Build(arg_toolchain.state, tpl_cb, tpl_lib); + reg.CallbackIf(custom_toolchain_arg.state, global_flags_cb, tpl_lib, + toolchain); + reg.Build(custom_toolchain_arg.state, tpl_cb, tpl_lib); // TODO, Make this a generic selection between StaticTarget and DynamicTarget StaticTarget_generic buildcc_lib("libbuildcc", toolchain, "buildcc"); - reg.CallbackIf(arg_toolchain.state, global_flags_cb, buildcc_lib, toolchain); - reg.Build(arg_toolchain.state, buildcc_cb, buildcc_lib, schema_gen, + reg.CallbackIf(custom_toolchain_arg.state, global_flags_cb, buildcc_lib, + toolchain); + reg.Build(custom_toolchain_arg.state, buildcc_cb, buildcc_lib, schema_gen, flatbuffers_ho_lib, fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib, taskflow_ho_lib, tpl_lib); reg.Dep(buildcc_lib, schema_gen); @@ -93,7 +96,7 @@ int main(int argc, char **argv) { ExecutableTarget_generic buildcc_hybrid_simple_example( "buildcc_hybrid_simple_example", toolchain, "example/hybrid/simple"); - reg.Build(arg_toolchain.state, hybrid_simple_example_cb, + reg.Build(custom_toolchain_arg.state, hybrid_simple_example_cb, buildcc_hybrid_simple_example, buildcc_lib); reg.Dep(buildcc_hybrid_simple_example, buildcc_lib); From 5c7fba90a7ddec07b2732c9b0e45be27d4f1f053 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 21:11:01 -0800 Subject: [PATCH 42/62] Update args.h --- buildcc/lib/args/include/args/args.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildcc/lib/args/include/args/args.h b/buildcc/lib/args/include/args/args.h index be325c44..99f9f06f 100644 --- a/buildcc/lib/args/include/args/args.h +++ b/buildcc/lib/args/include/args/args.h @@ -66,7 +66,7 @@ class Args { cpp_compiler(initial_cpp_compiler), archiver(initial_archiver), linker(initial_linker) {} - base::Toolchain ConstructToolchain() { + base::Toolchain ConstructToolchain() const { base::Toolchain toolchain(id, name, asm_compiler, c_compiler, cpp_compiler, archiver, linker); return toolchain; From ebbf70c07d18bc1956c3f20f88f8e9d992f5888e Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 21:49:01 -0800 Subject: [PATCH 43/62] Added persistent storage --- buildcc/buildcc.h | 1 + buildcc/lib/args/CMakeLists.txt | 1 + .../args/include/args/persistent_storage.h | 91 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 buildcc/lib/args/include/args/persistent_storage.h diff --git a/buildcc/buildcc.h b/buildcc/buildcc.h index 6d7ca2f2..8e533a96 100644 --- a/buildcc/buildcc.h +++ b/buildcc/buildcc.h @@ -57,5 +57,6 @@ // BuildCC Modules #include "args/args.h" #include "args/register.h" +#include "args/persistent_storage.h" #endif diff --git a/buildcc/lib/args/CMakeLists.txt b/buildcc/lib/args/CMakeLists.txt index 949b51b1..56f7a32b 100644 --- a/buildcc/lib/args/CMakeLists.txt +++ b/buildcc/lib/args/CMakeLists.txt @@ -55,6 +55,7 @@ set(ARGS_SRCS src/tasks.cpp include/args/args.h include/args/register.h + include/args/persistent_storage.h ) if(${BUILDCC_BUILD_AS_SINGLE_LIB}) diff --git a/buildcc/lib/args/include/args/persistent_storage.h b/buildcc/lib/args/include/args/persistent_storage.h new file mode 100644 index 00000000..04842832 --- /dev/null +++ b/buildcc/lib/args/include/args/persistent_storage.h @@ -0,0 +1,91 @@ +/* + * Copyright 2021 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 ARGS_PERSISTENT_STORAGE_H_ +#define ARGS_PERSISTENT_STORAGE_H_ + +#include +#include +#include +#include + +#include "env/assert_fatal.h" + +namespace buildcc { + +class PersistentStorage { +public: + PersistentStorage() {} + ~PersistentStorage() { + for (const auto &ptr_iter : ptrs_) { + ptr_iter.second.destructor(); + } + ptrs_.clear(); + env::assert_fatal(ptrs_.empty(), "Memory not deallocated"); + } + + template + void Add(const std::string &identifier, Params &&...params) { + T *ptr = new T(std::forward(params)...); + PtrMetadata metadata; + metadata.ptr = (void *)ptr; + metadata.typeid_name = typeid(T).name(); + metadata.destructor = [&, identifier]() { + env::log_info("Removing", identifier); + Remove(identifier); + }; + ptrs_.emplace(identifier, metadata); + } + + template T &Ref(const std::string &identifier) { + PtrMetadata &metadata = ptrs_.at(identifier); + env::assert_fatal( + typeid(T).name() == metadata.typeid_name, + fmt::format("Wrong type, expects: {}", metadata.typeid_name)); + T *p = (T *)metadata.ptr; + return *p; + } + + template const T &ConstRef(const std::string &identifier) const { + return GetRef(identifier); + } + +private: + /** + * @brief + * @param ptr Can hold data of any type + * @param typeid_name We cannot store a template type so this is the next best + * thing + * @param desstructor Destructor callback to delete ptr + */ + struct PtrMetadata { + void *ptr; + std::string typeid_name; + std::function destructor; + }; + +private: + template void Remove(const std::string &identifier) { + T *ptr = (T *)(ptrs_.at(identifier).ptr); + delete ptr; + } + + std::unordered_map ptrs_; +}; + +} // namespace buildcc + +#endif From 2af3bc7e508a44d6b939a1c2fe1fca5b55143cf6 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 21:49:24 -0800 Subject: [PATCH 44/62] 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 04842832..e22ce7d9 100644 --- a/buildcc/lib/args/include/args/persistent_storage.h +++ b/buildcc/lib/args/include/args/persistent_storage.h @@ -60,7 +60,7 @@ class PersistentStorage { } template const T &ConstRef(const std::string &identifier) const { - return GetRef(identifier); + return Get(identifier); } private: From 4f98b41795b60e56978f3f4ec97f2b3c9ad85d90 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 21:50:54 -0800 Subject: [PATCH 45/62] 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 e22ce7d9..375995de 100644 --- a/buildcc/lib/args/include/args/persistent_storage.h +++ b/buildcc/lib/args/include/args/persistent_storage.h @@ -60,7 +60,7 @@ class PersistentStorage { } template const T &ConstRef(const std::string &identifier) const { - return Get(identifier); + return Ref(identifier); } private: From c5fdaac85f64d1a754ce2db0e8c742494d77f8f7 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 21:57:41 -0800 Subject: [PATCH 46/62] Update persistent_storage.h --- buildcc/lib/args/include/args/persistent_storage.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buildcc/lib/args/include/args/persistent_storage.h b/buildcc/lib/args/include/args/persistent_storage.h index 375995de..68919dd0 100644 --- a/buildcc/lib/args/include/args/persistent_storage.h +++ b/buildcc/lib/args/include/args/persistent_storage.h @@ -24,6 +24,8 @@ #include "env/assert_fatal.h" +#include "fmt/format.h" + namespace buildcc { class PersistentStorage { From bb2fd21b82b3a679c3a2e281235843bf7e6edb25 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 22:20:29 -0800 Subject: [PATCH 47/62] Update generator.h --- buildcc/lib/target/include/target/generator.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/buildcc/lib/target/include/target/generator.h b/buildcc/lib/target/include/target/generator.h index fe41eabc..b2d6baec 100644 --- a/buildcc/lib/target/include/target/generator.h +++ b/buildcc/lib/target/include/target/generator.h @@ -47,6 +47,7 @@ class Generator : public BuilderInterface { loader_(name, generator_build_dir_), parallel_(parallel) { Initialize(); } + virtual ~Generator() {} Generator(const Generator &generator) = delete; /** @@ -98,8 +99,8 @@ class Generator : public BuilderInterface { const fs::path &GetBinaryPath() const { return loader_.GetBinaryPath(); } tf::Taskflow &GetTaskflow() { return tf_; } - const std::string &GetName() { return name_; } - env::TaskState GetTaskState() { return task_state_; } + const std::string &GetName() const { return name_; } + env::TaskState GetTaskState() const { return task_state_; } const std::string & GetValueByIdentifier(const std::string &file_identifier) const; From 0926985c6aa254e3b43837add87801e0b49d52c7 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 22:21:58 -0800 Subject: [PATCH 48/62] Added test_persistent_storage.cpp --- buildcc/lib/args/CMakeLists.txt | 8 +++ .../lib/args/test/test_persistent_storage.cpp | 52 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 buildcc/lib/args/test/test_persistent_storage.cpp diff --git a/buildcc/lib/args/CMakeLists.txt b/buildcc/lib/args/CMakeLists.txt index 56f7a32b..c2f2d3a3 100644 --- a/buildcc/lib/args/CMakeLists.txt +++ b/buildcc/lib/args/CMakeLists.txt @@ -40,12 +40,20 @@ target_link_libraries(test_register PRIVATE mock_args ) +add_executable(test_persistent_storage + test/test_persistent_storage.cpp +) +target_link_libraries(test_persistent_storage PRIVATE mock_args) + add_test(NAME test_args COMMAND test_args WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test ) add_test(NAME test_register COMMAND test_register WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test ) +add_test(NAME test_persistent_storage COMMAND test_persistent_storage + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test +) endif() set(ARGS_SRCS diff --git a/buildcc/lib/args/test/test_persistent_storage.cpp b/buildcc/lib/args/test/test_persistent_storage.cpp new file mode 100644 index 00000000..e73c4dff --- /dev/null +++ b/buildcc/lib/args/test/test_persistent_storage.cpp @@ -0,0 +1,52 @@ +#include "args/persistent_storage.h" + +#include "target/generator.h" +#include "target/target.h" + +// NOTE, Make sure all these includes are AFTER the system and header includes +#include "CppUTest/CommandLineTestRunner.h" +#include "CppUTest/MemoryLeakDetectorNewMacros.h" +#include "CppUTest/TestHarness.h" +#include "CppUTest/Utest.h" +#include "CppUTestExt/MockSupport.h" + +// clang-format off +TEST_GROUP(PersistentStorageTestGroup) +{ +}; +// clang-format on + +buildcc::BaseToolchain gcc(buildcc::ToolchainId::Gcc, "gcc", "as", "gcc", "g++", + "ar", "ld"); + +TEST(PersistentStorageTestGroup, BasicUsage) { + buildcc::PersistentStorage persistent; + persistent.Add("target_identifier", "target_name", + buildcc::TargetType::Executable, gcc, ""); + persistent.Add("generator_identifier", + "generator_name", ""); + + // Usage + persistent.Ref("target_identifier").GetName(); + persistent.Ref("generator_identifier").GetTaskflow(); + + // Automatic cleanup here +} + +TEST(PersistentStorageTestGroup, IncorrectUsage) { + buildcc::PersistentStorage persistent; + persistent.Add("target_identifier", "target_name", + buildcc::TargetType::Executable, gcc, ""); + + // We try to cast to a different type! + CHECK_THROWS(std::exception, + persistent.Ref("target_identifier")); + + // We use a wrong identifier + CHECK_THROWS(std::exception, + persistent.Ref("generator_identifier")); +} + +int main(int ac, char **av) { + return CommandLineTestRunner::RunAllTests(ac, av); +} From c9e2b3fb22ef2d2e6d18fd4f41f8a81ea70431ec Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 22:39:01 -0800 Subject: [PATCH 49/62] Update persistent_storage.h --- buildcc/lib/args/include/args/persistent_storage.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/buildcc/lib/args/include/args/persistent_storage.h b/buildcc/lib/args/include/args/persistent_storage.h index 68919dd0..9bc711ea 100644 --- a/buildcc/lib/args/include/args/persistent_storage.h +++ b/buildcc/lib/args/include/args/persistent_storage.h @@ -52,17 +52,19 @@ class PersistentStorage { ptrs_.emplace(identifier, metadata); } - template T &Ref(const std::string &identifier) { - PtrMetadata &metadata = ptrs_.at(identifier); + template const T &ConstRef(const std::string &identifier) const { + const PtrMetadata &metadata = ptrs_.at(identifier); env::assert_fatal( typeid(T).name() == metadata.typeid_name, fmt::format("Wrong type, expects: {}", metadata.typeid_name)); - T *p = (T *)metadata.ptr; + const T *p = (const T *)metadata.ptr; return *p; } - template const T &ConstRef(const std::string &identifier) const { - return Ref(identifier); + // https://stackoverflow.com/questions/123758/how-do-i-remove-code-duplication-between-similar-const-and-non-const-member-func/123995 + template T &Ref(const std::string &identifier) { + return const_cast( + static_cast(*this).ConstRef(identifier)); } private: From 8d1135a0657402a9ca005f67563e19fa2f613291 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 22:39:07 -0800 Subject: [PATCH 50/62] Update test_persistent_storage.cpp --- buildcc/lib/args/test/test_persistent_storage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildcc/lib/args/test/test_persistent_storage.cpp b/buildcc/lib/args/test/test_persistent_storage.cpp index e73c4dff..f95e74ba 100644 --- a/buildcc/lib/args/test/test_persistent_storage.cpp +++ b/buildcc/lib/args/test/test_persistent_storage.cpp @@ -27,7 +27,7 @@ TEST(PersistentStorageTestGroup, BasicUsage) { "generator_name", ""); // Usage - persistent.Ref("target_identifier").GetName(); + persistent.ConstRef("target_identifier").GetName(); persistent.Ref("generator_identifier").GetTaskflow(); // Automatic cleanup here From 56bb7b069ce3b94c090e3e6370daf794163be8cc Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 1 Dec 2021 22:41:02 -0800 Subject: [PATCH 51/62] Update test_persistent_storage.cpp --- buildcc/lib/args/test/test_persistent_storage.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/buildcc/lib/args/test/test_persistent_storage.cpp b/buildcc/lib/args/test/test_persistent_storage.cpp index f95e74ba..94fece11 100644 --- a/buildcc/lib/args/test/test_persistent_storage.cpp +++ b/buildcc/lib/args/test/test_persistent_storage.cpp @@ -48,5 +48,6 @@ TEST(PersistentStorageTestGroup, IncorrectUsage) { } int main(int ac, char **av) { + buildcc::env::init(fs::current_path(), fs::current_path()); return CommandLineTestRunner::RunAllTests(ac, av); } From 0babca22201fe42fa26085a47aba41ebc390484d Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 2 Dec 2021 00:10:44 -0800 Subject: [PATCH 52/62] Update persistent_storage.h --- .../lib/args/include/args/persistent_storage.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/buildcc/lib/args/include/args/persistent_storage.h b/buildcc/lib/args/include/args/persistent_storage.h index 9bc711ea..3d538eb4 100644 --- a/buildcc/lib/args/include/args/persistent_storage.h +++ b/buildcc/lib/args/include/args/persistent_storage.h @@ -41,17 +41,21 @@ class PersistentStorage { template void Add(const std::string &identifier, Params &&...params) { - T *ptr = new T(std::forward(params)...); + T *ptr = new T(std::forward(params)...); + env::assert_fatal(ptr != nullptr, "System out of memory"); + PtrMetadata metadata; metadata.ptr = (void *)ptr; metadata.typeid_name = typeid(T).name(); - metadata.destructor = [&, identifier]() { - env::log_info("Removing", identifier); - Remove(identifier); + metadata.destructor = [this, identifier, ptr]() { + env::log_info("Cleaning", identifier); + Remove(ptr); }; ptrs_.emplace(identifier, metadata); } + template void Remove(T *ptr) { delete ptr; } + template const T &ConstRef(const std::string &identifier) const { const PtrMetadata &metadata = ptrs_.at(identifier); env::assert_fatal( @@ -82,11 +86,6 @@ class PersistentStorage { }; private: - template void Remove(const std::string &identifier) { - T *ptr = (T *)(ptrs_.at(identifier).ptr); - delete ptr; - } - std::unordered_map ptrs_; }; From 45b2121a0582bd63a1b283c2e53f13d217499c71 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 2 Dec 2021 00:10:47 -0800 Subject: [PATCH 53/62] Update test_persistent_storage.cpp --- buildcc/lib/args/test/test_persistent_storage.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/buildcc/lib/args/test/test_persistent_storage.cpp b/buildcc/lib/args/test/test_persistent_storage.cpp index 94fece11..16079c4e 100644 --- a/buildcc/lib/args/test/test_persistent_storage.cpp +++ b/buildcc/lib/args/test/test_persistent_storage.cpp @@ -47,6 +47,13 @@ TEST(PersistentStorageTestGroup, IncorrectUsage) { persistent.Ref("generator_identifier")); } +std::string &toReference(std::string *pointer) { return *pointer; } + +TEST(PersistentStorageTestGroup, NullptrDelete) { + buildcc::PersistentStorage persistent; + persistent.Remove(nullptr); +} + int main(int ac, char **av) { buildcc::env::init(fs::current_path(), fs::current_path()); return CommandLineTestRunner::RunAllTests(ac, av); From 241bd4d3261ebea59dce0f2fba7f41125a77e76e Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 2 Dec 2021 02:00:12 -0800 Subject: [PATCH 54/62] Update persistent_storage.h --- buildcc/lib/args/include/args/persistent_storage.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/buildcc/lib/args/include/args/persistent_storage.h b/buildcc/lib/args/include/args/persistent_storage.h index 3d538eb4..4c3c5b73 100644 --- a/buildcc/lib/args/include/args/persistent_storage.h +++ b/buildcc/lib/args/include/args/persistent_storage.h @@ -40,7 +40,7 @@ class PersistentStorage { } template - void Add(const std::string &identifier, Params &&...params) { + T &Add(const std::string &identifier, Params &&...params) { T *ptr = new T(std::forward(params)...); env::assert_fatal(ptr != nullptr, "System out of memory"); @@ -52,6 +52,7 @@ class PersistentStorage { Remove(ptr); }; ptrs_.emplace(identifier, metadata); + return *ptr; } template void Remove(T *ptr) { delete ptr; } From 1965c75c3cc7a0382d5c731786cee860fae0a9b1 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 2 Dec 2021 02:00:25 -0800 Subject: [PATCH 55/62] Update main.buildcc.cpp --- bootstrap/main.buildcc.cpp | 113 +++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 48 deletions(-) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index d7107e2f..4b3a0e13 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -33,6 +33,9 @@ static void global_flags_cb(TargetInfo &global_info, static void hybrid_simple_example_cb(BaseTarget &target, const BaseTarget &libbuildcc); +void setup_buildcc_cb(PersistentStorage &storage, Register ®, + const Args::ToolchainArg &custom_toolchain_arg); + int main(int argc, char **argv) { Args args; Args::ToolchainArg custom_toolchain_arg; @@ -44,55 +47,11 @@ int main(int argc, char **argv) { BaseToolchain toolchain = custom_toolchain_arg.ConstructToolchain(); - // Flatc Executable - ExecutableTarget_generic flatc_exe("flatc", toolchain, - "third_party/flatbuffers"); - reg.CallbackIf(custom_toolchain_arg.state, global_flags_cb, flatc_exe, - toolchain); - reg.Build(custom_toolchain_arg.state, build_flatc_exe_cb, flatc_exe); - - // Schema - BaseGenerator schema_gen("schema_gen", "buildcc/schema"); - reg.Build(schema_gen_cb, schema_gen, flatc_exe); - reg.Dep(schema_gen, flatc_exe); - - // Flatbuffers HO lib - TargetInfo flatbuffers_ho_lib("third_party/flatbuffers"); - reg.Callback(flatbuffers_ho_cb, flatbuffers_ho_lib); - - // CLI11 HO lib - TargetInfo cli11_ho_lib("third_party/CLI11"); - reg.Callback(cli11_ho_cb, cli11_ho_lib); - - // fmt HO lib - TargetInfo fmt_ho_lib("third_party/fmt"); - reg.Callback(fmt_ho_cb, fmt_ho_lib); - - // spdlog HO lib - TargetInfo spdlog_ho_lib("third_party/spdlog"); - reg.Callback(spdlog_ho_cb, spdlog_ho_lib); - - // taskflow HO lib - TargetInfo taskflow_ho_lib("third_party/taskflow"); - reg.Callback(taskflow_ho_cb, taskflow_ho_lib); + PersistentStorage storage; + setup_buildcc_cb(storage, reg, custom_toolchain_arg); - // Tiny-process-library lib - // TODO, Make this a generic selection between StaticTarget and DynamicTarget - StaticTarget_generic tpl_lib("libtpl", toolchain, - "third_party/tiny-process-library"); - reg.CallbackIf(custom_toolchain_arg.state, global_flags_cb, tpl_lib, - toolchain); - reg.Build(custom_toolchain_arg.state, tpl_cb, tpl_lib); - - // TODO, Make this a generic selection between StaticTarget and DynamicTarget - StaticTarget_generic buildcc_lib("libbuildcc", toolchain, "buildcc"); - reg.CallbackIf(custom_toolchain_arg.state, global_flags_cb, buildcc_lib, - toolchain); - reg.Build(custom_toolchain_arg.state, buildcc_cb, buildcc_lib, schema_gen, - flatbuffers_ho_lib, fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib, - taskflow_ho_lib, tpl_lib); - reg.Dep(buildcc_lib, schema_gen); - reg.Dep(buildcc_lib, tpl_lib); + const StaticTarget_generic &buildcc_lib = + storage.ConstRef("libbuildcc"); ExecutableTarget_generic buildcc_hybrid_simple_example( "buildcc_hybrid_simple_example", toolchain, "example/hybrid/simple"); @@ -140,6 +99,64 @@ static void global_flags_cb(TargetInfo &global_info, } } +void setup_buildcc_cb(PersistentStorage &storage, Register ®, + const Args::ToolchainArg &custom_toolchain_arg) { + + BaseToolchain toolchain = custom_toolchain_arg.ConstructToolchain(); + + // Flatc Executable + ExecutableTarget_generic &flatc_exe = storage.Add( + "flatc", "flatc", toolchain, "third_party/flatbuffers"); + reg.CallbackIf(custom_toolchain_arg.state, global_flags_cb, flatc_exe, + toolchain); + reg.Build(custom_toolchain_arg.state, build_flatc_exe_cb, flatc_exe); + + // Schema + BaseGenerator &schema_gen = + storage.Add("schema_gen", "schema_gen", "buildcc/schema"); + reg.Build(schema_gen_cb, schema_gen, flatc_exe); + reg.Dep(schema_gen, flatc_exe); + + // Flatbuffers HO lib + TargetInfo flatbuffers_ho_lib("third_party/flatbuffers"); + reg.Callback(flatbuffers_ho_cb, flatbuffers_ho_lib); + + // CLI11 HO lib + TargetInfo cli11_ho_lib("third_party/CLI11"); + reg.Callback(cli11_ho_cb, cli11_ho_lib); + + // fmt HO lib + TargetInfo fmt_ho_lib("third_party/fmt"); + reg.Callback(fmt_ho_cb, fmt_ho_lib); + + // spdlog HO lib + TargetInfo spdlog_ho_lib("third_party/spdlog"); + reg.Callback(spdlog_ho_cb, spdlog_ho_lib); + + // taskflow HO lib + TargetInfo taskflow_ho_lib("third_party/taskflow"); + reg.Callback(taskflow_ho_cb, taskflow_ho_lib); + + // Tiny-process-library lib + // TODO, Make this a generic selection between StaticTarget and DynamicTarget + StaticTarget_generic &tpl_lib = storage.Add( + "libtpl", "libtpl", toolchain, "third_party/tiny-process-library"); + reg.CallbackIf(custom_toolchain_arg.state, global_flags_cb, tpl_lib, + toolchain); + reg.Build(custom_toolchain_arg.state, tpl_cb, tpl_lib); + + // TODO, Make this a generic selection between StaticTarget and DynamicTarget + StaticTarget_generic &buildcc_lib = storage.Add( + "libbuildcc", "libbuildcc", toolchain, "buildcc"); + reg.CallbackIf(custom_toolchain_arg.state, global_flags_cb, buildcc_lib, + toolchain); + reg.Build(custom_toolchain_arg.state, buildcc_cb, buildcc_lib, schema_gen, + flatbuffers_ho_lib, fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib, + taskflow_ho_lib, tpl_lib); + reg.Dep(buildcc_lib, schema_gen); + reg.Dep(buildcc_lib, tpl_lib); +} + static void hybrid_simple_example_cb(BaseTarget &target, const BaseTarget &libbuildcc) { target.Insert(libbuildcc, { From 26aea5a0dcb1f8544ddaa4c15852584a11b478cd Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 2 Dec 2021 02:03:17 -0800 Subject: [PATCH 56/62] Update main.buildcc.cpp --- bootstrap/main.buildcc.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index 4b3a0e13..d9acd7a8 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -30,12 +30,13 @@ using namespace buildcc; static void clean_cb(); static void global_flags_cb(TargetInfo &global_info, const BaseToolchain &toolchain); + +static void setup_buildcc_cb(PersistentStorage &storage, Register ®, + const Args::ToolchainArg &custom_toolchain_arg); + static void hybrid_simple_example_cb(BaseTarget &target, const BaseTarget &libbuildcc); -void setup_buildcc_cb(PersistentStorage &storage, Register ®, - const Args::ToolchainArg &custom_toolchain_arg); - int main(int argc, char **argv) { Args args; Args::ToolchainArg custom_toolchain_arg; @@ -99,8 +100,8 @@ static void global_flags_cb(TargetInfo &global_info, } } -void setup_buildcc_cb(PersistentStorage &storage, Register ®, - const Args::ToolchainArg &custom_toolchain_arg) { +static void setup_buildcc_cb(PersistentStorage &storage, Register ®, + const Args::ToolchainArg &custom_toolchain_arg) { BaseToolchain toolchain = custom_toolchain_arg.ConstructToolchain(); From b83c9859a0a2f5540aad46f80080a7667f0fae05 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 2 Dec 2021 02:05:46 -0800 Subject: [PATCH 57/62] Update main.buildcc.cpp --- bootstrap/main.buildcc.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index d9acd7a8..744678c1 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -32,7 +32,8 @@ static void global_flags_cb(TargetInfo &global_info, const BaseToolchain &toolchain); static void setup_buildcc_cb(PersistentStorage &storage, Register ®, - const Args::ToolchainArg &custom_toolchain_arg); + const Args::ToolchainArg &custom_toolchain_arg, + const BaseToolchain &toolchain); static void hybrid_simple_example_cb(BaseTarget &target, const BaseTarget &libbuildcc); @@ -49,7 +50,7 @@ int main(int argc, char **argv) { BaseToolchain toolchain = custom_toolchain_arg.ConstructToolchain(); PersistentStorage storage; - setup_buildcc_cb(storage, reg, custom_toolchain_arg); + setup_buildcc_cb(storage, reg, custom_toolchain_arg, toolchain); const StaticTarget_generic &buildcc_lib = storage.ConstRef("libbuildcc"); @@ -101,9 +102,8 @@ static void global_flags_cb(TargetInfo &global_info, } static void setup_buildcc_cb(PersistentStorage &storage, Register ®, - const Args::ToolchainArg &custom_toolchain_arg) { - - BaseToolchain toolchain = custom_toolchain_arg.ConstructToolchain(); + const Args::ToolchainArg &custom_toolchain_arg, + const BaseToolchain &toolchain) { // Flatc Executable ExecutableTarget_generic &flatc_exe = storage.Add( From 808f89c39f92cf2c885ff2eb1ce52a936b0293cb Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 2 Dec 2021 02:58:21 -0800 Subject: [PATCH 58/62] Update main.buildcc.cpp --- bootstrap/main.buildcc.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bootstrap/main.buildcc.cpp b/bootstrap/main.buildcc.cpp index 744678c1..f5569183 100644 --- a/bootstrap/main.buildcc.cpp +++ b/bootstrap/main.buildcc.cpp @@ -119,23 +119,27 @@ static void setup_buildcc_cb(PersistentStorage &storage, Register ®, reg.Dep(schema_gen, flatc_exe); // Flatbuffers HO lib - TargetInfo flatbuffers_ho_lib("third_party/flatbuffers"); + TargetInfo &flatbuffers_ho_lib = + storage.Add("flatbuffers_ho", "third_party/flatbuffers"); reg.Callback(flatbuffers_ho_cb, flatbuffers_ho_lib); // CLI11 HO lib - TargetInfo cli11_ho_lib("third_party/CLI11"); + TargetInfo &cli11_ho_lib = + storage.Add("cli11_ho", "third_party/CLI11"); reg.Callback(cli11_ho_cb, cli11_ho_lib); // fmt HO lib - TargetInfo fmt_ho_lib("third_party/fmt"); + TargetInfo &fmt_ho_lib = storage.Add("fmt_ho", "third_party/fmt"); reg.Callback(fmt_ho_cb, fmt_ho_lib); // spdlog HO lib - TargetInfo spdlog_ho_lib("third_party/spdlog"); + TargetInfo &spdlog_ho_lib = + storage.Add("spdlog_ho", "third_party/spdlog"); reg.Callback(spdlog_ho_cb, spdlog_ho_lib); // taskflow HO lib - TargetInfo taskflow_ho_lib("third_party/taskflow"); + TargetInfo &taskflow_ho_lib = + storage.Add("taskflow_ho", "third_party/taskflow"); reg.Callback(taskflow_ho_cb, taskflow_ho_lib); // Tiny-process-library lib From 53137dba631910e1a6879635bb1c8c48bec290da Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 2 Dec 2021 03:01:14 -0800 Subject: [PATCH 59/62] Update CMakePresets.json --- CMakePresets.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakePresets.json b/CMakePresets.json index b645b1a2..45c4fa20 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -20,6 +20,7 @@ "BUILDCC_FLATBUFFERS_FLATC": true, "BUILDCC_BUILD_AS_SINGLE_LIB": true, "BUILDCC_BUILD_AS_INTERFACE": true, + "BUILDCC_BOOTSTRAP_THROUGH_CMAKE": true, "BUILDCC_PRECOMPILE_HEADERS": true, "BUILDCC_EXAMPLES": true, "BUILDCC_TESTING": true, @@ -43,6 +44,7 @@ "BUILDCC_FLATBUFFERS_FLATC": true, "BUILDCC_BUILD_AS_SINGLE_LIB": true, "BUILDCC_BUILD_AS_INTERFACE": false, + "BUILDCC_BOOTSTRAP_THROUGH_CMAKE": true, "BUILDCC_PRECOMPILE_HEADERS": true, "BUILDCC_EXAMPLES": true, "BUILDCC_TESTING": true, @@ -66,6 +68,7 @@ "BUILDCC_FLATBUFFERS_FLATC": true, "BUILDCC_BUILD_AS_SINGLE_LIB": false, "BUILDCC_BUILD_AS_INTERFACE": true, + "BUILDCC_BOOTSTRAP_THROUGH_CMAKE": false, "BUILDCC_PRECOMPILE_HEADERS": true, "BUILDCC_EXAMPLES": false, "BUILDCC_TESTING": true, @@ -89,6 +92,7 @@ "BUILDCC_FLATBUFFERS_FLATC": true, "BUILDCC_BUILD_AS_SINGLE_LIB": true, "BUILDCC_BUILD_AS_INTERFACE": true, + "BUILDCC_BOOTSTRAP_THROUGH_CMAKE": true, "BUILDCC_PRECOMPILE_HEADERS": true, "BUILDCC_EXAMPLES": true, "BUILDCC_TESTING": false, @@ -109,6 +113,7 @@ "BUILDCC_FLATBUFFERS_FLATC": true, "BUILDCC_BUILD_AS_SINGLE_LIB": true, "BUILDCC_BUILD_AS_INTERFACE": true, + "BUILDCC_BOOTSTRAP_THROUGH_CMAKE": true, "BUILDCC_PRECOMPILE_HEADERS": true, "BUILDCC_EXAMPLES": true, "BUILDCC_TESTING": false, @@ -129,6 +134,7 @@ "BUILDCC_FLATBUFFERS_FLATC": true, "BUILDCC_BUILD_AS_SINGLE_LIB": true, "BUILDCC_BUILD_AS_INTERFACE": false, + "BUILDCC_BOOTSTRAP_THROUGH_CMAKE": false, "BUILDCC_PRECOMPILE_HEADERS": false, "BUILDCC_EXAMPLES": false, "BUILDCC_TESTING": false, From cb6ef78849adecd99be0ea9c4e5b3d23a17515a5 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 2 Dec 2021 03:04:03 -0800 Subject: [PATCH 60/62] Update linux_gcc_cmake_build.yml --- .github/workflows/linux_gcc_cmake_build.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linux_gcc_cmake_build.yml b/.github/workflows/linux_gcc_cmake_build.yml index 8a76b6dd..4770d4b7 100644 --- a/.github/workflows/linux_gcc_cmake_build.yml +++ b/.github/workflows/linux_gcc_cmake_build.yml @@ -63,6 +63,11 @@ jobs: run: | ctest --preset=${{env.BUILD_DEV_ALL_PRESET}} --parallel 2 + - name: Bootstrap through CMake + working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_ALL}} + run: | + cmake --build . --target run_buildcc_lib_bootstrap_linux_gcc + - name: Install working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_ALL}} run: | @@ -110,7 +115,7 @@ jobs: working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_ALL}} run: | cmake --build . --target run_hybrid_depchaining_example_linux - + - name: Hybrid Target Info Example working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_ALL}} run: | @@ -174,6 +179,11 @@ jobs: cat ../codecov.yml | curl --data-binary @- https://codecov.io/validate bash <(curl -s https://codecov.io/bash) -f coverage_truncated.info || echo "Codecov did not collect coverage reports" + - name: Bootstrap through CMake + working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}} + run: | + cmake --build . --target run_buildcc_lib_bootstrap_linux_gcc + - name: Install working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}} run: | From 140cbdfb44ec30e24356ad9f39b2f97bfeb1a143 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 2 Dec 2021 03:06:48 -0800 Subject: [PATCH 61/62] Update win_cmake_build.yml --- .github/workflows/win_cmake_build.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/win_cmake_build.yml b/.github/workflows/win_cmake_build.yml index 9760177f..63ba0285 100644 --- a/.github/workflows/win_cmake_build.yml +++ b/.github/workflows/win_cmake_build.yml @@ -50,6 +50,11 @@ jobs: cmake --build --list-presets cmake --build --preset=${{env.BUILD_MSVC_PRESET}} --config Release --parallel 2 + - name: Bootstrap through CMake + working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}} + run: | + cmake --build . --config Release --target run_buildcc_lib_bootstrap_win_msvc --parallel 2 + - name: Install working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}} run: | From d0d7be4279affa0dc8ef4f762cef77893beb3332 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 2 Dec 2021 03:08:47 -0800 Subject: [PATCH 62/62] Update win_cmake_build.yml --- .github/workflows/win_cmake_build.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/win_cmake_build.yml b/.github/workflows/win_cmake_build.yml index 63ba0285..91e62ad8 100644 --- a/.github/workflows/win_cmake_build.yml +++ b/.github/workflows/win_cmake_build.yml @@ -73,42 +73,42 @@ jobs: - name: Hybrid Simple Example working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}} run: | - cmake --build . --target run_hybrid_simple_example_win + cmake --build . --config Release --parallel 2 --target run_hybrid_simple_example_win - name: Hybrid Foolib Example working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}} run: | - cmake --build . --target run_hybrid_foolib_example_win + cmake --build . --config Release --parallel 2 --target run_hybrid_foolib_example_win - name: Hybrid External Lib Example working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}} run: | - cmake --build . --target run_hybrid_externallib_example_win + cmake --build . --config Release --parallel 2 --target run_hybrid_externallib_example_win - name: Hybrid Custom Target Example working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}} run: | - cmake --build . --target run_hybrid_customtarget_example_win + cmake --build . --config Release --parallel 2 --target run_hybrid_customtarget_example_win - name: Hybrid Generic Target Example working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}} run: | - cmake --build . --target run_hybrid_generic_example + cmake --build . --config Release --parallel 2 --target run_hybrid_generic_example - name: Hybrid PCH Target Example working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}} run: | - cmake --build . --target run_hybrid_pch_example_win + cmake --build . --config Release --parallel 2 --target run_hybrid_pch_example_win - name: Hybrid Dep Chaining Target Example working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}} run: | - cmake --build . --target run_hybrid_depchaining_example_win + cmake --build . --config Release --parallel 2 --target run_hybrid_depchaining_example_win - name: Hybrid Target Info Example working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}} run: | - cmake --build . --target run_hybrid_targetinfo_example_win + cmake --build . --config Release --parallel 2 --target run_hybrid_targetinfo_example_win build_clang: name: Clang single and interface Lib