Skip to content

Commit 6d17fe3

Browse files
authored
[BuildExe] Basic Immediate mode feature (#168)
- BuildExe executables that take a *.toml file to compile one target (executable/library) of the users choice - Current limitations: Target needs to be standalone (cannot depend on other targets)
1 parent 07037be commit 6d17fe3

File tree

24 files changed

+531
-128
lines changed

24 files changed

+531
-128
lines changed

.github/workflows/linux_gcc_cmake_build.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ jobs:
6868
run: |
6969
cmake --build . --target run_buildcc_lib_bootstrap_linux_gcc
7070
71+
- name: BuildExe IM example tiny-process-library
72+
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_ALL}}
73+
run: |
74+
cmake --build . --target run_buildexe_im_tpl_linux_gcc
75+
7176
- name: Install
7277
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_ALL}}
7378
run: |
@@ -184,6 +189,11 @@ jobs:
184189
run: |
185190
cmake --build . --target run_buildcc_lib_bootstrap_linux_gcc
186191
192+
- name: BuildExe IM example tiny-process-library
193+
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}}
194+
run: |
195+
cmake --build . --target run_buildexe_im_tpl_linux_gcc
196+
187197
- name: Install
188198
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}}
189199
run: |

.github/workflows/win_cmake_build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ jobs:
5555
run: |
5656
cmake --build . --config Release --target run_buildcc_lib_bootstrap_win_msvc --parallel 2
5757
58+
- name: BuildExe IM example tiny-process-library
59+
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}}
60+
run: |
61+
cmake --build . --target run_buildexe_im_tpl_win_msvc
62+
5863
- name: Install
5964
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}}
6065
run: |

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ project(BuildCC
1111
)
1212

1313
# User options
14-
option(BUILDCC_INSTALL "Enable Buildcc Installation" ON)
14+
option(BUILDCC_INSTALL "Enable BuildCC Installation" ON)
1515
option(BUILDCC_FLATBUFFERS_FLATC "Build Flatbuffer::Flatc Compiler" ON)
1616

1717
option(BUILDCC_BUILD_AS_SINGLE_LIB "Build all internal libs and modules as part of the buildcc library" ON)
1818
option(BUILDCC_BUILD_AS_INTERFACE "Build all internal libs and modules seperately and link" OFF)
1919

20+
option(BUILDCC_BUILDEXE "Standalone BuildCC buildsystem executable" ON)
2021
option(BUILDCC_BOOTSTRAP_THROUGH_CMAKE "Bootstrap buildcc through CMake" OFF)
2122

2223
# NOTE, Conflict with Clang-Tidy on certain compilers
23-
option(BUILDCC_PRECOMPILE_HEADERS "Enable Buildcc precompile headers" OFF)
24-
option(BUILDCC_EXAMPLES "Enable Buildcc Examples" OFF)
24+
option(BUILDCC_PRECOMPILE_HEADERS "Enable BuildCC precompile headers" OFF)
25+
option(BUILDCC_EXAMPLES "Enable BuildCC Examples" OFF)
2526

2627
# Dev options
2728
option(BUILDCC_TESTING "Enable BuildCC Testing" OFF)
@@ -115,6 +116,10 @@ if (${BUILDCC_EXAMPLES})
115116
add_subdirectory(example/hybrid/target_info)
116117
endif()
117118

119+
if (${BUILDCC_BUILDEXE})
120+
add_subdirectory(buildexe)
121+
endif()
122+
118123
if (${BUILDCC_BOOTSTRAP_THROUGH_CMAKE})
119124
add_subdirectory(bootstrap)
120125
endif()

