Skip to content

Commit ef84dac

Browse files
authored
fix: add missing SDK includes (#49)
1 parent 5f0f7d2 commit ef84dac

File tree

11 files changed

+76
-32
lines changed

11 files changed

+76
-32
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module(
44
compatibility_level = 2,
55
)
66

7-
bazel_dep(name = "rules_cc", version = "0.0.8")
7+
bazel_dep(name = "rules_cc", version = "0.0.9")
88
bazel_dep(name = "nlohmann_json", version = "3.11.2")
99
bazel_dep(name = "platforms", version = "0.0.7")
1010
bazel_dep(name = "rules_pkg", version = "0.9.1")

ecsact/cli/commands/BUILD.bazel

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ cc_library(
3535
copts = copts,
3636
deps = [
3737
":command",
38-
"//ecsact/cli/detail/executable_path",
3938
"//ecsact/cli/commands/codegen:codegen",
4039
"@magic_enum",
4140
"@docopt.cpp//:docopt",
@@ -55,7 +54,7 @@ cc_library(
5554
copts = copts,
5655
deps = [
5756
":command",
58-
"//ecsact/cli/detail/executable_path",
57+
"//ecsact/cli/detail:argv0",
5958
"@docopt.cpp//:docopt",
6059
"@nlohmann_json//:json",
6160
],
@@ -72,7 +71,6 @@ cc_library(
7271
"//ecsact/cli:report_message",
7372
"//ecsact/cli/detail:json_report",
7473
"//ecsact/cli/detail:text_report",
75-
"//ecsact/cli/detail/executable_path",
7674
"//ecsact/cli/commands/build/recipe:taste",
7775
"//ecsact/cli/commands/build/recipe:cook",
7876
"//ecsact/cli/commands/build:cc_compiler",

ecsact/cli/commands/build.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "ecsact/interpret/eval.hh"
1313
#include "ecsact/runtime/meta.hh"
1414
#include "ecsact/cli/report.hh"
15+
#include "ecsact/cli/detail/argv0.hh"
1516
#include "ecsact/cli/detail/json_report.hh"
1617
#include "ecsact/cli/detail/text_report.hh"
1718
#include "ecsact/cli/commands/build/recipe/taste.hh"
@@ -52,6 +53,7 @@ auto ecsact::cli::detail::build_command( //
5253
) -> int {
5354
auto args = docopt::docopt(USAGE, {argv + 1, argv + argc});
5455
auto format = args["--format"].asString();
56+
auto exec_path = canon_argv0(argv[0]);
5557

5658
if(format == "text") {
5759
set_report_handler(text_report{});

ecsact/cli/commands/build/build_recipe.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ static auto parse_sources( //
109109
} else if(path) {
110110
auto src_path = fs::path{path.as<std::string>()};
111111
auto outdir = std::optional<std::string>{};
112-
auto relative_to_cwd = src["relative_to_cwd"].as<bool>();
112+
auto relative_to_cwd = src["relative_to_cwd"] //
113+
? src["relative_to_cwd"].as<bool>()
114+
: false;
113115
if(src["outdir"]) {
114116
outdir = src["outdir"].as<std::string>();
115117
}

ecsact/cli/commands/build/recipe/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ cc_library(
2626
}),
2727
deps = [
2828
"//ecsact/cli:report",
29+
"//ecsact/cli/detail:argv0",
2930
"//ecsact/cli/commands/build:build_recipe",
3031
"//ecsact/cli/commands/build:cc_compiler_config",
3132
"//ecsact/cli/commands/codegen:codegen",

ecsact/cli/commands/build/recipe/cook.cc

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "ecsact/cli/commands/build/cc_compiler_config.hh"
88
#include "ecsact/cli/commands/codegen/codegen.hh"
99
#include "ecsact/cli/report.hh"
10+
#include "ecsact/cli/detail/argv0.hh"
1011
#ifndef ECSACT_CLI_USE_SDK_VERSION
1112
# include "tools/cpp/runfiles/runfiles.h"
1213
#endif
@@ -91,7 +92,7 @@ struct compile_options {
9192
fs::path work_dir;
9293

9394
ecsact::cli::cc_compiler compiler;
94-
fs::path inc_dir;
95+
std::vector<fs::path> inc_dirs;
9596
std::vector<std::string> system_libs;
9697
std::vector<fs::path> srcs;
9798
fs::path output_path;
@@ -118,10 +119,13 @@ auto clang_gcc_compile(compile_options options) -> int {
118119
compile_proc_args.push_back(std::format("-isystem {}", inc_dir.string()));
119120
}
120121

121-
compile_proc_args.push_back("-isystem");
122-
compile_proc_args.push_back(
123-
fs::relative(options.inc_dir, options.work_dir).generic_string()
124-
);
122+
for(auto inc_dir : options.inc_dirs) {
123+
compile_proc_args.push_back("-isystem");
124+
compile_proc_args.push_back(
125+
fs::relative(inc_dir, options.work_dir).generic_string()
126+
);
127+
}
128+
125129
compile_proc_args.push_back("-isystem"); // TODO(zaucy): why two of these?
126130

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

309-
cl_args.push_back(std::format("/I{}", options.inc_dir.string()));
313+
for(auto inc_dir : options.inc_dirs) {
314+
cl_args.push_back(std::format("/I{}", inc_dir.string()));
315+
}
310316

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

369375
auto ecsact::cli::cook_recipe( //
370-
[[maybe_unused]] const char* argv0,
371-
std::vector<fs::path> files,
372-
const ecsact::build_recipe& recipe,
373-
cc_compiler compiler,
374-
fs::path work_dir,
375-
fs::path output_path
376+
const char* argv0,
377+
std::vector<fs::path> files,
378+
const ecsact::build_recipe& recipe,
379+
cc_compiler compiler,
380+
fs::path work_dir,
381+
fs::path output_path
376382
) -> std::optional<std::filesystem::path> {
377383
auto exit_code = int{};
378384

@@ -411,6 +417,8 @@ auto ecsact::cli::cook_recipe( //
411417
auto src_dir = work_dir / "src";
412418
auto inc_dir = work_dir / "include";
413419

420+
auto inc_dirs = std::vector{inc_dir};
421+
414422
auto ec = std::error_code{};
415423
fs::create_directories(inc_dir, ec);
416424
fs::create_directories(src_dir, ec);
@@ -485,6 +493,11 @@ auto ecsact::cli::cook_recipe( //
485493
return {};
486494
}
487495
}
496+
#else
497+
auto exec_path = ecsact::cli::detail::canon_argv0(argv0);
498+
auto install_prefix = exec_path.parent_path().parent_path();
499+
500+
inc_dirs.push_back(install_prefix / "include");
488501
#endif
489502

490503
auto system_libs = std::vector<std::string>{};
@@ -496,7 +509,7 @@ auto ecsact::cli::cook_recipe( //
496509
exit_code = cl_compile({
497510
.work_dir = work_dir,
498511
.compiler = compiler,
499-
.inc_dir = inc_dir,
512+
.inc_dirs = inc_dirs,
500513
.system_libs = system_libs,
501514
.srcs = source_files,
502515
.output_path = output_path,
@@ -505,7 +518,7 @@ auto ecsact::cli::cook_recipe( //
505518
exit_code = clang_gcc_compile({
506519
.work_dir = work_dir,
507520
.compiler = compiler,
508-
.inc_dir = inc_dir,
521+
.inc_dirs = inc_dirs,
509522
.system_libs = system_libs,
510523
.srcs = source_files,
511524
.output_path = output_path,

ecsact/cli/commands/codegen.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "ecsact/runtime/dylib.h"
1616
#include "ecsact/codegen/plugin.h"
1717
#include "ecsact/codegen/plugin_validate.hh"
18-
#include "ecsact/cli/detail/executable_path/executable_path.hh"
1918
#include "ecsact/cli/commands/codegen/codegen.hh"
2019

2120
namespace fs = std::filesystem;

ecsact/cli/commands/config.cc

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <string>
77
#include "docopt.h"
88
#include "nlohmann/json.hpp"
9-
#include "ecsact/cli/detail/executable_path/executable_path.hh"
9+
#include "ecsact/cli/detail/argv0.hh"
1010

1111
namespace fs = std::filesystem;
1212

@@ -46,19 +46,9 @@ constexpr auto CANNOT_FIND_PLUGIN_DIR = R"(
4646

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

5150
auto args = docopt::docopt(USAGE, {argv + 1, argv + argc});
52-
auto exec_path = executable_path();
53-
if(exec_path.empty()) {
54-
exec_path = fs::path{argv[0]};
55-
std::error_code ec;
56-
exec_path = fs::canonical(exec_path, ec);
57-
if(ec) {
58-
exec_path = fs::weakly_canonical(fs::path{argv[0]});
59-
}
60-
}
61-
51+
auto exec_path = canon_argv0(argv[0]);
6252
auto install_prefix = exec_path.parent_path().parent_path();
6353
auto plugin_dir = install_prefix / "share" / "ecsact" / "plugins";
6454
auto output = "{}"_json;

ecsact/cli/detail/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ load("//bazel:copts.bzl", "copts")
33

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

6+
cc_library(
7+
name = "argv0",
8+
srcs = ["argv0.cc"],
9+
hdrs = ["argv0.hh"],
10+
copts = copts,
11+
deps = [
12+
"//ecsact/cli/detail/executable_path",
13+
],
14+
)
15+
616
cc_library(
717
name = "json_report",
818
copts = copts,

ecsact/cli/detail/argv0.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "ecsact/cli/detail/argv0.hh"
2+
3+
#include <filesystem>
4+
#include "ecsact/cli/detail/executable_path/executable_path.hh"
5+
6+
namespace fs = std::filesystem;
7+
8+
auto ecsact::cli::detail::canon_argv0( //
9+
const char* argv0
10+
) -> std::filesystem::path {
11+
auto exec_path = executable_path::executable_path();
12+
if(exec_path.empty()) {
13+
exec_path = fs::path{argv0};
14+
auto ec = std::error_code{};
15+
exec_path = fs::canonical(exec_path, ec);
16+
if(ec) {
17+
exec_path = fs::weakly_canonical(fs::path{argv0});
18+
}
19+
}
20+
21+
return exec_path;
22+
}

ecsact/cli/detail/argv0.hh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#include <filesystem>
4+
5+
namespace ecsact::cli::detail {
6+
auto canon_argv0(const char* argv0) -> std::filesystem::path;
7+
}

0 commit comments

Comments
 (0)