Skip to content

Buildexe script mode #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9a8c8fe
Update generator.h
coder137 Dec 10, 2021
0acb760
Update win_cmake_build.yml
coder137 Dec 10, 2021
6fca233
Added BuildBuildCC to build_buildcc.h
coder137 Dec 10, 2021
0e368f3
Update main.buildcc.cpp
coder137 Dec 10, 2021
711ba8e
Update build_buildcc.cpp
coder137 Dec 10, 2021
fc3266b
Replaced magic strings
coder137 Dec 10, 2021
58aa644
Update toolchain_verify.h
coder137 Dec 10, 2021
df7ac94
Update util.h
coder137 Dec 10, 2021
5f0e596
Update toolchain_verify.cpp
coder137 Dec 10, 2021
7d3b1f7
Added host_toolchain_verification
coder137 Dec 10, 2021
c2bf300
Update buildexe.cpp
coder137 Dec 10, 2021
dc75dac
Update build_buildcc.h
coder137 Dec 10, 2021
fddffc4
Create sm_simple.toml
coder137 Dec 10, 2021
826ed1f
Update CMakeLists.txt
coder137 Dec 10, 2021
dc240e3
Updated target for ordered lib deps
coder137 Dec 11, 2021
cb6aed7
Updated buildexe for Buildcc compilation from BUILDCC_HOME environment
coder137 Dec 11, 2021
366e0f6
Added std::vector for ORDERED storage of external_lib_deps
coder137 Dec 11, 2021
6d54106
Updated buildexe with ArgScriptInfo for configs
coder137 Dec 11, 2021
fdfddf6
Updated sm_hybrid_simple example
coder137 Dec 11, 2021
2d5fb47
Update main.buildcc.cpp
coder137 Dec 11, 2021
e7b2aa1
Update buildexe.cpp
coder137 Dec 11, 2021
e9be31e
Update linux_gcc_cmake_build.yml
coder137 Dec 11, 2021
680d232
Updated build files for buildexe
coder137 Dec 11, 2021
ef6d52a
Update win_cmake_build.yml
coder137 Dec 11, 2021
0515a57
Updated github ci/cd with environment variable BUILDCC_HOME
coder137 Dec 11, 2021
aad9972
Upload BuildExe artifacts
coder137 Dec 11, 2021
60375cd
Update win_cmake_build.yml
coder137 Dec 11, 2021
fc24c7a
Updated toolchain_verify.cpp
coder137 Dec 11, 2021
228b68c
Updated toolchain verify for edge error cases
coder137 Dec 12, 2021
24d993f
Updated test_toolchain_verify unit test
coder137 Dec 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/linux_gcc_cmake_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
- name: BuildExe IM example tiny-process-library
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_ALL}}
run: |
cmake --build . --target run_buildexe_im_tpl_linux_gcc
cmake --build . --target run_buildexe_im_tpl_gcc_linux

- name: Install
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_ALL}}
Expand Down Expand Up @@ -192,7 +192,15 @@ jobs:
- name: BuildExe IM example tiny-process-library
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}}
run: |
cmake --build . --target run_buildexe_im_tpl_linux_gcc
cmake --build . --target run_buildexe_im_tpl_gcc_linux

# - name: TODO, BuildExe SM simple hyrid example

- name: Upload BuildExe
uses: actions/upload-artifact@v2
with:
name: "BuildExe_Linux"
path: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}}/buildexe/buildexe

- name: Install
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}}
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/win_cmake_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ jobs:
- name: BuildExe IM example tiny-process-library
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}}
run: |
cmake --build . --target run_buildexe_im_tpl_win_msvc
cmake --build . --config Release --target run_buildexe_im_tpl_msvc_win

# - name: TODO, BuildExe SM simple hyrid example

- name: Upload BuildExe
uses: actions/upload-artifact@v2
with:
name: "BuildExe_Win"
path: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}}/buildexe/Release/buildexe.exe

- name: Install
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}}
Expand Down
54 changes: 54 additions & 0 deletions bootstrap/include/bootstrap/build_buildcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

#include "buildcc.h"

#include "build_cli11.h"
#include "build_flatbuffers.h"
#include "build_fmtlib.h"
#include "build_spdlog.h"
#include "build_taskflow.h"
#include "build_tpl.h"

namespace buildcc {

void schema_gen_cb(BaseGenerator &generator, const BaseTarget &flatc_exe);
Expand All @@ -28,6 +35,53 @@ void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen,
const TargetInfo &spdlog_ho, const TargetInfo &cli11_ho,
const TargetInfo &taskflow_ho, const BaseTarget &tpl);