CMakePresets.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"BUILDCC_FLATBUFFERS_FLATC": true,
2121
"BUILDCC_BUILD_AS_SINGLE_LIB": true,
2222
"BUILDCC_BUILD_AS_INTERFACE": true,
23+
"BUILDCC_BUILDEXE": true,
2324
"BUILDCC_BOOTSTRAP_THROUGH_CMAKE": true,
2425
"BUILDCC_PRECOMPILE_HEADERS": true,
2526
"BUILDCC_EXAMPLES": true,
@@ -44,6 +45,7 @@
4445
"BUILDCC_FLATBUFFERS_FLATC": true,
4546
"BUILDCC_BUILD_AS_SINGLE_LIB": true,
4647
"BUILDCC_BUILD_AS_INTERFACE": false,
48+
"BUILDCC_BUILDEXE": true,
4749
"BUILDCC_BOOTSTRAP_THROUGH_CMAKE": true,
4850
"BUILDCC_PRECOMPILE_HEADERS": true,
4951
"BUILDCC_EXAMPLES": true,
@@ -68,6 +70,7 @@
6870
"BUILDCC_FLATBUFFERS_FLATC": true,
6971
"BUILDCC_BUILD_AS_SINGLE_LIB": false,
7072
"BUILDCC_BUILD_AS_INTERFACE": true,
73+
"BUILDCC_BUILDEXE": false,
7174
"BUILDCC_BOOTSTRAP_THROUGH_CMAKE": false,
7275
"BUILDCC_PRECOMPILE_HEADERS": true,
7376
"BUILDCC_EXAMPLES": false,
@@ -92,6 +95,7 @@
9295
"BUILDCC_FLATBUFFERS_FLATC": true,
9396
"BUILDCC_BUILD_AS_SINGLE_LIB": true,
9497
"BUILDCC_BUILD_AS_INTERFACE": true,
98+
"BUILDCC_BUILDEXE": true,
9599
"BUILDCC_BOOTSTRAP_THROUGH_CMAKE": true,
96100
"BUILDCC_PRECOMPILE_HEADERS": true,
97101
"BUILDCC_EXAMPLES": true,
@@ -113,6 +117,7 @@
113117
"BUILDCC_FLATBUFFERS_FLATC": true,
114118
"BUILDCC_BUILD_AS_SINGLE_LIB": true,
115119
"BUILDCC_BUILD_AS_INTERFACE": true,
120+
"BUILDCC_BUILDEXE": true,
116121
"BUILDCC_BOOTSTRAP_THROUGH_CMAKE": true,
117122
"BUILDCC_PRECOMPILE_HEADERS": true,
118123
"BUILDCC_EXAMPLES": true,
@@ -134,6 +139,7 @@
134139
"BUILDCC_FLATBUFFERS_FLATC": true,
135140
"BUILDCC_BUILD_AS_SINGLE_LIB": true,
136141
"BUILDCC_BUILD_AS_INTERFACE": false,
142+
"BUILDCC_BUILDEXE": false,
137143
"BUILDCC_BOOTSTRAP_THROUGH_CMAKE": false,
138144
"BUILDCC_PRECOMPILE_HEADERS": false,
139145
"BUILDCC_EXAMPLES": false,

bootstrap/main.buildcc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ static void global_flags_cb(TargetInfo &global_info,
3232
const BaseToolchain &toolchain);
3333

3434
static void setup_buildcc_cb(PersistentStorage &storage, Register &reg,
35-
const Args::ToolchainArg &custom_toolchain_arg,
35+
const ArgToolchain &custom_toolchain_arg,
3636
const BaseToolchain &toolchain);
3737

3838
static void hybrid_simple_example_cb(BaseTarget &target,
3939
const BaseTarget &libbuildcc);
4040

