Skip to content

Toolchain flags api #197

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 21 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions bootstrap/src/build_buildcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen,
// TOOLCHAIN
target.GlobSources("lib/toolchain/src/api");
target.GlobSources("lib/toolchain/src/common");
target.GlobSources("lib/toolchain/src/toolchain");
target.AddIncludeDir("lib/toolchain/include");
target.GlobHeaders("lib/toolchain/include/toolchain");
target.GlobHeaders("lib/toolchain/include/toolchain/api");
Expand All @@ -72,6 +73,7 @@ void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen,
target.GlobSources("lib/target/src/common");
target.GlobSources("lib/target/src/generator");
target.GlobSources("lib/target/src/api");
target.GlobSources("lib/target/src/target_info");
target.GlobSources("lib/target/src/target");
target.GlobSources("lib/target/src/target/friend");

Expand Down
4 changes: 2 additions & 2 deletions buildcc/lib/args/test/test_persistent_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ TEST_GROUP(PersistentStorageTestGroup)
};
// clang-format on

buildcc::BaseToolchain gcc(buildcc::ToolchainId::Gcc, "gcc", "as", "gcc", "g++",
"ar", "ld");
static buildcc::BaseToolchain gcc(buildcc::ToolchainId::Gcc, "gcc", "as", "gcc",
"g++", "ar", "ld");