/**
* @brief
*
*/
class BuildBuildCC {
public:
// TargetInfo / Header Only
static constexpr const char *const kFlatbuffersHoName = "flatbuffers_ho";
static constexpr const char *const kCli11HoName = "cli11_ho";
static constexpr const char *const kFmtHoName = "fmtlib_ho";
static constexpr const char *const kSpdlogHoName = "spdlog_ho";
static constexpr const char *const kTaskflowHoName = "taskflow_ho";

// Executable
static constexpr const char *const kFlatcExeName = "flatc";

// Generator
static constexpr const char *const kSchemaGenName = "schema_gen";

// Libraries
static constexpr const char *const kTplLibName = "libtpl";
static constexpr const char *const kBuildccLibName = "libbuildcc";

public:
BuildBuildCC(Register &reg, const BaseToolchain &toolchain,
const TargetEnv &env)
: reg_(reg), toolchain_(toolchain), env_(env) {}
BuildBuildCC(const BuildBuildCC &) = delete;

void Setup(const ArgToolchainState &state);

// Getters
StaticTarget_generic &GetTpl() {
return storage_.Ref<StaticTarget_generic>(kTplLibName);
}
StaticTarget_generic &GetBuildcc() {
return storage_.Ref<StaticTarget_generic>(kBuildccLibName);
}

private:
Register &reg_;
const BaseToolchain &toolchain_;
TargetEnv env_;

PersistentStorage storage_;
};

} // namespace buildcc

#endif
101 changes: 6 additions & 95 deletions bootstrap/main.buildcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
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 &reg,
const ArgToolchain &custom_toolchain_arg,
const BaseToolchain &toolchain);

static void hybrid_simple_example_cb(BaseTarget &target,
const BaseTarget &libbuildcc);
Expand All @@ -50,11 +44,12 @@ int main(int argc, char **argv) {
BaseToolchain toolchain = custom_toolchain_arg.ConstructToolchain();

PersistentStorage storage;
setup_buildcc_cb(storage, reg, custom_toolchain_arg, toolchain);

const StaticTarget_generic &buildcc_lib =
storage.ConstRef<StaticTarget_generic>("libbuildcc");
BuildBuildCC buildcc(
reg, toolchain,
TargetEnv(env::get_project_root_dir(), env::get_project_build_dir()));
buildcc.Setup(custom_toolchain_arg.state);

const auto &buildcc_lib = buildcc.GetBuildcc();
ExecutableTarget_generic buildcc_hybrid_simple_example(
"buildcc_hybrid_simple_example", toolchain, "example/hybrid/simple");
reg.Build(custom_toolchain_arg.state, hybrid_simple_example_cb,
Expand All @@ -78,92 +73,9 @@ 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");
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");
global_info.AddCppCompileFlag("/WX");
default:
break;
}
}

static void setup_buildcc_cb(PersistentStorage &storage, Register &reg,
const ArgToolchain &custom_toolchain_arg,
const BaseToolchain &toolchain) {

// Flatc Executable
ExecutableTarget_generic &flatc_exe = storage.Add<ExecutableTarget_generic>(
"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<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 =
storage.Add<TargetInfo>("flatbuffers_ho", "third_party/flatbuffers");
reg.Callback(flatbuffers_ho_cb, flatbuffers_ho_lib);

// CLI11 HO lib
TargetInfo &cli11_ho_lib =
storage.Add<TargetInfo>("cli11_ho", "third_party/CLI11");
reg.Callback(cli11_ho_cb, cli11_ho_lib);

// fmt HO lib
TargetInfo &fmt_ho_lib = storage.Add<TargetInfo>("fmt_ho", "third_party/fmt");
reg.Callback(fmt_ho_cb, fmt_ho_lib);

// spdlog HO lib
TargetInfo &spdlog_ho_lib =
storage.Add<TargetInfo>("spdlog_ho", "third_party/spdlog");
reg.Callback(spdlog_ho_cb, spdlog_ho_lib);

// taskflow HO lib
TargetInfo &taskflow_ho_lib =
storage.Add<TargetInfo>("taskflow_ho", "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<StaticTarget_generic>(
"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<StaticTarget_generic>(
"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.AddLibDep(libbuildcc);
target.Insert(libbuildcc, {
SyncOption::PreprocessorFlags,
SyncOption::CppCompileFlags,
Expand All @@ -174,6 +86,5 @@ static void hybrid_simple_example_cb(BaseTarget &target,
SyncOption::ExternalLibDeps,
});
target.AddSource("build.cpp");
target.AddLibDep(libbuildcc);
target.Build();
}
98 changes: 98 additions & 0 deletions bootstrap/src/build_buildcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,102 @@ void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen,
target.Build();
}

// TODO, Shift this inside BuildBuildcc class if required
// TODO, Add this to options
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");
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");
global_info.AddCppCompileFlag("/WX");
default:
break;
}
}

