Skip to content

Commit

Permalink
feat: Tracy is now an option, boost regex and remove logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelwan committed Nov 29, 2024
1 parent 2b1bb0d commit 6c7a652
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 57 deletions.
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bazel_dep(name = "docopt.cpp", version = "0.6.2")
bazel_dep(name = "boost.process", version = "1.83.0.bzl.2")
bazel_dep(name = "boost.algorithm", version = "1.83.0.bzl.1")
bazel_dep(name = "boost.url", version = "1.83.0.bzl.2")
bazel_dep(name = "boost.regex", version = "1.83.0.bcr.1")
bazel_dep(name = "yaml-cpp", version = "0.8.0")
bazel_dep(name = "libarchive", version = "3.7.4.bcr.2")
bazel_dep(name = "tracy", version = "0.11.1")
Expand All @@ -38,7 +39,7 @@ git_override(

git_override(
module_name = "tracy",
commit = "9e3ab98805fec8f1fbcfd7747af4117bb984be19",
commit = "b75f30a3823bc290b4d2359234d10ff69855d046",
remote = "[email protected]:seaube/tracy.git",
)

Expand Down
2 changes: 1 addition & 1 deletion ecsact/cli/commands/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ cc_library(
],
)


cc_library(
name = "codegen",
srcs = ["codegen.cc"],
Expand Down Expand Up @@ -94,6 +93,7 @@ cc_library(
"@ecsact_interpret",
"@docopt.cpp//:docopt",
"@magic_enum",
"@boost.regex",
],
)

Expand Down
7 changes: 5 additions & 2 deletions ecsact/cli/commands/build.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ecsact/cli/commands/build.hh"

#include <iostream>
#include <memory>
#include <format>
#include <filesystem>
Expand Down Expand Up @@ -30,7 +31,7 @@ constexpr auto USAGE = R"docopt(Ecsact Build Command
Usage:
ecsact build (-h | --help)
ecsact build <files>... --recipe=<name>... --output=<path> [--allow-unresolved-imports] [--format=<type>] [--temp_dir=<path>] [--compiler_config=<path>] [--report_filter=<filter>] [--debug]
ecsact build <files>... --recipe=<name>... --output=<path> [--allow-unresolved-imports] [--format=<type>] [--temp_dir=<path>] [--compiler_config=<path>] [--report_filter=<filter>] [--debug] [--tracy]
Options:
<files> Ecsact files used to build Ecsact Runtime
Expand All @@ -40,7 +41,8 @@ constexpr auto USAGE = R"docopt(Ecsact Build Command
--compiler_config=<path> Optionally specify the compiler by name or path
-f --format=<type> The format used to report progress of the build [default: text]
--report_filter=<filter> Filtering out report logs [default: none]
--debug Compile with debug symbols
--debug Compile with debug symbols
--tracy Enable the tracy profiler
)docopt";

// TODO(zaucy): Add this documentation to docopt (msvc regex fails)
Expand Down Expand Up @@ -302,6 +304,7 @@ auto ecsact::cli::detail::build_command( //
.work_dir = work_dir,
.output_path = output_path,
.debug = args["--debug"].asBool(),
.tracy = args["--debug"].asBool(),
.additional_plugin_dirs = additional_plugin_dirs,
};
auto runtime_output_path =
Expand Down
86 changes: 42 additions & 44 deletions ecsact/cli/commands/build/recipe/cook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,16 @@ struct compile_options {
fs::path output_path;
std::vector<std::string> imports;
std::vector<std::string> exports;
std::optional<fs::path> tracy_dir;
bool debug;
};

struct tracy_compile_options {
fs::path tracy_dir;
fs::path output_path;
ecsact::cli::cc_compiler compiler;
};

