Skip to content

Commit 57a26a5

Browse files
authored
[Serialization] Removing flatbuffer/flexbuffer usage and library from BuildCC (#226)
1 parent 2c2337e commit 57a26a5

33 files changed

+74
-158
lines changed

.gitmodules

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
[submodule "flatbuffers"]
2-
path = third_party/flatbuffers
3-
url = https://github.com/google/flatbuffers.git
1+
[submodule "json"]
2+
path = third_party/json
3+
url = https://github.com/nlohmann/json.git
44
[submodule "spdlog"]
55
path = third_party/spdlog
66
url = https://github.com/gabime/spdlog.git
@@ -22,6 +22,3 @@
2222
[submodule "optional"]
2323
path = third_party/tl_optional
2424
url = https://github.com/TartanLlama/optional.git
25-
[submodule "json"]
26-
path = third_party/json
27-
url = https://github.com/nlohmann/json.git

CMakeLists.txt

-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ project(BuildCC
1212

1313
# User options
1414
option(BUILDCC_INSTALL "Enable BuildCC Installation" ON)
15-
option(BUILDCC_FLATBUFFERS_FLATC "Build Flatbuffer::Flatc Compiler" ON)
16-
1715
option(BUILDCC_BUILD_AS_SINGLE_LIB "Build all internal libs and modules as part of the buildcc library" ON)
1816
option(BUILDCC_BUILD_AS_INTERFACE "Build all internal libs and modules seperately and link" OFF)
1917

@@ -34,7 +32,6 @@ option(BUILDCC_DOCUMENTATION "Enable Documentation" OFF)
3432

3533
# Compiler options
3634
# NOTE, This option is required for clang compilers, architecture x86_64-pc-windows-msvc
37-
# Flatbuffers library uses `std::system` internally which causes a deprecated error
3835
option(BUILDCC_NO_DEPRECATED "Disable Deprecated" OFF)
3936
if (${BUILDCC_NO_DEPRECATED})
4037
add_compile_options("-Wno-deprecated")
@@ -72,9 +69,7 @@ include(cmake/tool/cppcheck.cmake)
7269
include(cmake/tool/doxygen.cmake)
7370

7471
# Libraries
75-
include(cmake/target/flatbuffers.cmake)
7672
include(cmake/target/json.cmake)
77-
7873
include(cmake/target/fmt.cmake)
7974
include(cmake/target/spdlog.cmake)
8075
include(cmake/target/cli11.cmake)

CMakePresets.json

-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"CMAKE_C_COMPILER": "gcc",
1818
"CMAKE_CXX_COMPILER": "g++",
1919
"BUILDCC_INSTALL": true,
20-
"BUILDCC_FLATBUFFERS_FLATC": true,
2120
"BUILDCC_BUILD_AS_SINGLE_LIB": true,
2221
"BUILDCC_BUILD_AS_INTERFACE": true,
2322
"BUILDCC_BUILDEXE": true,
@@ -42,7 +41,6 @@
4241
"CMAKE_C_COMPILER": "gcc",
4342
"CMAKE_CXX_COMPILER": "g++",
4443
"BUILDCC_INSTALL": true,
45-
"BUILDCC_FLATBUFFERS_FLATC": true,
4644
"BUILDCC_BUILD_AS_SINGLE_LIB": true,
4745
"BUILDCC_BUILD_AS_INTERFACE": false,
4846
"BUILDCC_BUILDEXE": true,
@@ -67,7 +65,6 @@
6765
"CMAKE_C_COMPILER": "gcc",
6866
"CMAKE_CXX_COMPILER": "g++",
6967
"BUILDCC_INSTALL": true,
70-
"BUILDCC_FLATBUFFERS_FLATC": true,
7168
"BUILDCC_BUILD_AS_SINGLE_LIB": false,
7269
"BUILDCC_BUILD_AS_INTERFACE": true,
7370
"BUILDCC_BUILDEXE": false,
@@ -92,7 +89,6 @@
9289
"CMAKE_C_COMPILER": "clang",
9390
"CMAKE_CXX_COMPILER": "clang++",
9491
"BUILDCC_INSTALL": true,
95-
"BUILDCC_FLATBUFFERS_FLATC": true,
9692
"BUILDCC_BUILD_AS_SINGLE_LIB": true,
9793
"BUILDCC_BUILD_AS_INTERFACE": true,
9894
"BUILDCC_BUILDEXE": true,
@@ -114,7 +110,6 @@
114110
"binaryDir": "${sourceDir}/_build_msvc_dev_all",
115111
"cacheVariables": {
116112
"BUILDCC_INSTALL": true,
117-
"BUILDCC_FLATBUFFERS_FLATC": true,
118113
"BUILDCC_BUILD_AS_SINGLE_LIB": true,
119114
"BUILDCC_BUILD_AS_INTERFACE": true,
120115
"BUILDCC_BUILDEXE": true,
@@ -136,7 +131,6 @@
136131
"binaryDir": "${sourceDir}/_build_msvc_analysis",
137132
"cacheVariables": {
138133
"BUILDCC_INSTALL": false,
139-
"BUILDCC_FLATBUFFERS_FLATC": true,
140134
"BUILDCC_BUILD_AS_SINGLE_LIB": true,
141135
"BUILDCC_BUILD_AS_INTERFACE": false,
142136
"BUILDCC_BUILDEXE": false,

DEPENDENCIES.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
These third party libraries are added as submodules since they aren't meant to be modified by this project.
44

5+
### Adding a submodule
6+
57
`git submodule add [git_url] third_party/[foldername]`
68

9+
### Removing a submodule
10+
11+
- `git rm --cached path_to_submodule` (no trailing slash)
12+
- Delete relevant line from `.gitmodules` file
13+
- Delete relevant section from `.git/config` file
14+
715
## Main
816

917
- fmt (Formatting)
1018
- spdlog (Logging)
11-
- flatbuffers (Serialization)
19+
- json (Serialization)
1220
- CLI11 (Argument Parsing)
1321
- Taskflow (Parallel Programming)
1422

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Build C, C++ and ASM files in C++
2727
- `C++17 filesystem` library support
2828
- `C++11 thread` library support
2929
- Third Party Libraries (See License below)
30-
- Flatbuffers v2.0.0
3130
- Nlohmann::Json v3.11.2
3231
- Taskflow v3.1.0
3332
- CLI11 v2.1.0
@@ -178,7 +177,6 @@ _BuildCC_ is licensed under the Apache License, Version 2.0. See [LICENSE](LICEN
178177
- [Taskflow](https://github.com/taskflow/taskflow) (Parallel Programming) [MIT License] [Header Only]
179178
- See also [3rd-Party](https://github.com/taskflow/taskflow/tree/master/3rd-party) used by Taskflow
180179
- [Nlohmann::Json](https://github.com/nlohmann/json) (JSON Serialization) [MIT License] [Header Only]
181-
- [Flatbuffers](https://github.com/google/flatbuffers) (Serialization) [Apache-2.0 License]
182180
- [CLI11](https://github.com/CLIUtils/CLI11) (Argument Parsing) [BSD-3-Clause License] [Header Only]
183181
- [CppUTest](https://github.com/cpputest/cpputest) (Unit Testing/Mocking) [BSD-3-Clause License]
184182
- [Tl::Optional](https://github.com/TartanLlama/optional) (Optional support) [CC0-1.0 License]

bootstrap/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ add_executable(buildcc_lib_bootstrap
22
main.buildcc.cpp
33
)
44
target_sources(buildcc_lib_bootstrap PRIVATE
5-
src/build_flatbuffers.cpp
65
src/build_nlohmann_json.cpp
76
src/build_cli11.cpp
87
src/build_fmtlib.cpp

bootstrap/include/bootstrap/build_buildcc.h

+4-13
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "buildcc.h"
2121

2222
#include "build_cli11.h"
23-
#include "build_flatbuffers.h"
2423
#include "build_fmtlib.h"
2524
#include "build_nlohmann_json.h"
2625
#include "build_spdlog.h"
@@ -30,11 +29,10 @@
3029

3130
namespace buildcc {
3231

33-
void buildcc_cb(BaseTarget &target, const TargetInfo &flatbuffers_ho,
34-
const TargetInfo &nlohmann_json_ho, const TargetInfo &fmt_ho,
35-
const TargetInfo &spdlog_ho, const TargetInfo &cli11_ho,
36-
const TargetInfo &taskflow_ho, const TargetInfo &tl_optional_ho,
37-
const BaseTarget &tpl);
32+
void buildcc_cb(BaseTarget &target, const TargetInfo &nlohmann_json_ho,
33+
const TargetInfo &fmt_ho, const TargetInfo &spdlog_ho,
34+
const TargetInfo &cli11_ho, const TargetInfo &taskflow_ho,
35+
const TargetInfo &tl_optional_ho, const BaseTarget &tpl);
3836

3937
/**
4038
* @brief
@@ -43,7 +41,6 @@ void buildcc_cb(BaseTarget &target, const TargetInfo &flatbuffers_ho,
4341
class BuildBuildCC {
4442
public:
4543
// TargetInfo / Header Only
46-
static constexpr const char *const kFlatbuffersHoName = "flatbuffers_ho";
4744
static constexpr const char *const kNlohmannJsonHoName = "nlohmann_json_ho";
4845
static constexpr const char *const kCli11HoName = "cli11_ho";
4946
static constexpr const char *const kFmtHoName = "fmtlib_ho";
@@ -77,12 +74,6 @@ class BuildBuildCC {
7774

7875
private:
7976
void Initialize();
80-
ExecutableTarget_generic &GetFlatc() {
81-
return storage_.Ref<ExecutableTarget_generic>(kFlatcExeName);
82-
}
83-
TargetInfo &GetFlatbuffersHo() {
84-
return storage_.Ref<TargetInfo>(kFlatbuffersHoName);
85-
}
8677
TargetInfo &GetNlohmannJsonHo() {
8778
return storage_.Ref<TargetInfo>(kNlohmannJsonHoName);
8879
}

bootstrap/main.buildcc.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "buildcc.h"
1818

1919
#include "bootstrap/build_cli11.h"
20-
#include "bootstrap/build_flatbuffers.h"
2120
#include "bootstrap/build_fmtlib.h"
2221
#include "bootstrap/build_spdlog.h"
2322
#include "bootstrap/build_taskflow.h"

bootstrap/src/build_buildcc.cpp

+7-24
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818

1919
namespace buildcc {
2020

21-
void buildcc_cb(BaseTarget &target, const TargetInfo &flatbuffers_ho,
22-
const TargetInfo &nlohmann_json_ho, const TargetInfo &fmt_ho,
23-
const TargetInfo &spdlog_ho, const TargetInfo &cli11_ho,
24-
const TargetInfo &taskflow_ho, const TargetInfo &tl_optional_ho,
25-
const BaseTarget &tpl) {
21+
void buildcc_cb(BaseTarget &target, const TargetInfo &nlohmann_json_ho,
22+
const TargetInfo &fmt_ho, const TargetInfo &spdlog_ho,
23+
const TargetInfo &cli11_ho, const TargetInfo &taskflow_ho,
24+
const TargetInfo &tl_optional_ho, const BaseTarget &tpl) {
2625
// NOTE, Build as single lib
2726
target.AddIncludeDir("", true);
2827

@@ -88,9 +87,6 @@ void buildcc_cb(BaseTarget &target, const TargetInfo &flatbuffers_ho,
8887
SyncOption::HeaderFiles,
8988
};
9089

91-
// FLATBUFFERS HO
92-
target.Insert(flatbuffers_ho, kInsertOptions);
93-
9490
// NLOHMANN JSON HO
9591
target.Insert(nlohmann_json_ho, kInsertOptions);
9692

@@ -175,17 +171,6 @@ static void global_flags_cb(TargetInfo &global_info,
175171
}
176172

177173
void BuildBuildCC::Initialize() {
178-
(void)storage_.Add<ExecutableTarget_generic>(
179-
kFlatcExeName, kFlatcExeName, toolchain_,
180-
TargetEnv(env_.GetTargetRootDir() / "third_party" / "flatbuffers",
181-
env_.GetTargetBuildDir()));
182-
183-
// Flatbuffers HO lib
184-
(void)storage_.Add<TargetInfo>(
185-
kFlatbuffersHoName, toolchain_,
186-
TargetEnv(env_.GetTargetRootDir() / "third_party" / "flatbuffers",
187-
env_.GetTargetBuildDir()));
188-
189174
// Nlohmann json HO lib
190175
(void)storage_.Add<TargetInfo>(
191176
kNlohmannJsonHoName, toolchain_,
@@ -240,7 +225,6 @@ void BuildBuildCC::Initialize() {
240225
}
241226

242227
void BuildBuildCC::Setup(const ArgToolchainState &state) {
243-
auto &flatbuffers_ho_lib = GetFlatbuffersHo();
244228
auto &nlohmann_json_ho_lib = GetNlohmannJsonHo();
245229
auto &cli11_ho_lib = GetCli11Ho();
246230
auto &fmt_ho_lib = GetFmtHo();
@@ -250,7 +234,6 @@ void BuildBuildCC::Setup(const ArgToolchainState &state) {
250234
auto &tpl_lib = GetTpl();
251235
auto &buildcc_lib = GetBuildcc();
252236
Reg::Toolchain(state)
253-
.Func(flatbuffers_ho_cb, flatbuffers_ho_lib)
254237
.Func(nlohmann_json_ho_cb, nlohmann_json_ho_lib)
255238
.Func(cli11_ho_cb, cli11_ho_lib)
256239
.Func(fmt_ho_cb, fmt_ho_lib)
@@ -260,9 +243,9 @@ void BuildBuildCC::Setup(const ArgToolchainState &state) {
260243
.Func(global_flags_cb, tpl_lib, toolchain_)
261244
.Build(tpl_cb, tpl_lib)
262245
.Func(global_flags_cb, buildcc_lib, toolchain_)
263-
.Build(buildcc_cb, buildcc_lib, flatbuffers_ho_lib, nlohmann_json_ho_lib,
264-
fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib, taskflow_ho_lib,
265-
tl_optional_ho_lib, tpl_lib)
246+
.Build(buildcc_cb, buildcc_lib, nlohmann_json_ho_lib, fmt_ho_lib,
247+
spdlog_ho_lib, cli11_ho_lib, taskflow_ho_lib, tl_optional_ho_lib,
248+
tpl_lib)
266249
.Dep(buildcc_lib, tpl_lib);
267250
}
268251

buildcc/CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ if(${BUILDCC_BUILD_AS_SINGLE_LIB})
1313
target_link_libraries(buildcc PUBLIC
1414
fmt::fmt
1515
tl::optional
16-
flatbuffers
1716
nlohmann_json::nlohmann_json
1817
Taskflow
1918
CLI11::CLI11
@@ -29,7 +28,7 @@ if(${BUILDCC_BUILD_AS_SINGLE_LIB})
2928
endif()
3029
endif()
3130

32-
# Flatbuffers schema
31+
# Schema
3332
add_subdirectory(schema)
3433

3534
# Environment

buildcc/lib/target/src/generator/file_generator.cpp

+6-25
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
#include <algorithm>
2020

21-
#include "flatbuffers/flexbuffers.h"
22-
2321
#include "env/assert_fatal.h"
2422

2523
namespace {
@@ -32,29 +30,18 @@ class FileGeneratorBlobHandler : public buildcc::CustomBlobHandler {
3230
// serialized_data has already been verified
3331
static std::vector<std::string>
3432
Deserialize(const std::vector<uint8_t> &serialized_data) {
33+
json j = json::from_msgpack(serialized_data, true, false);
3534
std::vector<std::string> deserialized;
36-
auto flex_vect = flexbuffers::GetRoot(serialized_data).AsVector();
37-
for (size_t i = 0; i < flex_vect.size(); i++) {
38-
deserialized.emplace_back(flex_vect[i].AsString().str());
39-
}
35+
j.get_to(deserialized);
4036
return deserialized;
4137
}
4238

4339
private:
4440
const std::vector<std::string> &commands_;
4541

4642
bool Verify(const std::vector<uint8_t> &serialized_data) const override {
47-
auto flex_ref = flexbuffers::GetRoot(serialized_data);
48-
if (!flex_ref.IsVector()) {
49-
return false;
50-
}
51-
auto flex_vect = flex_ref.AsVector();
52-
for (size_t i = 0; i < flex_vect.size(); i++) {
53-
if (!flex_vect[i].IsString()) {
54-
return false;
55-
}
56-
}
57-
return true;
43+
json j = json::from_msgpack(serialized_data, true, false);
44+
return !j.is_discarded();
5845
}
5946

6047
bool IsEqual(const std::vector<uint8_t> &previous,
@@ -63,14 +50,8 @@ class FileGeneratorBlobHandler : public buildcc::CustomBlobHandler {
6350
}
6451

6552
std::vector<uint8_t> Serialize() const override {
66-
flexbuffers::Builder builder;
67-
builder.Vector([&]() {
68-
for (const auto &c : commands_) {
69-
builder.Add(c);
70-
}
71-
});
72-
builder.Finish();
73-
return builder.GetBuffer();
53+
json j = commands_;
54+
return json::to_msgpack(j);
7455
}
7556
};
7657

buildcc/lib/target/test/target/test_custom_generator.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include "expect_custom_generator.h"
55
#include "test_target_util.h"
66

7-
#include "flatbuffers/flexbuffers.h"
8-
97
#include <memory>
108

119
// NOTE, Make sure all these includes are AFTER the system and header includes
@@ -986,7 +984,8 @@ class MyCustomBlobHandler : public buildcc::CustomBlobHandler {
986984

987985
private:
988986
bool Verify(const std::vector<uint8_t> &serialized_data) const override {
989-
return flexbuffers::GetRoot(serialized_data).IsInt();
987+
json j = json::from_msgpack(serialized_data);
988+
return !j.is_discarded();
990989
}
991990

992991
bool IsEqual(const std::vector<uint8_t> &previous,
@@ -995,15 +994,16 @@ class MyCustomBlobHandler : public buildcc::CustomBlobHandler {
995994
}
996995

997996
std::vector<uint8_t> Serialize() const override {
998-
flexbuffers::Builder builder;
999-
builder.Add(recheck_value);
1000-
builder.Finish();
1001-
return builder.GetBuffer();
997+
json j = recheck_value;
998+
return json::to_msgpack(j);
1002999
}
10031000

10041001
// serialized_data has already been verified
10051002
int32_t Deserialize(const std::vector<uint8_t> &serialized_data) const {
1006-
return flexbuffers::GetRoot(serialized_data).AsInt32();
1003+
json j = json::from_msgpack(serialized_data);
1004+
int32_t deserialized;
1005+
j.get_to(deserialized);
1006+
return deserialized;
10071007
}
10081008
};
10091009

buildcc/schema/cmake/schema.cmake

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ if (${TESTING})
2020
)
2121
target_link_libraries(mock_schema PUBLIC
2222
mock_env
23-
flatbuffers
2423
nlohmann_json::nlohmann_json
2524

2625
CppUTest
@@ -88,7 +87,6 @@ if(${BUILDCC_BUILD_AS_INTERFACE})
8887
)
8988
target_link_libraries(schema PUBLIC
9089
env
91-
flatbuffers
9290
nlohmann_json::nlohmann_json
9391
)
9492
target_include_directories(schema PRIVATE

0 commit comments

Comments
 (0)