4141
int main(int argc, char **argv) {
4242
Args args;
43-
Args::ToolchainArg custom_toolchain_arg;
43+
ArgToolchain custom_toolchain_arg;
4444
args.AddToolchain("custom", "Host Toolchain", custom_toolchain_arg);
4545
args.Parse(argc, argv);
4646

@@ -102,7 +102,7 @@ static void global_flags_cb(TargetInfo &global_info,
102102
}
103103

104104
static void setup_buildcc_cb(PersistentStorage &storage, Register &reg,
105-
const Args::ToolchainArg &custom_toolchain_arg,
105+
const ArgToolchain &custom_toolchain_arg,
106106
const BaseToolchain &toolchain) {
107107

108108
// Flatc Executable

buildcc/lib/args/include/args/args.h

Lines changed: 53 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -31,66 +31,59 @@ namespace fs = std::filesystem;
3131

3232
namespace buildcc {
3333

34-
class Args {
35-
public:
36-
/**
37-
* @brief Toolchain State used by the Register module to selectively build or
38-
* test targets
39-
*/
40-
struct ToolchainState {
41-
bool build{false};
42-
bool test{false};
43-
};
34+
/**
35+
* @brief Toolchain State used by the Register module to selectively build or
36+
* test targets
37+
*/
38+
struct ArgToolchainState {
39+
bool build{false};
40+
bool test{false};
41+
};
42+
43+
/**
44+
* @brief Toolchain Arg used to receive toolchain information through the
45+
* command line
46+
* Bundled with Toolchain State
47+
*/
48+
struct ArgToolchain {
49+
ArgToolchain(){};
50+
ArgToolchain(ToolchainId initial_id, const std::string &initial_name,
51+
const std::string &initial_asm_compiler,
52+
const std::string &initial_c_compiler,
53+
const std::string &initial_cpp_compiler,
54+
const std::string &initial_archiver,
55+
const std::string &initial_linker)
56+
: id(initial_id), name(initial_name), asm_compiler(initial_asm_compiler),
57+
c_compiler(initial_c_compiler), cpp_compiler(initial_cpp_compiler),
58+
archiver(initial_archiver), linker(initial_linker) {}
59+
60+
BaseToolchain ConstructToolchain() const {
61+
BaseToolchain toolchain(id, name, asm_compiler, c_compiler, cpp_compiler,
62+
archiver, linker);
63+
return toolchain;
64+
}
65+
66+
ArgToolchainState state;
67+
ToolchainId id{ToolchainId::Undefined};
68+
std::string name{""};
69+
std::string asm_compiler{""};
70+
std::string c_compiler{""};
71+
std::string cpp_compiler{""};
72+
std::string archiver{""};
73+
std::string linker{""};
74+
};
4475

45-
// TODO, Rename to Toolchain
46-
// TODO, Put ToolchainState into Args::Toolchain
47-
// TODO, Add operator() overload and remove ConstructToolchain
76+
// NOTE, Incomplete without pch_compile_command
77+
// TODO, Update this for PCH
78+
struct ArgTarget {
79+
ArgTarget(){};
4880

49-
/**
50-
* @brief Toolchain Arg used to receive toolchain information through the
51-
* command line
52-
* Bundled with Toolchain State
53-
*/
54-
struct ToolchainArg {
55-
ToolchainArg(){};
56-
57-
ToolchainArg(base::Toolchain::Id initial_id,
58-
const std::string &initial_name,
59-
const std::string &initial_asm_compiler,
60-
const std::string &initial_c_compiler,
61-
const std::string &initial_cpp_compiler,
62-
const std::string &initial_archiver,
63-
const std::string &initial_linker)
64-
: id(initial_id), name(initial_name),
65-
asm_compiler(initial_asm_compiler), c_compiler(initial_c_compiler),
66-
cpp_compiler(initial_cpp_compiler), archiver(initial_archiver),
67-
linker(initial_linker) {}
68-
69-
base::Toolchain ConstructToolchain() const {
70-
base::Toolchain toolchain(id, name, asm_compiler, c_compiler,
71-
cpp_compiler, archiver, linker);
72-
return toolchain;
73-
}
74-
75-
ToolchainState state;
76-
base::Toolchain::Id id{base::Toolchain::Id::Undefined};
77-
std::string name{""};
78-
std::string asm_compiler{""};
79-
std::string c_compiler{""};
80-
std::string cpp_compiler{""};
81-
std::string archiver{""};
82-
std::string linker{""};
83-
};
84-
85-
// NOTE, Incomplete without pch_compile_command
86-
// TODO, Update this for PCH
87-
struct TargetArg {
88-
TargetArg(){};
89-
90-
std::string compile_command{""};
91-
std::string link_command{""};
92-
};
81+
std::string compile_command{""};
82+
std::string link_command{""};
83+
};
9384

85+
class Args {
86+
public:
9487
public:
9588
Args() { Initialize(); }
9689
Args(const Args &) = delete;
@@ -110,13 +103,13 @@ class Args {
110103
* @param initial Set the default toolchain information as a fallback
111104
*/
112105
void AddToolchain(const std::string &name, const std::string &description,
113-
ToolchainArg &out,
114-
const ToolchainArg &initial = ToolchainArg());
106+
ArgToolchain &out,
107+
const ArgToolchain &initial = ArgToolchain());
115108

116109
// NOTE, Incomplete TargetArg
117110
// TODO, Update for pch_compile_command
118111
void AddTarget(const std::string &name, const std::string &description,
119-
TargetArg &out, const TargetArg &initial = TargetArg());
112+
ArgTarget &out, const ArgTarget &initial = ArgTarget());
120113

121114
// Getters
122115
bool Clean() const { return clean_; }

buildcc/lib/args/include/args/register.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class Register {
5656
* Can be used to add Toolchain-Target specific information
5757
*/
5858
template <typename C, typename... Params>
59-
void CallbackIf(const Args::ToolchainState &toolchain_state,
60-
const C &build_cb, Params &...params) {
59+
void CallbackIf(const ArgToolchainState &toolchain_state, const C &build_cb,
60+
Params &...params) {
6161
if (toolchain_state.build) {
6262
Callback(build_cb, std::forward<Params &>(params)...);
6363
}
@@ -67,7 +67,7 @@ class Register {
6767
* @brief Register the Target to be built
6868
*/
6969
template <typename C, typename... Params>
70-
void Build(const Args::ToolchainState &toolchain_state, const C &build_cb,
70+
void Build(const ArgToolchainState &toolchain_state, const C &build_cb,
7171
base::Target &target, Params &...params) {
7272
tf::Task task;
7373
CallbackIf(
@@ -106,7 +106,7 @@ class Register {
106106
*
107107
* Target is added as the `{executable}` argument
108108
*/
109-
void Test(const Args::ToolchainState &toolchain_state,
109+
void Test(const ArgToolchainState &toolchain_state,
110110
const std::string &command, const base::Target &target,
111111
const TestConfig &config = TestConfig());
112112

buildcc/lib/args/src/args.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const std::unordered_map<const char *, buildcc::base::Toolchain::Id>
8989
namespace buildcc {
9090

9191
void Args::AddToolchain(const std::string &name, const std::string &description,
92-
ToolchainArg &out, const ToolchainArg &initial) {
92+
ArgToolchain &out, const ArgToolchain &initial) {
9393
CLI::App *t_user =
9494
toolchain_->add_subcommand(name, description)->group(kToolchainGroup);
9595
t_user->add_flag(kToolchainBuildParam, out.state.build);
@@ -112,7 +112,7 @@ void Args::AddToolchain(const std::string &name, const std::string &description,
112112
}
113113

114114
void Args::AddTarget(const std::string &name, const std::string &description,
115-
TargetArg &out, const TargetArg &initial) {
115+
ArgTarget &out, const ArgTarget &initial) {
116116
CLI::App *target_user =
117117
target_->add_subcommand(name, description)->group(kTargetGroup);
118118
target_user->add_option(kTargetCompileCommandParam, out.compile_command)

buildcc/lib/args/src/register.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void Register::Dep(const base::BuilderInterface &target,
8787
target_iter->second.succeed(dep_iter->second);
8888
}
8989

90-
void Register::Test(const Args::ToolchainState &toolchain_state,
90+
void Register::Test(const ArgToolchainState &toolchain_state,
9191
const std::string &command, const base::Target &target,
9292
const TestConfig &config) {
9393
if (!(toolchain_state.build && toolchain_state.test)) {

buildcc/lib/args/test/test_args.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ TEST(ArgsTestGroup, Args_CustomToolchain) {
5454
int argc = av.size();
5555

5656
buildcc::Args args;
57-
buildcc::Args::ToolchainArg gcc_toolchain;
57+
buildcc::ArgToolchain gcc_toolchain;
5858
args.AddToolchain("gcc", "Generic gcc toolchain", gcc_toolchain);
5959
args.Parse(argc, av.data());
6060

@@ -88,8 +88,8 @@ TEST(ArgsTestGroup, Args_MultipleCustomToolchain) {
8888
int argc = av.size();
8989

9090
buildcc::Args args;
91-
buildcc::Args::ToolchainArg gcc_toolchain;
92-
buildcc::Args::ToolchainArg msvc_toolchain;
91+
buildcc::ArgToolchain gcc_toolchain;
92+
buildcc::ArgToolchain msvc_toolchain;
9393
args.AddToolchain("gcc", "Generic gcc toolchain", gcc_toolchain);
9494
args.AddToolchain("msvc", "Generic msvc toolchain", msvc_toolchain);
9595
args.Parse(argc, av.data());
@@ -126,8 +126,8 @@ TEST(ArgsTestGroup, Args_MultipleCustomToolchain) {
126126

127127
TEST(ArgsTestGroup, Args_DuplicateCustomToolchain) {
128128
buildcc::Args args;
129-
buildcc::Args::ToolchainArg gcc_toolchain;
130-
buildcc::Args::ToolchainArg other_gcc_toolchain;
129+
buildcc::ArgToolchain gcc_toolchain;
130+
buildcc::ArgToolchain other_gcc_toolchain;
131131
args.AddToolchain("gcc", "Generic gcc toolchain", gcc_toolchain);
132132

133133
// CLI11 Throws an exception when multiple toolchains with same name are added
@@ -151,8 +151,8 @@ TEST(ArgsTestGroup, Args_CustomTarget) {
151151
int argc = av.size();
152152

153153
buildcc::Args args;
154-
buildcc::Args::ToolchainArg gcc_toolchain;
155-
buildcc::Args::TargetArg gcc_target;
154+
buildcc::ArgToolchain gcc_toolchain;
155+
buildcc::ArgTarget gcc_target;
156156
args.AddToolchain("gcc", "Generic gcc toolchain", gcc_toolchain);
157157
args.AddTarget("gcc", "Generic gcc target", gcc_target);
158158
args.Parse(argc, av.data());
@@ -199,12 +199,12 @@ TEST(ArgsTestGroup, Args_MultipleCustomTarget) {
199199
int argc = av.size();
200200

201201
buildcc::Args args;
202-
buildcc::Args::ToolchainArg gcc_toolchain;
203-
buildcc::Args::TargetArg gcc_target;
202+
buildcc::ArgToolchain gcc_toolchain;
203+
buildcc::ArgTarget gcc_target;
204204
args.AddToolchain("gcc", "Generic gcc toolchain", gcc_toolchain);
205205
args.AddTarget("gcc", "Generic gcc target", gcc_target);
206-
buildcc::Args::ToolchainArg msvc_toolchain;
207-
buildcc::Args::TargetArg msvc_target;
206+
buildcc::ArgToolchain msvc_toolchain;
207+
buildcc::ArgTarget msvc_target;
208208
args.AddToolchain("msvc", "Generic msvc toolchain", msvc_toolchain);
209209
args.AddTarget("msvc", "Generic msvc target", msvc_target);
210210
args.Parse(argc, av.data());

0 commit comments

Comments
 (0)