Skip to content

Commit

Permalink
fix: add missing SDK includes (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy committed Oct 12, 2023
1 parent 5f0f7d2 commit ef84dac
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 32 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module(
compatibility_level = 2,
)

bazel_dep(name = "rules_cc", version = "0.0.8")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "nlohmann_json", version = "3.11.2")
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "rules_pkg", version = "0.9.1")
Expand Down
4 changes: 1 addition & 3 deletions ecsact/cli/commands/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ cc_library(
copts = copts,
deps = [
":command",
"//ecsact/cli/detail/executable_path",
"//ecsact/cli/commands/codegen:codegen",
"@magic_enum",
"@docopt.cpp//:docopt",
Expand All @@ -55,7 +54,7 @@ cc_library(
copts = copts,
deps = [
":command",
"//ecsact/cli/detail/executable_path",
"//ecsact/cli/detail:argv0",
"@docopt.cpp//:docopt",
"@nlohmann_json//:json",
],
Expand All @@ -72,7 +71,6 @@ cc_library(
"//ecsact/cli:report_message",
"//ecsact/cli/detail:json_report",
"//ecsact/cli/detail:text_report",
"//ecsact/cli/detail/executable_path",
"//ecsact/cli/commands/build/recipe:taste",
"//ecsact/cli/commands/build/recipe:cook",
"//ecsact/cli/commands/build:cc_compiler",
Expand Down
2 changes: 2 additions & 0 deletions ecsact/cli/commands/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ecsact/interpret/eval.hh"
#include "ecsact/runtime/meta.hh"
#include "ecsact/cli/report.hh"
#include "ecsact/cli/detail/argv0.hh"
#include "ecsact/cli/detail/json_report.hh"
#include "ecsact/cli/detail/text_report.hh"
#include "ecsact/cli/commands/build/recipe/taste.hh"
Expand Down Expand Up @@ -52,6 +53,7 @@ auto ecsact::cli::detail::build_command( //
) -> int {
auto args = docopt::docopt(USAGE, {argv + 1, argv + argc});
auto format = args["--format"].asString();
auto exec_path = canon_argv0(argv[0]);

if(format == "text") {
set_report_handler(text_report{});
Expand Down
4 changes: 3 additions & 1 deletion ecsact/cli/commands/build/build_recipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ static auto parse_sources( //
} else if(path) {
auto src_path = fs::path{path.as<std::string>()};
auto outdir = std::optional<std::string>{};
auto relative_to_cwd = src["relative_to_cwd"].as<bool>();
auto relative_to_cwd = src["relative_to_cwd"] //
? src["relative_to_cwd"].as<bool>()
: false;
if(src["outdir"]) {
outdir = src["outdir"].as<std::string>();
}
Expand Down
1 change: 1 addition & 0 deletions ecsact/cli/commands/build/recipe/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cc_library(
}),
deps = [
"//ecsact/cli:report",
"//ecsact/cli/detail:argv0",
"//ecsact/cli/commands/build:build_recipe",
"//ecsact/cli/commands/build:cc_compiler_config",
"//ecsact/cli/commands/codegen:codegen",
Expand Down
41 changes: 27 additions & 14 deletions ecsact/cli/commands/build/recipe/cook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ecsact/cli/commands/build/cc_compiler_config.hh"
#include "ecsact/cli/commands/codegen/codegen.hh"
#include "ecsact/cli/report.hh"
#include "ecsact/cli/detail/argv0.hh"
#ifndef ECSACT_CLI_USE_SDK_VERSION
# include "tools/cpp/runfiles/runfiles.h"
#endif
Expand Down Expand Up @@ -91,7 +92,7 @@ struct compile_options {
fs::path work_dir;

ecsact::cli::cc_compiler compiler;
fs::path inc_dir;
std::vector<fs::path> inc_dirs;
std::vector<std::string> system_libs;
std::vector<fs::path> srcs;
fs::path output_path;
Expand All @@ -118,10 +119,13 @@ auto clang_gcc_compile(compile_options options) -> int {
compile_proc_args.push_back(std::format("-isystem {}", inc_dir.string()));
}

compile_proc_args.push_back("-isystem");
compile_proc_args.push_back(
fs::relative(options.inc_dir, options.work_dir).generic_string()
);
for(auto inc_dir : options.inc_dirs) {
compile_proc_args.push_back("-isystem");
compile_proc_args.push_back(
fs::relative(inc_dir, options.work_dir).generic_string()
);
}

compile_proc_args.push_back("-isystem"); // TODO(zaucy): why two of these?

#ifdef _WIN32
Expand Down Expand Up @@ -306,7 +310,9 @@ auto cl_compile(compile_options options) -> int {
cl_args.push_back(std::format("/I{}", inc_dir.string()));
}

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

for(auto sys_lib : options.system_libs) {
cl_args.push_back(std::format("/DEFAULTLIB:{}", sys_lib));
Expand Down Expand Up @@ -367,12 +373,12 @@ auto cl_compile(compile_options options) -> int {
}

auto ecsact::cli::cook_recipe( //
[[maybe_unused]] const char* argv0,
std::vector<fs::path> files,
const ecsact::build_recipe& recipe,
cc_compiler compiler,
fs::path work_dir,
fs::path output_path
const char* argv0,
std::vector<fs::path> files,
const ecsact::build_recipe& recipe,
cc_compiler compiler,
fs::path work_dir,
fs::path output_path
) -> std::optional<std::filesystem::path> {
auto exit_code = int{};

Expand Down Expand Up @@ -411,6 +417,8 @@ auto ecsact::cli::cook_recipe( //
auto src_dir = work_dir / "src";
auto inc_dir = work_dir / "include";

auto inc_dirs = std::vector{inc_dir};

auto ec = std::error_code{};
fs::create_directories(inc_dir, ec);
fs::create_directories(src_dir, ec);
Expand Down Expand Up @@ -485,6 +493,11 @@ auto ecsact::cli::cook_recipe( //
return {};
}
}
#else
auto exec_path = ecsact::cli::detail::canon_argv0(argv0);
auto install_prefix = exec_path.parent_path().parent_path();

inc_dirs.push_back(install_prefix / "include");
#endif

auto system_libs = std::vector<std::string>{};
Expand All @@ -496,7 +509,7 @@ auto ecsact::cli::cook_recipe( //
exit_code = cl_compile({
.work_dir = work_dir,
.compiler = compiler,
.inc_dir = inc_dir,
.inc_dirs = inc_dirs,
.system_libs = system_libs,
.srcs = source_files,
.output_path = output_path,
Expand All @@ -505,7 +518,7 @@ auto ecsact::cli::cook_recipe( //
exit_code = clang_gcc_compile({
.work_dir = work_dir,
.compiler = compiler,
.inc_dir = inc_dir,
.inc_dirs = inc_dirs,
.system_libs = system_libs,
.srcs = source_files,
.output_path = output_path,
Expand Down
1 change: 0 additions & 1 deletion ecsact/cli/commands/codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "ecsact/runtime/dylib.h"
#include "ecsact/codegen/plugin.h"
#include "ecsact/codegen/plugin_validate.hh"
#include "ecsact/cli/detail/executable_path/executable_path.hh"
#include "ecsact/cli/commands/codegen/codegen.hh"

namespace fs = std::filesystem;
Expand Down
14 changes: 2 additions & 12 deletions ecsact/cli/commands/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string>
#include "docopt.h"
#include "nlohmann/json.hpp"
#include "ecsact/cli/detail/executable_path/executable_path.hh"
#include "ecsact/cli/detail/argv0.hh"

namespace fs = std::filesystem;

Expand Down Expand Up @@ -46,19 +46,9 @@ constexpr auto CANNOT_FIND_PLUGIN_DIR = R"(

int ecsact::cli::detail::config_command(int argc, char* argv[]) {
using namespace std::string_literals;
using executable_path::executable_path;

auto args = docopt::docopt(USAGE, {argv + 1, argv + argc});
auto exec_path = executable_path();
if(exec_path.empty()) {
exec_path = fs::path{argv[0]};
std::error_code ec;
exec_path = fs::canonical(exec_path, ec);
if(ec) {
exec_path = fs::weakly_canonical(fs::path{argv[0]});
}
}

auto exec_path = canon_argv0(argv[0]);
auto install_prefix = exec_path.parent_path().parent_path();
auto plugin_dir = install_prefix / "share" / "ecsact" / "plugins";
auto output = "{}"_json;
Expand Down
10 changes: 10 additions & 0 deletions ecsact/cli/detail/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ load("//bazel:copts.bzl", "copts")

package(default_visibility = ["//:__subpackages__"])

cc_library(
name = "argv0",
srcs = ["argv0.cc"],
hdrs = ["argv0.hh"],
copts = copts,
deps = [
"//ecsact/cli/detail/executable_path",
],
)

cc_library(
name = "json_report",
copts = copts,
Expand Down
22 changes: 22 additions & 0 deletions ecsact/cli/detail/argv0.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "ecsact/cli/detail/argv0.hh"

#include <filesystem>
#include "ecsact/cli/detail/executable_path/executable_path.hh"

namespace fs = std::filesystem;

auto ecsact::cli::detail::canon_argv0( //
const char* argv0
) -> std::filesystem::path {
auto exec_path = executable_path::executable_path();
if(exec_path.empty()) {
exec_path = fs::path{argv0};
auto ec = std::error_code{};
exec_path = fs::canonical(exec_path, ec);
if(ec) {
exec_path = fs::weakly_canonical(fs::path{argv0});
}
}

return exec_path;
}
7 changes: 7 additions & 0 deletions ecsact/cli/detail/argv0.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <filesystem>

namespace ecsact::cli::detail {
auto canon_argv0(const char* argv0) -> std::filesystem::path;
}

0 comments on commit ef84dac

Please # to comment.