Skip to content

Commit c9c2cd8

Browse files
authored
Toolchain config (#194)
Instead of having all configurations on the Target level, we have common parameters on the Toolchain level (which can be used by the corresponding targets). - TargetInfo now requires Toolchain - Some TargetConfig parameters are shifted to ToolchainConfig
1 parent 2dedb35 commit c9c2cd8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+420
-313
lines changed

.github/workflows/msvc-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ env:
2525
jobs:
2626
analyze:
2727
name: Analyze
28-
runs-on: windows-latest
28+
runs-on: windows-2019
2929

3030
steps:
3131
- name: Checkout repository

bootstrap/src/build_buildcc.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen,
6262

6363
// TOOLCHAIN
6464
target.GlobSources("lib/toolchain/src/api");
65+
target.GlobSources("lib/toolchain/src/common");
6566
target.AddIncludeDir("lib/toolchain/include");
6667
target.GlobHeaders("lib/toolchain/include/toolchain");
6768
target.GlobHeaders("lib/toolchain/include/toolchain/api");
69+
target.GlobHeaders("lib/toolchain/include/toolchain/common");
6870

6971
// TARGET
7072
target.GlobSources("lib/target/src/common");
@@ -205,33 +207,35 @@ void BuildBuildCC::Setup(const ArgToolchainState &state) {
205207

206208
// Flatbuffers HO lib
207209
auto &flatbuffers_ho_lib = storage_.Add<TargetInfo>(
208-
kFlatbuffersHoName,
210+
kFlatbuffersHoName, toolchain_,
209211
TargetEnv(env_.GetTargetRootDir() / "third_party" / "flatbuffers",
210212
env_.GetTargetBuildDir()));
211213
reg_.CallbackIf(state, flatbuffers_ho_cb, flatbuffers_ho_lib);
212214

213215
// CLI11 HO lib
214216
auto &cli11_ho_lib = storage_.Add<TargetInfo>(
215-
kCli11HoName, TargetEnv(env_.GetTargetRootDir() / "third_party" / "CLI11",
216-
env_.GetTargetBuildDir()));
217+
kCli11HoName, toolchain_,
218+
TargetEnv(env_.GetTargetRootDir() / "third_party" / "CLI11",
219+
env_.GetTargetBuildDir()));
217220
reg_.CallbackIf(state, cli11_ho_cb, cli11_ho_lib);
218221

219222
// fmt HO lib
220223
auto &fmt_ho_lib = storage_.Add<TargetInfo>(
221-
kFmtHoName, TargetEnv(env_.GetTargetRootDir() / "third_party" / "fmt",
222-
env_.GetTargetBuildDir()));
224+
kFmtHoName, toolchain_,
225+
TargetEnv(env_.GetTargetRootDir() / "third_party" / "fmt",
226+
env_.GetTargetBuildDir()));
223227
reg_.CallbackIf(state, fmt_ho_cb, fmt_ho_lib);
224228

225229
// spdlog HO lib
226230
auto &spdlog_ho_lib = storage_.Add<TargetInfo>(
227-
kSpdlogHoName,
231+
kSpdlogHoName, toolchain_,
228232
TargetEnv(env_.GetTargetRootDir() / "third_party" / "spdlog",
229233
env_.GetTargetBuildDir()));
230234
reg_.CallbackIf(state, spdlog_ho_cb, spdlog_ho_lib);
231235

232236
// taskflow HO lib
233237
auto &taskflow_ho_lib = storage_.Add<TargetInfo>(
234-
kTaskflowHoName,
238+
kTaskflowHoName, toolchain_,
235239
TargetEnv(env_.GetTargetRootDir() / "third_party" / "taskflow",
236240
env_.GetTargetBuildDir()));
237241
reg_.CallbackIf(state, taskflow_ho_cb, taskflow_ho_lib);

