Skip to content

Commit d57ae99

Browse files
authored
Buildexe script mode (#171)
1 parent 6fec1da commit d57ae99

File tree

21 files changed

+603
-154
lines changed

21 files changed

+603
-154
lines changed

.github/workflows/linux_gcc_cmake_build.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
- name: BuildExe IM example tiny-process-library
7272
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_ALL}}
7373
run: |
74-
cmake --build . --target run_buildexe_im_tpl_linux_gcc
74+
cmake --build . --target run_buildexe_im_tpl_gcc_linux
7575
7676
- name: Install
7777
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_ALL}}
@@ -192,7 +192,15 @@ jobs:
192192
- name: BuildExe IM example tiny-process-library
193193
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}}
194194
run: |
195-
cmake --build . --target run_buildexe_im_tpl_linux_gcc
195+
cmake --build . --target run_buildexe_im_tpl_gcc_linux
196+
197+
# - name: TODO, BuildExe SM simple hyrid example
198+
199+
- name: Upload BuildExe
200+
uses: actions/upload-artifact@v2
201+
with:
202+
name: "BuildExe_Linux"
203+
path: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}}/buildexe/buildexe
196204

197205
- name: Install
198206
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}}

.github/workflows/win_cmake_build.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ jobs:
5858
- name: BuildExe IM example tiny-process-library
5959
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}}
6060
run: |
61-
cmake --build . --target run_buildexe_im_tpl_win_msvc
61+
cmake --build . --config Release --target run_buildexe_im_tpl_msvc_win
62+
63+
# - name: TODO, BuildExe SM simple hyrid example
64+
65+
- name: Upload BuildExe
66+
uses: actions/upload-artifact@v2
67+
with:
68+
name: "BuildExe_Win"
69+
path: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}}/buildexe/Release/buildexe.exe
6270

6371
- name: Install
6472
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}}

bootstrap/include/bootstrap/build_buildcc.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919

2020
#include "buildcc.h"
2121

22+
#include "build_cli11.h"
23+
#include "build_flatbuffers.h"
24+
#include "build_fmtlib.h"
25+
#include "build_spdlog.h"
26+
#include "build_taskflow.h"
27+
#include "build_tpl.h"
28+
2229
namespace buildcc {
2330

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

38+
/**
39+
* @brief
40+
*
41+
*/
42+
class BuildBuildCC {
43+
public:
44+
// TargetInfo / Header Only
45+
static constexpr const char *const kFlatbuffersHoName = "flatbuffers_ho";
46+
static constexpr const char *const kCli11HoName = "cli11_ho";
47+
static constexpr const char *const kFmtHoName = "fmtlib_ho";
48+
static constexpr const char *const kSpdlogHoName = "spdlog_ho";
49+
static constexpr const char *const kTaskflowHoName = "taskflow_ho";
50+
51+
// Executable
52+
static constexpr const char *const kFlatcExeName = "flatc";
53+
54+
// Generator
55+
static constexpr const char *const kSchemaGenName = "schema_gen";
56+
57+
// Libraries
58+
static constexpr const char *const kTplLibName = "libtpl";
59+
static constexpr const char *const kBuildccLibName = "libbuildcc";
60+
61+
public:
62+
BuildBuildCC(Register &reg, const BaseToolchain &toolchain,
63+
const TargetEnv &env)
64+
: reg_(reg), toolchain_(toolchain), env_(env) {}
65+
BuildBuildCC(const BuildBuildCC &) = delete;
66+
67+
void Setup(const ArgToolchainState &state);
68+
69+
// Getters
70+
StaticTarget_generic &GetTpl() {
71+
return storage_.Ref<StaticTarget_generic>(kTplLibName);
72+
}
73+
StaticTarget_generic &GetBuildcc() {
74+
return storage_.Ref<StaticTarget_generic>(kBuildccLibName);
75+
}
76+
77+
private:
78+
Register &reg_;
79+
const BaseToolchain &toolchain_;
80+
TargetEnv env_;
81+
82+
PersistentStorage storage_;
83+
};
84+
3185
} // namespace buildcc
3286

3387
#endif

bootstrap/main.buildcc.cpp

Lines changed: 6 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@
2828
using namespace buildcc;
2929

3030
static void clean_cb();
31-
static void global_flags_cb(TargetInfo &global_info,
32-
const BaseToolchain &toolchain);
33-
34-
static void setup_buildcc_cb(PersistentStorage &storage, Register &reg,
35-
const ArgToolchain &custom_toolchain_arg,
36-
const BaseToolchain &toolchain);
3731

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