auto clang_gcc_compile(compile_options options) -> int {
const fs::path clang = options.compiler.compiler_path;

Expand Down Expand Up @@ -593,12 +600,7 @@ auto clang_gcc_compile(compile_options options) -> int {
return 0;
}

auto cl_tracy_compile(
compile_options options,
// TODO(Kelwan): Get rid of this, load runfiles sooner with a macro then pass
// in the tracy dir instead of making it here
const char* argv0
) -> int {
auto cl_tracy_compile(tracy_compile_options options) -> int {
struct : ecsact::cli::detail::spawn_reporter {
auto on_std_out(std::string_view line) -> std::optional<message_variant_t> {
if(line.find(": warning") != std::string::npos) {
Expand Down Expand Up @@ -627,24 +629,20 @@ auto cl_tracy_compile(
}
} reporter;

auto tracy_dir = options.work_dir / "third_party" / "tracy";
auto success = ecsact::cli::cook::load_tracy_runfiles(argv0, tracy_dir);

auto cl_args = std::vector<std::string>{};

cl_args.push_back("/DTRACY_ENABLE");
cl_args.push_back("/DTRACY_DELAYED_INIT");
cl_args.push_back("/DTRACY_MANUAL_LIFETIME");
cl_args.push_back("/DTRACY_EXPORTS");

// TODO(Kelwan): Add macro so only added to valid_srcs conditionally
cl_args.push_back("/O2");

for(auto inc_dir : options.compiler.std_inc_paths) {
cl_args.push_back(std::format("/I{}", inc_dir.string()));
}

auto src = fs::path{tracy_dir / "TracyClient.cpp"};
auto src = fs::path{options.tracy_dir / "TracyClient.cpp"};
cl_args.push_back(src.string());

cl_args.push_back("/std:c++20");
Expand All @@ -657,9 +655,6 @@ auto cl_tracy_compile(
}

auto profiler_path = options.output_path.parent_path() / "profiler.dll";
// TODO(Kelwan): Make tracy optional

ecsact::cli::report_info("pre spawn");

cl_args.push_back("/MACHINE:x64"); // TODO(zaucy): configure from triple
cl_args.push_back(std::format("/OUT:{}", profiler_path.string()));
Expand Down Expand Up @@ -731,11 +726,12 @@ auto cl_compile(compile_options options) -> int {
cl_args.push_back("/D_WIN32_WINNT=0x0A00");
cl_args.push_back("/diagnostics:column");
cl_args.push_back("/DECSACT_BUILD");
// TODO(Kelwan): Make tracy conditional
cl_args.push_back("/DTRACY_ENABLE");
cl_args.push_back("/DTRACY_DELAYED_INIT");
cl_args.push_back("/DTRACY_MANUAL_LIFETIME");
cl_args.push_back("/DTRACY_IMPORTS");
if(options.tracy_dir) {
cl_args.push_back("/DTRACY_ENABLE");
cl_args.push_back("/DTRACY_DELAYED_INIT");
cl_args.push_back("/DTRACY_MANUAL_LIFETIME");
cl_args.push_back("/DTRACY_IMPORTS");
}
if(options.debug) {
cl_args.push_back("/DEBUG:FULL");
cl_args.push_back("/MDd");
Expand Down Expand Up @@ -771,9 +767,10 @@ auto cl_compile(compile_options options) -> int {
for(auto inc_dir : options.inc_dirs) {
cl_args.push_back(std::format("/I{}", inc_dir.string()));
}
// TODO(Kelwan): Make Tracy conditional
auto tracy_dir = options.work_dir / "third_party" / "tracy";
cl_args.push_back(std::format("/I{}", tracy_dir.string()));

if(options.tracy_dir) {
cl_args.push_back(std::format("/I{}", options.tracy_dir->string()));
}

auto main_params_file =
create_params_file(long_path_workaround(options.work_dir / "main.params"));
Expand Down Expand Up @@ -871,8 +868,11 @@ auto cl_compile(compile_options options) -> int {
cl_args.push_back("@" + obj_params_file.string());
cl_args.push_back("@" + main_params_file.string());

auto tracy_lib = fs::path{options.output_path.parent_path() / "profiler.lib"};
cl_args.push_back(tracy_lib.string());
if(options.tracy_dir) {
auto tracy_lib =
fs::path{options.output_path.parent_path() / "profiler.lib"};
cl_args.push_back(tracy_lib.string());
}

cl_args.push_back("/link");
if(options.debug) {
Expand Down Expand Up @@ -967,6 +967,7 @@ auto ecsact::cli::cook_recipe( //

auto source_files = std::vector<fs::path>{};

ecsact::cli::report_info("PHASE 1");
{
// No need to add to source_files since it will be grabbed in the directory
// iterator
Expand Down Expand Up @@ -998,30 +999,28 @@ auto ecsact::cli::cook_recipe( //
#else
auto exec_path = ecsact::cli::detail::canon_argv0(argv0);
auto install_prefix = exec_path.parent_path().parent_path();
ecsact::cli::report_info("PHASE 2");

inc_dirs.push_back(install_prefix / "include");
#endif
std::optional<fs::path> tracy_dir;
if(recipe_options.tracy) {
tracy_dir = recipe_options.work_dir / "third_party" / "tracy";
auto success = ecsact::cli::cook::load_tracy_runfiles(argv0, *tracy_dir);
}

if(is_cl_like(compiler.compiler_type)) {
exit_code = cl_tracy_compile(
{
.work_dir = recipe_options.work_dir,
.compiler = compiler,
.inc_dirs = inc_dirs,
.system_libs = as_vec(recipe.system_libs()),
.srcs = source_files,
if(recipe_options.tracy) {
exit_code = cl_tracy_compile({
.tracy_dir = *tracy_dir,
.output_path = output_path,
.imports = as_vec(recipe.imports()),
.exports = as_vec(recipe.exports()),
.debug = recipe_options.debug,
},
argv0
);

if(exit_code != 0) {
return {};
.compiler = compiler,
});
if(exit_code != 0) {
return {};
}
}
ecsact::cli::report_info("TRACY DONE");
ecsact::cli::report_info("PHASE 3");
exit_code = cl_compile({
.work_dir = recipe_options.work_dir,
.compiler = compiler,
Expand All @@ -1031,11 +1030,10 @@ auto ecsact::cli::cook_recipe( //
.output_path = output_path,
.imports = as_vec(recipe.imports()),
.exports = as_vec(recipe.exports()),
.tracy_dir = tracy_dir,
.debug = recipe_options.debug,
});

ecsact::cli::report_info("CL COMPILE DONE");

ecsact::cli::report_info("PHASE 4");
} else {
exit_code = clang_gcc_compile({
.work_dir = recipe_options.work_dir,
Expand Down
1 change: 1 addition & 0 deletions ecsact/cli/commands/build/recipe/cook.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct cook_recipe_options {
std::filesystem::path work_dir;
std::filesystem::path output_path;
bool debug;
bool tracy;

/** Other directories to check for codegen plugins */
std::vector<std::filesystem::path> additional_plugin_dirs;
Expand Down
1 change: 1 addition & 0 deletions ecsact/cli/commands/build/recipe/cook_runfiles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,5 @@ auto ecsact::cli::cook::load_tracy_runfiles(
return false;
}
}
return true;
}
7 changes: 6 additions & 1 deletion ecsact/cli/commands/build/recipe/taste.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,17 @@ static auto check_runtime_info(
fs::path library_path,
const ecsact::build_recipe& recipe
) -> bool {
ecsact::cli::report_info("HELP MEEEEEEEEEEEEEEEEEEEEE");
auto ec = std::error_code{};

auto cookie =
AddDllDirectory(fs::absolute(library_path).parent_path().c_str());

auto profile_lib = boost::dll::shared_library{
((library_path.parent_path() / "profiler.dll").c_str()),
boost::dll::load_mode::default_mode,
ec,
};

auto runtime_lib = boost::dll::shared_library{
library_path.string(),
boost::dll::load_mode::default_mode,
Expand Down
8 changes: 0 additions & 8 deletions ecsact/cli/detail/proc_exec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ auto ecsact::cli::detail::spawn_and_report( //
auto proc_stdout = bp::ipstream{};
auto proc_stderr = bp::ipstream{};

ecsact::cli::report_error("REPORT 1");

auto proc = bp::child{
bp::exe(fs::absolute(exe).string()),
bp::start_dir(start_dir.string()),
Expand All @@ -42,8 +40,6 @@ auto ecsact::cli::detail::spawn_and_report( //
bp::std_err > proc_stderr,
};

ecsact::cli::report_error("REPORT 2");

auto subcommand_id = static_cast<subcommand_id_t>(proc.id());

ecsact::cli::report(subcommand_start_message{
Expand All @@ -62,8 +58,6 @@ auto ecsact::cli::detail::spawn_and_report( //
ecsact::cli::report(msg);
}

ecsact::cli::report_error("REPORT 3");

while(proc_stderr && std::getline(proc_stderr, line)) {
auto msg = reporter.on_std_err(line).value_or(subcommand_stderr_message{
.id = subcommand_id,
Expand All @@ -75,13 +69,11 @@ auto ecsact::cli::detail::spawn_and_report( //
proc.wait();

auto proc_exit_code = proc.exit_code();
ecsact::cli::report_error("REPORT 4");

ecsact::cli::report(subcommand_end_message{
.id = subcommand_id,
.exit_code = proc_exit_code,
});
ecsact::cli::report_error("REPORT 5?");

return proc_exit_code;
}
Expand Down
2 changes: 2 additions & 0 deletions test/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ build [email protected]//:use_std_fs
query [email protected]//:use_std_fs
query [email protected]//:use_std_fs

common [email protected]//:use_boost_regex

build --nocheck_visibility

try-import %workspace%/user.bazelrc
2 changes: 2 additions & 0 deletions test/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ bazel_dep(name = "rules_ecsact", version = "0.5.0")
bazel_dep(name = "ecsact_codegen", version = "0.4.1")
bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2")
bazel_dep(name = "boost.process", version = "1.83.0.bzl.2")
bazel_dep(name = "boost.regex", version = "1.83.0.bcr.1")
bazel_dep(name = "ecsact_runtime", version = "0.7.0")
bazel_dep(name = "docopt.cpp", version = "0.6.2")

bazel_dep(name = "toolchains_llvm", version = "1.0.0", dev_dependency = True)
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
Expand Down
2 changes: 2 additions & 0 deletions test/build_recipe/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ cc_test(
"@googletest//:gtest",
"@googletest//:gtest_main",
],
args = ["--gtest_catch_exceptions=0"],
)

cc_test(
Expand Down Expand Up @@ -122,4 +123,5 @@ cc_test(
"@googletest//:gtest",
"@googletest//:gtest_main",
],
args = ["--gtest_catch_exceptions=0"],
)

0 comments on commit 6c7a652

Please sign in to comment.