From 526684ee7bd0ebc957bd907b7b4ef90aea218769 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Thu, 12 Sep 2024 12:33:19 -0700 Subject: [PATCH 1/2] feat: allow adding cc deps to recipe rule --- .editorconfig | 14 +++++++++++ ecsact/private/ecsact_build_recipe.bzl | 32 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a5bbb0b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true + +[*.{cc,hh,cpp,hpp}] +# matching .clang-format IndentWidth +indent_size = 2 + +[*.{bzl,bazel}] +# matches output of buildifier +indent_size = 4 +indent_style = space diff --git a/ecsact/private/ecsact_build_recipe.bzl b/ecsact/private/ecsact_build_recipe.bzl index 5c2cdd0..02d1ff5 100644 --- a/ecsact/private/ecsact_build_recipe.bzl +++ b/ecsact/private/ecsact_build_recipe.bzl @@ -64,6 +64,35 @@ def _ecsact_build_recipe(ctx): }) recipe_data.append(info.plugin) + for cc_dep in ctx.attr.cc_deps: + cc_info = cc_dep[CcInfo] + for hdr in cc_info.compilation_context.direct_headers: + hdr_prefix = "" + + for quote_inc in cc_info.compilation_context.quote_includes.to_list(): + if hdr.path.startswith(quote_inc): + hdr_prefix = quote_inc + break + for sys_inc in cc_info.compilation_context.system_includes.to_list(): + if hdr.path.startswith(sys_inc): + hdr_prefix = sys_inc + break + + if hdr.path.endswith("channel_send_functions.hpp"): + print(hdr.path) + print(hdr_prefix) + + if hdr_prefix: + hdr_prefix_base = hdr.path.removeprefix(hdr_prefix) + hdr_prefix_base_idx = hdr_prefix_base.rindex("/") + hdr_prefix_base = hdr_prefix_base[:hdr_prefix_base_idx] + sources.append({ + "path": hdr.path, + "outdir": "include" + hdr_prefix_base, + "relative_to_cwd": True, + }) + recipe_data.append(hdr) + recipe = { "name": ctx.attr.name, "sources": sources, @@ -89,6 +118,9 @@ ecsact_build_recipe = rule( "srcs": attr.label_list( allow_files = True, ), + "cc_deps": attr.label_list( + providers = [CcInfo], + ), "fetch_srcs": attr.string_list_dict( allow_empty = True, ), From 482f8bf3682e676b4697f0925c6e4bd6bdba62d3 Mon Sep 17 00:00:00 2001 From: Kelwan Date: Fri, 13 Sep 2024 13:06:09 -0700 Subject: [PATCH 2/2] feat: use all headers instead of just direct headers --- ecsact/private/ecsact_build_recipe.bzl | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ecsact/private/ecsact_build_recipe.bzl b/ecsact/private/ecsact_build_recipe.bzl index 02d1ff5..0fb84c8 100644 --- a/ecsact/private/ecsact_build_recipe.bzl +++ b/ecsact/private/ecsact_build_recipe.bzl @@ -66,7 +66,8 @@ def _ecsact_build_recipe(ctx): for cc_dep in ctx.attr.cc_deps: cc_info = cc_dep[CcInfo] - for hdr in cc_info.compilation_context.direct_headers: + + for hdr in cc_info.compilation_context.headers.to_list(): hdr_prefix = "" for quote_inc in cc_info.compilation_context.quote_includes.to_list(): @@ -78,10 +79,6 @@ def _ecsact_build_recipe(ctx): hdr_prefix = sys_inc break - if hdr.path.endswith("channel_send_functions.hpp"): - print(hdr.path) - print(hdr_prefix) - if hdr_prefix: hdr_prefix_base = hdr.path.removeprefix(hdr_prefix) hdr_prefix_base_idx = hdr_prefix_base.rindex("/")