void BuildBuildCC::Setup(const ArgToolchainState &state) {
auto &flatc_exe = storage_.Add<ExecutableTarget_generic>(
kFlatcExeName, kFlatcExeName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "flatbuffers",
env_.GetTargetBuildDir()));

reg_.CallbackIf(state, global_flags_cb, flatc_exe, toolchain_);
reg_.Build(state, build_flatc_exe_cb, flatc_exe);

// Schema
auto &schema_gen = storage_.Add<BaseGenerator>(
kSchemaGenName, kSchemaGenName,
TargetEnv(env_.GetTargetRootDir() / "buildcc" / "schema",
env_.GetTargetBuildDir() / toolchain_.GetName()));
reg_.Build(schema_gen_cb, schema_gen, flatc_exe);
reg_.Dep(schema_gen, flatc_exe);

// Flatbuffers HO lib
auto &flatbuffers_ho_lib = storage_.Add<TargetInfo>(
kFlatbuffersHoName,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "flatbuffers",
env_.GetTargetBuildDir()));
reg_.CallbackIf(state, flatbuffers_ho_cb, flatbuffers_ho_lib);

// CLI11 HO lib
auto &cli11_ho_lib = storage_.Add<TargetInfo>(
kCli11HoName, TargetEnv(env_.GetTargetRootDir() / "third_party" / "CLI11",
env_.GetTargetBuildDir()));
reg_.CallbackIf(state, cli11_ho_cb, cli11_ho_lib);

// fmt HO lib
auto &fmt_ho_lib = storage_.Add<TargetInfo>(
kFmtHoName, TargetEnv(env_.GetTargetRootDir() / "third_party" / "fmt",
env_.GetTargetBuildDir()));
reg_.CallbackIf(state, fmt_ho_cb, fmt_ho_lib);

// spdlog HO lib
auto &spdlog_ho_lib = storage_.Add<TargetInfo>(
kSpdlogHoName,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "spdlog",
env_.GetTargetBuildDir()));
reg_.CallbackIf(state, spdlog_ho_cb, spdlog_ho_lib);

// taskflow HO lib
auto &taskflow_ho_lib = storage_.Add<TargetInfo>(
kTaskflowHoName,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "taskflow",
env_.GetTargetBuildDir()));
reg_.CallbackIf(state, taskflow_ho_cb, taskflow_ho_lib);

// Tiny-process-library lib
// TODO, Make this a generic selection between StaticTarget and
// DynamicTarget
auto &tpl_lib = storage_.Add<StaticTarget_generic>(
kTplLibName, kTplLibName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "third_party" /
"tiny-process-library",
env_.GetTargetBuildDir()));
reg_.CallbackIf(state, global_flags_cb, tpl_lib, toolchain_);
reg_.Build(state, tpl_cb, tpl_lib);

// TODO, Make this a generic selection between StaticTarget and
// DynamicTarget
auto &buildcc_lib = storage_.Add<StaticTarget_generic>(
kBuildccLibName, kBuildccLibName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "buildcc", env_.GetTargetBuildDir()));
reg_.CallbackIf(state, global_flags_cb, buildcc_lib, toolchain_);
reg_.Build(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);
}

} // namespace buildcc
33 changes: 33 additions & 0 deletions buildcc/lib/env/include/env/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#ifndef ENV_UTIL_H_
#define ENV_UTIL_H_

#include <algorithm>
#include <filesystem>
#include <fstream>
#include <sstream>
Expand Down Expand Up @@ -120,6 +121,38 @@ inline std::vector<std::string> split(const std::string &s, char delim) {
return result;
}

// https://stackoverflow.com/questions/44973435/stdptr-fun-replacement-for-c17/44973498#44973498
inline std::string ltrim(const std::string &s) {
std::string tr{s};
// Checks from left (beginning) and finds the `end point` where no `isspace`
// char is detected
auto l_tr_end = std::find_if(tr.begin(), tr.end(),
[](char c) { return !std::isspace(c); });
tr.erase(tr.begin(), l_tr_end);
return tr;
}

inline std::string rtrim(const std::string &s) {
std::string tr{s};
// Checks from right (ending) and finds the `start point` where no `isspace`
// char is detected
// Gets the base iterator (which is forward in nature)
auto r_tr_begin = std::find_if(tr.rbegin(), tr.rend(), [](char c) {
return !std::isspace(c);
}).base();
tr.erase(r_tr_begin, tr.end());
return tr;
}

/**
* @brief Trims both left and right part of the string
*/
inline std::string trim(const std::string &s) {
std::string tr = ltrim(s);
tr = rtrim(tr);
return tr;
}

} // namespace buildcc::env

#endif
Loading