5246
PersistentStorage storage;
53-
setup_buildcc_cb(storage, reg, custom_toolchain_arg, toolchain);
54-
55-
const StaticTarget_generic &buildcc_lib =
56-
storage.ConstRef<StaticTarget_generic>("libbuildcc");
47+
BuildBuildCC buildcc(
48+
reg, toolchain,
49+
TargetEnv(env::get_project_root_dir(), env::get_project_build_dir()));
50+
buildcc.Setup(custom_toolchain_arg.state);
5751

52+
const auto &buildcc_lib = buildcc.GetBuildcc();
5853
ExecutableTarget_generic buildcc_hybrid_simple_example(
5954
"buildcc_hybrid_simple_example", toolchain, "example/hybrid/simple");
6055
reg.Build(custom_toolchain_arg.state, hybrid_simple_example_cb,
@@ -78,92 +73,9 @@ int main(int argc, char **argv) {
7873

7974
static void clean_cb() {}
8075

81-
static void global_flags_cb(TargetInfo &global_info,
82-
const BaseToolchain &toolchain) {
83-
// TODO, Clang
84-
switch (toolchain.GetId()) {
85-
case ToolchainId::Gcc:
86-
case ToolchainId::MinGW:
87-
global_info.AddCppCompileFlag("-std=c++17");
88-
global_info.AddCppCompileFlag("-Os");
89-
global_info.AddCppCompileFlag("-Wall");
90-
global_info.AddCppCompileFlag("-Wextra");
91-
global_info.AddCppCompileFlag("-Werror");
92-
break;
93-
case ToolchainId::Msvc:
94-
global_info.AddPreprocessorFlag("/D_CRT_SECURE_NO_WARNINGS");
95-
global_info.AddCppCompileFlag("/std:c++17");
96-
global_info.AddCppCompileFlag("/Ot");
97-
global_info.AddCppCompileFlag("/W4");
98-
global_info.AddCppCompileFlag("/WX");
99-
default:
100-
break;
101-
}
102-
}
103-
104-
static void setup_buildcc_cb(PersistentStorage &storage, Register &reg,
105-
const ArgToolchain &custom_toolchain_arg,
106-
const BaseToolchain &toolchain) {
107-
108-
// Flatc Executable
109-
ExecutableTarget_generic &flatc_exe = storage.Add<ExecutableTarget_generic>(
110-
"flatc", "flatc", toolchain, "third_party/flatbuffers");
111-
reg.CallbackIf(custom_toolchain_arg.state, global_flags_cb, flatc_exe,
112-
toolchain);
113-
reg.Build(custom_toolchain_arg.state, build_flatc_exe_cb, flatc_exe);
114-
115-
// Schema
116-
BaseGenerator &schema_gen =
117-
storage.Add<BaseGenerator>("schema_gen", "schema_gen", "buildcc/schema");
118-
reg.Build(schema_gen_cb, schema_gen, flatc_exe);
119-
reg.Dep(schema_gen, flatc_exe);
120-
121-
// Flatbuffers HO lib
122-
TargetInfo &flatbuffers_ho_lib =
123-
storage.Add<TargetInfo>("flatbuffers_ho", "third_party/flatbuffers");
124-
reg.Callback(flatbuffers_ho_cb, flatbuffers_ho_lib);
125-
126-
// CLI11 HO lib
127-
TargetInfo &cli11_ho_lib =
128-
storage.Add<TargetInfo>("cli11_ho", "third_party/CLI11");
129-
reg.Callback(cli11_ho_cb, cli11_ho_lib);
130-
131-
// fmt HO lib
132-
TargetInfo &fmt_ho_lib = storage.Add<TargetInfo>("fmt_ho", "third_party/fmt");
133-
reg.Callback(fmt_ho_cb, fmt_ho_lib);
134-
135-
// spdlog HO lib
136-
TargetInfo &spdlog_ho_lib =
137-
storage.Add<TargetInfo>("spdlog_ho", "third_party/spdlog");
138-
reg.Callback(spdlog_ho_cb, spdlog_ho_lib);
139-
140-
// taskflow HO lib
141-
TargetInfo &taskflow_ho_lib =
142-
storage.Add<TargetInfo>("taskflow_ho", "third_party/taskflow");
143-
reg.Callback(taskflow_ho_cb, taskflow_ho_lib);
144-
145-
// Tiny-process-library lib
146-
// TODO, Make this a generic selection between StaticTarget and DynamicTarget
147-
StaticTarget_generic &tpl_lib = storage.Add<StaticTarget_generic>(
148-
"libtpl", "libtpl", toolchain, "third_party/tiny-process-library");
149-
reg.CallbackIf(custom_toolchain_arg.state, global_flags_cb, tpl_lib,
150-
toolchain);
151-
reg.Build(custom_toolchain_arg.state, tpl_cb, tpl_lib);
152-
153-
// TODO, Make this a generic selection between StaticTarget and DynamicTarget
154-
StaticTarget_generic &buildcc_lib = storage.Add<StaticTarget_generic>(
155-
"libbuildcc", "libbuildcc", toolchain, "buildcc");
156-
reg.CallbackIf(custom_toolchain_arg.state, global_flags_cb, buildcc_lib,
157-
toolchain);
158-
reg.Build(custom_toolchain_arg.state, buildcc_cb, buildcc_lib, schema_gen,
159-
flatbuffers_ho_lib, fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib,
160-
taskflow_ho_lib, tpl_lib);
161-
reg.Dep(buildcc_lib, schema_gen);
162-
reg.Dep(buildcc_lib, tpl_lib);
163-
}
164-
16576
static void hybrid_simple_example_cb(BaseTarget &target,
16677
const BaseTarget &libbuildcc) {
78+
target.AddLibDep(libbuildcc);
16779
target.Insert(libbuildcc, {
16880
SyncOption::PreprocessorFlags,
16981
SyncOption::CppCompileFlags,
@@ -174,6 +86,5 @@ static void hybrid_simple_example_cb(BaseTarget &target,
17486
SyncOption::ExternalLibDeps,
17587
});
17688
target.AddSource("build.cpp");
177-
target.AddLibDep(libbuildcc);
17889
target.Build();
17990
}

bootstrap/src/build_buildcc.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,102 @@ void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen,
154154
target.Build();
155155
}
156156

157+
// TODO, Shift this inside BuildBuildcc class if required
158+
// TODO, Add this to options
159+
static void global_flags_cb(TargetInfo &global_info,
160+
const BaseToolchain &toolchain) {
161+
// TODO, Clang
162+
switch (toolchain.GetId()) {
163+
case ToolchainId::Gcc:
164+
case ToolchainId::MinGW:
165+
global_info.AddCppCompileFlag("-std=c++17");
166+
global_info.AddCppCompileFlag("-Os");
167+
global_info.AddCppCompileFlag("-Wall");
168+
global_info.AddCppCompileFlag("-Wextra");
169+
global_info.AddCppCompileFlag("-Werror");
170+
break;
171+
case ToolchainId::Msvc:
172+
global_info.AddPreprocessorFlag("/D_CRT_SECURE_NO_WARNINGS");
173+
global_info.AddCppCompileFlag("/std:c++17");
174+
global_info.AddCppCompileFlag("/Ot");
175+
global_info.AddCppCompileFlag("/W4");
176+
global_info.AddCppCompileFlag("/WX");
177+
default:
178+
break;
179+
}
180+
}
181+
182+
void BuildBuildCC::Setup(const ArgToolchainState &state) {
183+
auto &flatc_exe = storage_.Add<ExecutableTarget_generic>(
184+
kFlatcExeName, kFlatcExeName, toolchain_,
185+
TargetEnv(env_.GetTargetRootDir() / "third_party" / "flatbuffers",
186+
env_.GetTargetBuildDir()));
187+
188+
reg_.CallbackIf(state, global_flags_cb, flatc_exe, toolchain_);
189+
reg_.Build(state, build_flatc_exe_cb, flatc_exe);
190+
191+
// Schema
192+
auto &schema_gen = storage_.Add<BaseGenerator>(
193+
kSchemaGenName, kSchemaGenName,
194+
TargetEnv(env_.GetTargetRootDir() / "buildcc" / "schema",
195+
env_.GetTargetBuildDir() / toolchain_.GetName()));
196+
reg_.Build(schema_gen_cb, schema_gen, flatc_exe);
197+
reg_.Dep(schema_gen, flatc_exe);
198+
199+
// Flatbuffers HO lib
200+
auto &flatbuffers_ho_lib = storage_.Add<TargetInfo>(
201+
kFlatbuffersHoName,
202+
TargetEnv(env_.GetTargetRootDir() / "third_party" / "flatbuffers",
203+
env_.GetTargetBuildDir()));
204+
reg_.CallbackIf(state, flatbuffers_ho_cb, flatbuffers_ho_lib);
205+
206+
// CLI11 HO lib
207+
auto &cli11_ho_lib = storage_.Add<TargetInfo>(
208+
kCli11HoName, TargetEnv(env_.GetTargetRootDir() / "third_party" / "CLI11",
209+
env_.GetTargetBuildDir()));
210+
reg_.CallbackIf(state, cli11_ho_cb, cli11_ho_lib);
211+
212+
// fmt HO lib
213+
auto &fmt_ho_lib = storage_.Add<TargetInfo>(
214+
kFmtHoName, TargetEnv(env_.GetTargetRootDir() / "third_party" / "fmt",
215+
env_.GetTargetBuildDir()));
216+
reg_.CallbackIf(state, fmt_ho_cb, fmt_ho_lib);
217+
218+
// spdlog HO lib
219+
auto &spdlog_ho_lib = storage_.Add<TargetInfo>(
220+
kSpdlogHoName,
221+
TargetEnv(env_.GetTargetRootDir() / "third_party" / "spdlog",
222+
env_.GetTargetBuildDir()));
223+
reg_.CallbackIf(state, spdlog_ho_cb, spdlog_ho_lib);
224+
225+
// taskflow HO lib
226+
auto &taskflow_ho_lib = storage_.Add<TargetInfo>(
227+
kTaskflowHoName,
228+
TargetEnv(env_.GetTargetRootDir() / "third_party" / "taskflow",
229+
env_.GetTargetBuildDir()));
230+
reg_.CallbackIf(state, taskflow_ho_cb, taskflow_ho_lib);
231+
232+
// Tiny-process-library lib
233+
// TODO, Make this a generic selection between StaticTarget and
234+
// DynamicTarget
235+
auto &tpl_lib = storage_.Add<StaticTarget_generic>(
236+
kTplLibName, kTplLibName, toolchain_,
237+
TargetEnv(env_.GetTargetRootDir() / "third_party" /
238+
"tiny-process-library",
239+
env_.GetTargetBuildDir()));
240+
reg_.CallbackIf(state, global_flags_cb, tpl_lib, toolchain_);
241+
reg_.Build(state, tpl_cb, tpl_lib);
242+
243+
// TODO, Make this a generic selection between StaticTarget and
244+
// DynamicTarget
245+
auto &buildcc_lib = storage_.Add<StaticTarget_generic>(
246+
kBuildccLibName, kBuildccLibName, toolchain_,
247+
TargetEnv(env_.GetTargetRootDir() / "buildcc", env_.GetTargetBuildDir()));
248+
reg_.CallbackIf(state, global_flags_cb, buildcc_lib, toolchain_);
249+
reg_.Build(state, buildcc_cb, buildcc_lib, schema_gen, flatbuffers_ho_lib,
250+
fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib, taskflow_ho_lib, tpl_lib);
251+
reg_.Dep(buildcc_lib, schema_gen);
252+
reg_.Dep(buildcc_lib, tpl_lib);
253+
}
254+
157255
} // namespace buildcc

buildcc/lib/env/include/env/util.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#ifndef ENV_UTIL_H_
3434
#define ENV_UTIL_H_
3535

36+
#include <algorithm>
3637
#include <filesystem>
3738
#include <fstream>
3839
#include <sstream>
@@ -120,6 +121,38 @@ inline std::vector<std::string> split(const std::string &s, char delim) {
120121
return result;
121122
}
122123

124+
// https://stackoverflow.com/questions/44973435/stdptr-fun-replacement-for-c17/44973498#44973498
125+
inline std::string ltrim(const std::string &s) {
126+
std::string tr{s};
127+
// Checks from left (beginning) and finds the `end point` where no `isspace`
128+
// char is detected
129+
auto l_tr_end = std::find_if(tr.begin(), tr.end(),
130+
[](char c) { return !std::isspace(c); });
131+
tr.erase(tr.begin(), l_tr_end);
132+
return tr;
133+
}
134+
135+
inline std::string rtrim(const std::string &s) {
136+
std::string tr{s};
137+
// Checks from right (ending) and finds the `start point` where no `isspace`
138+
// char is detected
139+
// Gets the base iterator (which is forward in nature)
140+
auto r_tr_begin = std::find_if(tr.rbegin(), tr.rend(), [](char c) {
141+
return !std::isspace(c);
142+
}).base();
143+
tr.erase(r_tr_begin, tr.end());
144+
return tr;
145+
}
146+
147+
/**
148+
* @brief Trims both left and right part of the string
149+
*/
150+
inline std::string trim(const std::string &s) {
151+
std::string tr = ltrim(s);
152+
tr = rtrim(tr);
153+
return tr;
154+
}
155+
123156
} // namespace buildcc::env
124157

125158
#endif

0 commit comments

Comments
 (0)