buildcc/lib/target/cmake/common_target_src.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ set(COMMON_TARGET_SRCS
77
src/common/target_state.cpp
88
include/target/common/target_config.h
99
include/target/common/target_state.h
10-
include/target/common/target_file_ext.h
1110
include/target/common/target_env.h
1211

1312
src/common/util.cpp

buildcc/lib/target/cmake/mock_target.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ target_link_options(mock_target PUBLIC ${TEST_LINK_FLAGS} ${BUILD_LINK_FLAGS})
2121
target_link_libraries(mock_target PUBLIC
2222
Taskflow
2323

24-
mock_schema
2524
mock_toolchain
2625

2726
CppUTest

buildcc/lib/target/cmake/target.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ if(${BUILDCC_BUILD_AS_INTERFACE})
2828
$<INSTALL_INTERFACE:${BUILDCC_INSTALL_HEADER_PREFIX}>
2929
)
3030
target_link_libraries(target PUBLIC
31-
schema
3231
toolchain
3332
Taskflow
3433
)

buildcc/lib/target/include/target/common/target_config.h

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -21,86 +21,20 @@
2121
#include <string>
2222
#include <unordered_set>
2323

24-
#include "target/common/target_file_ext.h"
25-
2624
namespace fs = std::filesystem;
2725

2826
namespace buildcc {
2927

3028
struct TargetConfig {
3129
TargetConfig() = default;
3230

33-
/**
34-
* @brief Get the valid file extension from a path
35-
*
36-
* See TargetConfig::valid_c_ext, TargetConfig::valid_cpp_ext,
37-
* TargetConfig::valid_asm_ext, TargetConfig::valid_header_ext
38-
*
39-
* @param filepath Absolute / Relative path of the file
40-
* @return TargetFileExt File path detected as per TargetConfig::valid_*
41-
* variables
42-
*/
43-
TargetFileExt GetFileExt(const fs::path &filepath) const;
44-
45-
/**
46-
* @brief Checks for C/C++ source file validity.
47-
*
48-
* See TargetConfig::valid_c_ext, TargetConfig::valid_cpp_ext,
49-
* TargetConfig::valid_asm_ext
50-
*
51-
* @param filepath Absolute / Relative path of file
52-
* @return true If file extension belongs to the above valid_* list
53-
* @return false If file extension does not belong to the above valid_* list
54-
*/
55-
bool IsValidSource(const fs::path &filepath) const;
56-
57-
/**
58-
* @brief Checks for Header file validity
59-
*
60-
* See TargetConfig::valid_header_ext
61-
*
62-
* @param filepath Absolute / Relative path of file
63-
* @return true If file extension belongs to above valid_* list
64-
* @return false If file extension does not belong to above valid_* list
65-
*/
66-
bool IsValidHeader(const fs::path &filepath) const;
67-
68-
/**
69-
* @brief Expects Source file validity
70-
*
71-
* env::assert_fatal if not a valid source
72-
*
73-
* @param filepath Absolute / Relative path of file
74-
*/
75-
void ExpectsValidSource(const fs::path &filepath) const;
76-
77-
/**
78-
* @brief Expects header file validity
79-
*
80-
* env::assert_fatal if not a valid header
81-
*
82-
* @param filepath Absolute / Relative path of file
83-
*/
84-
void ExpectsValidHeader(const fs::path &filepath) const;
85-
8631
std::string target_ext{""};
87-
std::string obj_ext{".o"};
88-
std::string pch_header_ext{".h"};
89-
std::string pch_compile_ext{".gch"};
90-
91-
std::string prefix_include_dir{"-I"};
92-
std::string prefix_lib_dir{"-L"};
9332

9433
// clang-format off
9534
std::string pch_command{"{compiler} {preprocessor_flags} {include_dirs} {common_compile_flags} {pch_compile_flags} {compile_flags} -o {output} -c {input}"};
9635
std::string compile_command{"{compiler} {preprocessor_flags} {include_dirs} {common_compile_flags} {pch_object_flags} {compile_flags} -o {output} -c {input}"};
9736
std::string link_command{"{cpp_compiler} {link_flags} {compiled_sources} -o {output} {lib_dirs} {lib_deps}"};
9837
// clang-format on
99-
100-
std::unordered_set<std::string> valid_c_ext{".c"};
101-
std::unordered_set<std::string> valid_cpp_ext{".cpp", ".cxx", ".cc"};
102-
std::unordered_set<std::string> valid_asm_ext{".s", ".S", ".asm"};
103-
std::unordered_set<std::string> valid_header_ext{".h", ".hpp"};
10438
};
10539

10640
} // namespace buildcc

buildcc/lib/target/include/target/common/target_state.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifndef TARGET_COMMON_TARGET_STATE_H_
1818
#define TARGET_COMMON_TARGET_STATE_H_
1919

20-
#include "target/common/target_file_ext.h"
20+
#include "toolchain/common/file_ext.h"
2121

2222
namespace buildcc {
2323

@@ -27,7 +27,7 @@ namespace buildcc {
2727
// TargetInfo does not have a `Build` method, it is only meant to hold
2828
// information
2929
struct TargetState {
30-
void SetSourceState(TargetFileExt file_extension);
30+
void SetSourceState(FileExt file_extension);
3131
void SetPch();
3232
void SetLock();
3333

buildcc/lib/target/include/target/target.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ class Target : public internal::BuilderInterface,
7070
const Toolchain &toolchain, const TargetEnv &env,
7171
const TargetConfig &config = TargetConfig())
7272
: TargetInfo(
73+
toolchain,
7374
TargetEnv(env.GetTargetRootDir(),
7475
env.GetTargetBuildDir() / toolchain.GetName() / name),
7576
config),
76-
name_(name), type_(type), toolchain_(toolchain),
77+
name_(name), type_(type),
78+
// toolchain_(toolchain),
7779
// loader_(name, env_.GetTargetBuildDir()),
7880
serialization_(env_.GetTargetBuildDir() / fmt::format("{}.bin", name)),
7981
compile_pch_(*this), compile_object_(*this), link_target_(*this) {
@@ -99,8 +101,8 @@ class Target : public internal::BuilderInterface,
99101
void Initialize();
100102

101103
//
102-
std::optional<std::string> SelectCompileFlags(TargetFileExt ext) const;
103-
std::optional<std::string> SelectCompiler(TargetFileExt ext) const;
104+
std::optional<std::string> SelectCompileFlags(FileExt ext) const;
105+
std::optional<std::string> SelectCompiler(FileExt ext) const;
104106

105107
// Recompilation checks
106108
void RecheckPaths(const internal::path_unordered_set &previous_path,
@@ -139,7 +141,7 @@ class Target : public internal::BuilderInterface,
139141
private:
140142
std::string name_;
141143
TargetType type_;
142-
const Toolchain &toolchain_;
144+
// const Toolchain &toolchain_;
143145
internal::TargetSerialization serialization_;
144146

145147
// Friend classes

buildcc/lib/target/include/target/target_info.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include <string>
2121

22+
#include "toolchain/toolchain.h"
23+
2224
#include "target/common/target_config.h"
2325
#include "target/common/target_env.h"
2426
#include "target/common/target_state.h"
@@ -60,8 +62,9 @@ class TargetInfo : public internal::SourceApi<TargetInfo>,
6062
public internal::SyncApi<TargetInfo>,
6163
public internal::TargetInfoGetter<TargetInfo> {
6264
public:
63-
TargetInfo(const TargetEnv &env, const TargetConfig &config = TargetConfig())
64-
: env_(env), config_(config) {}
65+
TargetInfo(const BaseToolchain &toolchain, const TargetEnv &env,
66+
const TargetConfig &config = TargetConfig())
67+
: toolchain_(toolchain), env_(env), config_(config) {}
6568

6669
private:
6770
// Inputs
@@ -79,6 +82,7 @@ class TargetInfo : public internal::SourceApi<TargetInfo>,
7982
friend class internal::TargetInfoGetter<TargetInfo>;
8083

8184
protected:
85+
const BaseToolchain &toolchain_;
8286
TargetEnv env_;
8387
TargetConfig config_;
8488

buildcc/lib/target/src/api/include_api.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void IncludeApi<T>::AddHeaderAbsolute(const fs::path &absolute_filepath) {
2525
T &t = static_cast<T &>(*this);
2626

2727
t.state_.ExpectsUnlock();
28-
t.config_.ExpectsValidHeader(absolute_filepath);
28+
t.toolchain_.GetConfig().ExpectsValidHeader(absolute_filepath);
2929
t.user_.headers.insert(absolute_filepath);
3030
}
3131

@@ -53,7 +53,7 @@ void IncludeApi<T>::GlobHeadersAbsolute(const fs::path &absolute_path) {
5353
T &t = static_cast<T &>(*this);
5454

5555
for (const auto &p : fs::directory_iterator(absolute_path)) {
56-
if (t.config_.IsValidHeader(p.path())) {
56+
if (t.toolchain_.GetConfig().IsValidHeader(p.path())) {
5757
AddHeaderAbsolute(p.path());
5858
}
5959
}

buildcc/lib/target/src/api/pch_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void PchApi<T>::AddPchAbsolute(const fs::path &absolute_filepath) {
2525
T &t = static_cast<T &>(*this);
2626

2727
t.state_.ExpectsUnlock();
28-
t.config_.ExpectsValidHeader(absolute_filepath);
28+
t.toolchain_.GetConfig().ExpectsValidHeader(absolute_filepath);
2929

3030
const fs::path absolute_pch = fs::path(absolute_filepath).make_preferred();
3131
t.user_.pchs.insert(absolute_pch);

buildcc/lib/target/src/api/source_api.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void SourceApi<T>::AddSourceAbsolute(const fs::path &absolute_source) {
2525
T &t = static_cast<T &>(*this);
2626

2727
t.state_.ExpectsUnlock();
28-
t.config_.ExpectsValidSource(absolute_source);
28+
t.toolchain_.GetConfig().ExpectsValidSource(absolute_source);
2929
t.user_.sources.emplace(fs::path(absolute_source).make_preferred());
3030
}
3131

@@ -34,7 +34,7 @@ void SourceApi<T>::GlobSourcesAbsolute(const fs::path &absolute_source_dir) {
3434
T &t = static_cast<T &>(*this);
3535

3636
for (const auto &p : fs::directory_iterator(absolute_source_dir)) {
37-
if (t.config_.IsValidSource(p.path())) {
37+
if (t.toolchain_.GetConfig().IsValidSource(p.path())) {
3838
AddSourceAbsolute(p.path());
3939
}
4040
}
@@ -59,7 +59,7 @@ void SourceApi<T>::GlobSources(const fs::path &relative_to_target_path) {
5959
fs::path absolute_input_path =
6060
t.env_.GetTargetRootDir() / relative_to_target_path;
6161
for (const auto &p : fs::directory_iterator(absolute_input_path)) {
62-
if (t.config_.IsValidSource(p.path())) {
62+
if (t.toolchain_.GetConfig().IsValidSource(p.path())) {
6363
AddSourceAbsolute(p.path());
6464
}
6565
}

buildcc/lib/target/src/common/target_config.cpp

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -22,67 +22,4 @@
2222

2323
#include "fmt/format.h"
2424

25-
namespace buildcc {
26-
27-
TargetFileExt TargetConfig::GetFileExt(const fs::path &filepath) const {
28-
if (!filepath.has_extension()) {
29-
return TargetFileExt::Invalid;
30-
}
31-
32-
TargetFileExt type = TargetFileExt::Invalid;
33-
const std::string ext = filepath.extension().string();
34-
35-
if (valid_c_ext.count(ext) == 1) {
36-
type = TargetFileExt::C;
37-
} else if (valid_cpp_ext.count(ext) == 1) {
38-
type = TargetFileExt::Cpp;
39-
} else if (valid_asm_ext.count(ext) == 1) {
40-
type = TargetFileExt::Asm;
41-
} else if (valid_header_ext.count(ext) == 1) {
42-
type = TargetFileExt::Header;
43-
}
44-
45-
return type;
46-
}
47-
48-
bool TargetConfig::IsValidSource(const fs::path &filepath) const {
49-
if (!filepath.has_extension()) {
50-
return false;
51-
}
52-
53-
const std::string ext = filepath.extension().string();
54-
bool valid = false;
55-
if ((valid_c_ext.find(ext) != valid_c_ext.end()) ||
56-
(valid_cpp_ext.find(ext) != valid_cpp_ext.end()) ||
57-
(valid_asm_ext.find(ext) != valid_asm_ext.end())) {
58-
valid = true;
59-
}
60-
return valid;
61-
}
62-
63-
void TargetConfig::ExpectsValidSource(const fs::path &filepath) const {
64-
env::assert_fatal(
65-
IsValidSource(filepath),
66-
fmt::format("{} does not have a valid source extension", filepath));
67-
}
68-
69-
bool TargetConfig::IsValidHeader(const fs::path &filepath) const {
70-
if (!filepath.has_extension()) {
71-
return {};
72-
}
73-
74-
const std::string ext = filepath.extension().string();
75-
bool valid = false;
76-
if ((valid_header_ext.find(ext) != valid_header_ext.end())) {
77-
valid = true;
78-
}
79-
return valid;
80-
}
81-
82-
void TargetConfig::ExpectsValidHeader(const fs::path &filepath) const {
83-
env::assert_fatal(
84-
IsValidHeader(filepath),
85-
fmt::format("{} does not have a valid header extension", filepath));
86-
}
87-
88-
} // namespace buildcc
25+
namespace buildcc {} // namespace buildcc

0 commit comments

Comments
 (0)