Skip to content

Updated examples #207

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 9 commits into from
Apr 24, 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
22 changes: 21 additions & 1 deletion bootstrap/include/bootstrap/build_buildcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class BuildBuildCC {

public:
BuildBuildCC(const BaseToolchain &toolchain, const TargetEnv &env)
: toolchain_(toolchain), env_(env) {}
: toolchain_(toolchain), env_(env) {
Initialize();
}
BuildBuildCC(const BuildBuildCC &) = delete;

void Setup(const ArgToolchainState &state);
Expand All @@ -73,6 +75,24 @@ class BuildBuildCC {
return storage_.Ref<StaticTarget_generic>(kBuildccLibName);
}

private:
void Initialize();
ExecutableTarget_generic &GetFlatc() {
return storage_.Ref<ExecutableTarget_generic>(kFlatcExeName);
}
BaseGenerator &GetSchemaGen() {
return storage_.Ref<BaseGenerator>(kSchemaGenName);
}
TargetInfo &GetFlatbuffersHo() {
return storage_.Ref<TargetInfo>(kFlatbuffersHoName);
}
TargetInfo &GetCli11Ho() { return storage_.Ref<TargetInfo>(kCli11HoName); }
TargetInfo &GetFmtHo() { return storage_.Ref<TargetInfo>(kFmtHoName); }
TargetInfo &GetSpdlogHo() { return storage_.Ref<TargetInfo>(kSpdlogHoName); }
TargetInfo &GetTaskflowHo() {
return storage_.Ref<TargetInfo>(kTaskflowHoName);
}

private:
const BaseToolchain &toolchain_;
TargetEnv env_;
Expand Down
6 changes: 3 additions & 3 deletions bootstrap/main.buildcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ int main(int argc, char **argv) {
Reg::Call(Args::Clean()).Func(clean_cb);

BaseToolchain toolchain = custom_toolchain_arg.ConstructToolchain();
toolchain.Verify();

BuildBuildCC buildcc(
toolchain, TargetEnv(Project::GetRootDir(), Project::GetBuildDir()));
buildcc.Setup(custom_toolchain_arg.state);
auto &buildcc_lib = buildcc.GetBuildcc();

const auto &buildcc_lib = buildcc.GetBuildcc();
ExecutableTarget_generic buildcc_hybrid_simple_example(
"buildcc_hybrid_simple_example", toolchain, "example/hybrid/simple");
Reg::Toolchain(custom_toolchain_arg.state)
.Func([&]() { toolchain.Verify(); })
.BuildPackage(buildcc)
.Build(hybrid_simple_example_cb, buildcc_hybrid_simple_example,
buildcc_lib)
.Dep(buildcc_hybrid_simple_example, buildcc_lib);
Expand Down
31 changes: 21 additions & 10 deletions bootstrap/src/build_buildcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,52 +189,52 @@ static void global_flags_cb(TargetInfo &global_info,
}
}

void BuildBuildCC::Setup(const ArgToolchainState &state) {
auto &flatc_exe = storage_.Add<ExecutableTarget_generic>(
void BuildBuildCC::Initialize() {
(void)storage_.Add<ExecutableTarget_generic>(
kFlatcExeName, kFlatcExeName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "flatbuffers",
env_.GetTargetBuildDir()));

// Schema
auto &schema_gen = storage_.Add<BaseGenerator>(
(void)storage_.Add<BaseGenerator>(
kSchemaGenName, kSchemaGenName,
TargetEnv(env_.GetTargetRootDir() / "buildcc" / "schema",
env_.GetTargetBuildDir() / toolchain_.GetName()));

// Flatbuffers HO lib
auto &flatbuffers_ho_lib = storage_.Add<TargetInfo>(
(void)storage_.Add<TargetInfo>(
kFlatbuffersHoName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "flatbuffers",
env_.GetTargetBuildDir()));

// CLI11 HO lib
auto &cli11_ho_lib = storage_.Add<TargetInfo>(
(void)storage_.Add<TargetInfo>(
kCli11HoName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "CLI11",
env_.GetTargetBuildDir()));

// fmt HO lib
auto &fmt_ho_lib = storage_.Add<TargetInfo>(
(void)storage_.Add<TargetInfo>(
kFmtHoName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "fmt",
env_.GetTargetBuildDir()));

// spdlog HO lib
auto &spdlog_ho_lib = storage_.Add<TargetInfo>(
(void)storage_.Add<TargetInfo>(
kSpdlogHoName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "spdlog",
env_.GetTargetBuildDir()));

// taskflow HO lib
auto &taskflow_ho_lib = storage_.Add<TargetInfo>(
(void)storage_.Add<TargetInfo>(
kTaskflowHoName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "taskflow",
env_.GetTargetBuildDir()));

// Tiny-process-library lib
// TODO, Make this a generic selection between StaticTarget and
// DynamicTarget
auto &tpl_lib = storage_.Add<StaticTarget_generic>(
(void)storage_.Add<StaticTarget_generic>(
kTplLibName, kTplLibName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "third_party" /
"tiny-process-library",
Expand All @@ -243,10 +243,21 @@ void BuildBuildCC::Setup(const ArgToolchainState &state) {
// BuildCC lib
// TODO, Make this a generic selection between StaticTarget and
// DynamicTarget
auto &buildcc_lib = storage_.Add<StaticTarget_generic>(
(void)storage_.Add<StaticTarget_generic>(
kBuildccLibName, kBuildccLibName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "buildcc", env_.GetTargetBuildDir()));
}

void BuildBuildCC::Setup(const ArgToolchainState &state) {
auto &flatc_exe = GetFlatc();
auto &schema_gen = GetSchemaGen();
auto &flatbuffers_ho_lib = GetFlatbuffersHo();
auto &cli11_ho_lib = GetCli11Ho();
auto &fmt_ho_lib = GetFmtHo();
auto &spdlog_ho_lib = GetSpdlogHo();
auto &taskflow_ho_lib = GetTaskflowHo();
auto &tpl_lib = GetTpl();
auto &buildcc_lib = GetBuildcc();
Reg::Toolchain(state)
.Func(global_flags_cb, flatc_exe, toolchain_)
.Build(build_flatc_exe_cb, flatc_exe)
Expand Down
7 changes: 4 additions & 3 deletions buildcc/lib/args/include/args/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ namespace buildcc {
* @brief Toolchain State used to selectively build and test targets
*/
struct ArgToolchainState {
bool build{false};
bool test{false};
ArgToolchainState(bool b = false, bool t = false) : build(b), test(t) {}
bool build;
bool test;
};

/**
Expand All @@ -47,7 +48,7 @@ struct ArgToolchainState {
* Bundled with Toolchain State
*/
struct ArgToolchain {
ArgToolchain(){};
ArgToolchain() = default;
ArgToolchain(ToolchainId initial_id, const std::string &initial_name,
const ToolchainExecutables &initial_executables)
: id(initial_id), name(initial_name), executables(initial_executables) {}
Expand Down
3 changes: 3 additions & 0 deletions buildcc/lib/args/include/args/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ class Reg::ToolchainInstance {
Params &&...params) {
return BuildInternal(build_cb, target, std::forward<Params>(params)...);
}
template <typename P> ToolchainInstance &BuildPackage(P &package) {
return Func([&]() { package.Setup(condition_); });
}
ToolchainInstance &Dep(const internal::BuilderInterface &target,
const internal::BuilderInterface &dependency);
ToolchainInstance &Test(const std::string &command, const BaseTarget &target,
Expand Down
2 changes: 2 additions & 0 deletions buildcc/lib/env/include/env/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class ScopedStorage {
template <typename T> void Remove(T *ptr) { delete ptr; }

template <typename T> const T &ConstRef(const std::string &identifier) const {
env::assert_fatal(ptrs_.find(identifier) != ptrs_.end(),
fmt::format("Could not find '{}'", identifier));
const PtrMetadata &metadata = ptrs_.at(identifier);
env::assert_fatal(
typeid(T).name() == metadata.typeid_name,
Expand Down
3 changes: 2 additions & 1 deletion buildexe/buildexe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ int main(int argc, char **argv) {

// Build Target
BuildEnvSetup build_setup(toolchain, buildexe_args);
build_setup.ConstructTarget();
Reg::Toolchain(ArgToolchainState(true)).BuildPackage(build_setup);
Reg::Run();

// Run Target if script mode
if (buildexe_args.GetBuildMode() == BuildExeMode::Script) {
Expand Down
6 changes: 2 additions & 4 deletions buildexe/include/buildexe/build_env_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ class BuildEnvSetup {
public:
BuildEnvSetup(const BaseToolchain &toolchain,
const BuildExeArgs &buildexe_args)
: toolchain_(toolchain), buildexe_args_(buildexe_args) {
state_.build = true;
}
: toolchain_(toolchain), buildexe_args_(buildexe_args) {}

void ConstructTarget();
void Setup(const ArgToolchainState &state);

void RunUserTarget(const ArgScriptInfo &arg_script_info);

Expand Down
4 changes: 2 additions & 2 deletions buildexe/src/build_env_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ namespace buildcc {

constexpr const char *const kTag = "BuildExe";

void BuildEnvSetup::ConstructTarget() {
void BuildEnvSetup::Setup(const ArgToolchainState &state) {
state_ = state;
if (buildexe_args_.GetBuildMode() == BuildExeMode::Script) {
// buildcc and user target
ConstructUserTargetWithBuildcc();
} else {
// user target
ConstructUserTarget();
}
Reg::Run();
}

void BuildEnvSetup::RunUserTarget(const ArgScriptInfo &arg_script_info) {
Expand Down
1 change: 0 additions & 1 deletion docs/source/arch/cmake_boilerplate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ We can then ``add_subdirectory`` that particular folder. This helps us keep our
src/assert_fatal.cpp
src/logging.cpp
include/env/assert_fatal.h
include/env/assert_throw.h
include/env/env.h
include/env/logging.h
include/env/util.h
Expand Down
13 changes: 0 additions & 13 deletions docs/source/user_api/environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@ assert_fatal.h

.. doxygendefine:: ASSERT_FATAL

assert_throw.h
--------------

.. doxygenfunction:: assert_throw([[maybe_unused]] const char *)

.. doxygenfunction:: assert_throw(const std::string &)

.. doxygenfunction:: assert_throw(bool, const char *)

.. doxygenfunction:: assert_throw(bool, const std::string &)

.. doxygendefine:: ASSERT_THROW

command.h
---------

Expand Down
38 changes: 24 additions & 14 deletions example/hybrid/external_lib/build.main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,45 @@
using namespace buildcc;

static void clean_cb();
static void foolib_build_cb(BaseTarget &target);
static void foolib_build_cb(BaseTarget &target, const TargetInfo &foolib);

constexpr const char *const EXE = "build";

int main(int argc, char **argv) {
// 1. Get arguments
// Get arguments
ArgToolchain arg_gcc;
ArgToolchain arg_msvc;
Args::Init()
.AddToolchain("gcc", "Generic gcc toolchain", arg_gcc)
.AddToolchain("msvc", "Generic msvc toolchain", arg_msvc)
.Parse(argc, argv);

// 2. Initialize your environment
// Initialize your environment
Reg::Init();

// 3. Pre-build steps
// Pre-build steps
Reg::Call(Args::Clean()).Func(clean_cb);

// 4. Build steps
// Build steps
Toolchain_gcc gcc;
ExecutableTarget_gcc g_foolib("cppflags", gcc, "");
Reg::Toolchain(arg_gcc.state).Build(foolib_build_cb, g_foolib);
TargetInfo g_foo(gcc, "../foolib");
ExecutableTarget_gcc g_external("cppflags", gcc, "");
Reg::Toolchain(arg_gcc.state)
.Func(fooTarget, g_foo)
.Build(foolib_build_cb, g_external, g_foo);

Toolchain_msvc msvc;
ExecutableTarget_msvc m_foolib("cppflags", msvc, "");
Reg::Toolchain(arg_msvc.state).Build(foolib_build_cb, m_foolib);
ExecutableTarget_msvc m_external("cppflags", msvc, "");
TargetInfo m_foo(gcc, "../foolib");
Reg::Toolchain(arg_msvc.state)
.Func(fooTarget, m_foo)
.Build(foolib_build_cb, m_external, m_foo);

// 5.
//
Reg::Run();

// 6.
plugin::ClangCompileCommands({&g_foolib, &m_foolib}).Generate();
//
plugin::ClangCompileCommands({&g_external, &m_external}).Generate();

return 0;
}
Expand All @@ -47,8 +53,12 @@ static void clean_cb() {
fs::remove_all(Project::GetBuildDir());
}

static void foolib_build_cb(BaseTarget &target) {
fooTarget(target, "../foolib");
static void foolib_build_cb(BaseTarget &target, const TargetInfo &foolib) {
target.AddSource("main.cpp");
target.Insert(foolib, {
SyncOption::SourceFiles,
SyncOption::HeaderFiles,
SyncOption::IncludeDirs,
});
target.Build();
}
6 changes: 3 additions & 3 deletions example/hybrid/foolib/build.foo.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "build.foo.h"

void fooTarget(buildcc::BaseTarget &target, const fs::path &relative_path) {
target.AddSource(relative_path / "src/foo.cpp");
target.AddIncludeDir(relative_path / "src", true);
void fooTarget(buildcc::TargetInfo &target) {
target.AddSource("src/foo.cpp");
target.AddIncludeDir("src", true);
}
2 changes: 1 addition & 1 deletion example/hybrid/foolib/build.foo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#include "buildcc.h"

void fooTarget(buildcc::BaseTarget &target, const fs::path &relative_path);
void fooTarget(buildcc::TargetInfo &target);
Loading