TEST(PersistentStorageTestGroup, BasicUsage) {
buildcc::PersistentStorage persistent;
Expand Down
6 changes: 4 additions & 2 deletions buildcc/lib/target/cmake/common_target_src.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ set(COMMON_TARGET_SRCS
include/target/api/include_api.h
include/target/api/lib_api.h
include/target/api/pch_api.h
include/target/api/flag_api.h
include/target/api/deps_api.h

src/api/sync_api.cpp
Expand All @@ -38,6 +37,10 @@ set(COMMON_TARGET_SRCS
src/generator/generator.cpp
include/target/generator.h

# Target Info
src/target_info/target_info.cpp
include/target/target_info.h

# Target friend
src/target/friend/compile_pch.cpp
src/target/friend/compile_object.cpp
Expand All @@ -49,6 +52,5 @@ set(COMMON_TARGET_SRCS
# Target
src/target/target.cpp
src/target/build.cpp
include/target/target_info.h
include/target/target.h
)
1 change: 0 additions & 1 deletion buildcc/lib/target/include/target/api/deps_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace buildcc::internal {

// Requires
// - TargetStorer
// - TargetState
// - TargetEnv
template <typename T> class DepsApi {
public:
Expand Down
1 change: 0 additions & 1 deletion buildcc/lib/target/include/target/api/include_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace buildcc::internal {

// Requires
// - TargetStorer
// - TargetState
// - TargetConfig
// - TargetEnv
template <typename T> class IncludeApi {
Expand Down
1 change: 0 additions & 1 deletion buildcc/lib/target/include/target/api/lib_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace buildcc::internal {

// Requires
// - TargetStorer
// - TargetState
// - TargetEnv
// T::GetTargetPath
template <typename T> class LibApi {
Expand Down
1 change: 0 additions & 1 deletion buildcc/lib/target/include/target/api/pch_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace buildcc::internal {

// Requires
// - TargetStorer
// - TargetState
// - TargetConfig
// - TargetEnv
template <typename T> class PchApi {
Expand Down
1 change: 0 additions & 1 deletion buildcc/lib/target/include/target/api/source_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace buildcc::internal {

// Requires
// - TargetStorer
// - TargetState
// - TargetConfig
// - TargetEnv
template <typename T> class SourceApi {
Expand Down
1 change: 0 additions & 1 deletion buildcc/lib/target/include/target/api/sync_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ enum class SyncOption {

// Requires
// - TargetStorer
// - TargetState
template <typename T> class SyncApi {
public:
/**
Expand Down
7 changes: 7 additions & 0 deletions buildcc/lib/target/include/target/api/target_getter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "toolchain/toolchain.h"

#include "target/common/target_state.h"

#include "taskflow/taskflow.hpp"

namespace fs = std::filesystem;
Expand All @@ -32,6 +34,11 @@ namespace buildcc::internal {

template <typename T> class TargetGetter {
public:
// Target State
const TargetState &GetState() const;
bool IsBuilt() const;
bool IsLocked() const;

const std::string &GetName() const;
const Toolchain &GetToolchain() const;
TargetType GetType() const;
Expand Down
15 changes: 1 addition & 14 deletions buildcc/lib/target/include/target/api/target_info_getter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@ namespace buildcc::internal {

// Requires
// - TargetStorer
// - TargetState
// - TargetEnv
// - TargetConfig
template <typename T> class TargetInfoGetter {
public:
// Target State
const TargetState &GetState() const;
bool IsBuilt() const;
bool IsLocked() const;

// Target Env
const fs::path &GetTargetRootDir() const;
const fs::path &GetTargetBuildDir() const;
Expand All @@ -51,14 +45,7 @@ template <typename T> class TargetInfoGetter {
const std::vector<std::string> &GetExternalLibDeps() const;
const fs_unordered_set &GetIncludeDirs() const;
const fs_unordered_set &GetLibDirs() const;
const std::unordered_set<std::string> &GetPreprocessorFlags() const;
const std::unordered_set<std::string> &GetCommonCompileFlags() const;
const std::unordered_set<std::string> &GetPchCompileFlags() const;
const std::unordered_set<std::string> &GetPchObjectFlags() const;
const std::unordered_set<std::string> &GetAsmCompileFlags() const;
const std::unordered_set<std::string> &GetCCompileFlags() const;
const std::unordered_set<std::string> &GetCppCompileFlags() const;
const std::unordered_set<std::string> &GetLinkFlags() const;

const fs_unordered_set &GetCompileDependencies() const;
const fs_unordered_set &GetLinkDependencies() const;
};
Expand Down
1 change: 1 addition & 0 deletions buildcc/lib/target/include/target/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

namespace buildcc {

// TODO, Make this private
struct UserGeneratorSchema : public internal::GeneratorSchema {
fs_unordered_set inputs;
};
Expand Down
12 changes: 5 additions & 7 deletions buildcc/lib/target/include/target/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,20 @@ class Target : public internal::BuilderInterface,
std::string name_;
TargetType type_;
internal::TargetSerialization serialization_;

// Friend classes
internal::CompilePch compile_pch_;
internal::CompileObject compile_object_;
internal::LinkTarget link_target_;

//
TargetState state_;
env::Command command_;
tf::Taskflow tf_;

// Task states
tf::Task target_start_task_;
tf::Task target_end_task_;

std::mutex task_state_mutex_;
env::TaskState task_state_{env::TaskState::SUCCESS};

//
env::Command command_;
tf::Taskflow tf_;
};

typedef Target BaseTarget;
Expand Down
14 changes: 8 additions & 6 deletions buildcc/lib/target/include/target/target_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@

#include "toolchain/toolchain.h"

#include "target/common/function_lock.h"
#include "target/common/target_config.h"
#include "target/common/target_env.h"
#include "target/common/target_state.h"

#include "target/api/deps_api.h"
#include "target/api/flag_api.h"
#include "target/api/include_api.h"
#include "target/api/lib_api.h"
#include "target/api/pch_api.h"
Expand All @@ -39,6 +36,7 @@

namespace buildcc {

// TODO, Make this private
struct UserTargetSchema : public internal::TargetSchema {
fs_unordered_set sources;
fs_unordered_set headers;
Expand All @@ -65,7 +63,9 @@ class TargetInfo : public internal::SourceApi<TargetInfo>,
public:
TargetInfo(const BaseToolchain &toolchain, const TargetEnv &env,
const TargetConfig &config = TargetConfig())
: toolchain_(toolchain), env_(env), config_(config) {}
: toolchain_(toolchain), env_(env), config_(config) {
Initialize();
}

private:
// Inputs
Expand All @@ -87,10 +87,12 @@ class TargetInfo : public internal::SourceApi<TargetInfo>,
TargetEnv env_;
TargetConfig config_;

//
UserTargetSchema user_;

FunctionLock lock_;
TargetState state_;

private:
void Initialize();
};

typedef TargetInfo BaseTargetInfo;
Expand Down
46 changes: 45 additions & 1 deletion buildcc/lib/target/src/api/flag_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#include "target/api/flag_api.h"
#include "toolchain/api/flag_api.h"

#include "target/target_info.h"

Expand Down Expand Up @@ -76,6 +76,50 @@ template <typename T> void FlagApi<T>::AddLinkFlag(const std::string &flag) {
t.user_.link_flags.insert(flag);
}

template <typename T>
const std::unordered_set<std::string> &
FlagApi<T>::GetPreprocessorFlags() const {
const T &t = static_cast<const T &>(*this);
return t.user_.preprocessor_flags;
}
template <typename T>
const std::unordered_set<std::string> &
FlagApi<T>::GetCommonCompileFlags() const {
const T &t = static_cast<const T &>(*this);
return t.user_.common_compile_flags;
}
template <typename T>
const std::unordered_set<std::string> &FlagApi<T>::GetPchCompileFlags() const {
const T &t = static_cast<const T &>(*this);
return t.user_.pch_compile_flags;
}
template <typename T>
const std::unordered_set<std::string> &FlagApi<T>::GetPchObjectFlags() const {
const T &t = static_cast<const T &>(*this);
return t.user_.pch_object_flags;
}
template <typename T>
const std::unordered_set<std::string> &FlagApi<T>::GetAsmCompileFlags() const {
const T &t = static_cast<const T &>(*this);
return t.user_.asm_compile_flags;
}
template <typename T>
const std::unordered_set<std::string> &FlagApi<T>::GetCCompileFlags() const {
const T &t = static_cast<const T &>(*this);
return t.user_.c_compile_flags;
}
template <typename T>
const std::unordered_set<std::string> &FlagApi<T>::GetCppCompileFlags() const {
const T &t = static_cast<const T &>(*this);
return t.user_.cpp_compile_flags;
}
template <typename T>
const std::unordered_set<std::string> &FlagApi<T>::GetLinkFlags() const {
const T &t = static_cast<const T &>(*this);
return t.user_.link_flags;
}

template class FlagApi<TargetInfo>;
template class FlagApi<Toolchain>;

} // namespace buildcc::internal
19 changes: 19 additions & 0 deletions buildcc/lib/target/src/api/target_getter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@

namespace buildcc::internal {

// Target State
template <typename T> const TargetState &TargetGetter<T>::GetState() const {
const T &t = static_cast<const T &>(*this);

return t.state_;
}

template <typename T> bool TargetGetter<T>::IsBuilt() const {
const T &t = static_cast<const T &>(*this);

return t.state_.IsBuilt();
}

template <typename T> bool TargetGetter<T>::IsLocked() const {
const T &t = static_cast<const T &>(*this);

return t.lock_.IsLocked();
}

template <typename T> const fs::path &TargetGetter<T>::GetBinaryPath() const {
const T &t = static_cast<const T &>(*this);

Expand Down
Loading