Skip to content

Commit 4f9b35e

Browse files
zaucyKelwan
andauthored
feat: allow adding cc deps to recipe rule (#65)
Co-authored-by: Kelwan <austin@kelway.ca>
1 parent 342fb1d commit 4f9b35e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
7+
[*.{cc,hh,cpp,hpp}]
8+
# matching .clang-format IndentWidth
9+
indent_size = 2
10+
11+
[*.{bzl,bazel}]
12+
# matches output of buildifier
13+
indent_size = 4
14+
indent_style = space

ecsact/private/ecsact_build_recipe.bzl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,32 @@ def _ecsact_build_recipe(ctx):
6464
})
6565
recipe_data.append(info.plugin)
6666

67+
for cc_dep in ctx.attr.cc_deps:
68+
cc_info = cc_dep[CcInfo]
69+
70+
for hdr in cc_info.compilation_context.headers.to_list():
71+
hdr_prefix = ""
72+
73+
for quote_inc in cc_info.compilation_context.quote_includes.to_list():
74+
if hdr.path.startswith(quote_inc):
75+
hdr_prefix = quote_inc
76+
break
77+
for sys_inc in cc_info.compilation_context.system_includes.to_list():
78+
if hdr.path.startswith(sys_inc):
79+
hdr_prefix = sys_inc
80+
break
81+
82+
if hdr_prefix:
83+
hdr_prefix_base = hdr.path.removeprefix(hdr_prefix)
84+
hdr_prefix_base_idx = hdr_prefix_base.rindex("/")
85+
hdr_prefix_base = hdr_prefix_base[:hdr_prefix_base_idx]
86+
sources.append({
87+
"path": hdr.path,
88+
"outdir": "include" + hdr_prefix_base,
89+
"relative_to_cwd": True,
90+
})
91+
recipe_data.append(hdr)
92+
6793
recipe = {
6894
"name": ctx.attr.name,
6995
"sources": sources,
@@ -89,6 +115,9 @@ ecsact_build_recipe = rule(
89115
"srcs": attr.label_list(
90116
allow_files = True,
91117
),
118+
"cc_deps": attr.label_list(
119+
providers = [CcInfo],
120+
),
92121
"fetch_srcs": attr.string_list_dict(
93122
allow_empty = True,
94123
),

0 commit comments

Comments
 (0)