@@ -31,111 +31,3 @@ ecsact_codegen_plugin = rule(
3131 "plugin" : attr .string (mandatory = True , doc = "Path to plugin or name of builtin plugin." ),
3232 },
3333)
34-
35- def _cc_ecsact_codegen_plugin_impl (ctx ):
36- plugin = None
37- files = ctx .attr .cc_binary [DefaultInfo ].files
38-
39- for file in files .to_list ():
40- if file .extension == "so" :
41- plugin = file
42- if file .extension == "dll" :
43- plugin = file
44-
45- return [
46- EcsactCodegenPluginInfo (
47- output_extension = ctx .attr .output_extension ,
48- plugin = plugin ,
49- data = [plugin ],
50- ),
51- ]
52-
53- _cc_ecsact_codegen_plugin = rule (
54- implementation = _cc_ecsact_codegen_plugin_impl ,
55- attrs = {
56- "cc_binary" : attr .label (mandatory = True ),
57- "output_extension" : attr .string (mandatory = True ),
58- },
59- )
60-
61- _generated_src = """
62- #include "ecsact/codegen_plugin.h"
63-
64- const char* ecsact_codegen_plugin_name() {{
65- return "{output_extension}";
66- }}
67- """
68-
69- def _cc_ecsact_codegen_plugin_src_impl (ctx ):
70- output_cc_src = ctx .actions .declare_file ("plugin_name.cc" .format (ctx .attr .name ))
71- ctx .actions .write (
72- output = output_cc_src ,
73- content = _generated_src .format (output_extension = ctx .attr .output_extension ),
74- )
75-
76- return [
77- DefaultInfo (files = depset ([output_cc_src ])),
78- ]
79-
80- _cc_ecsact_codegen_plugin_src = rule (
81- implementation = _cc_ecsact_codegen_plugin_src_impl ,
82- attrs = {
83- "output_extension" : attr .string (mandatory = True ),
84- },
85- )
86-
87- def cc_ecsact_codegen_plugin (name = None , srcs = [], deps = [], defines = [], no_validate_test = False , output_extension = None , ** kwargs ):
88- """Create ecsact codegen plugin with C++
89-
90- NOTE: ecsact_codegen_plugin_name() is automatically generated for you based
91- on the `output_extension` attribute.
92-
93- Args:
94- name: Passed to underling cc_binary
95- srcs: Passed to underling cc_binary
96- deps: Passed to underling cc_binary
97- defines: Passed to underling cc_binary
98- output_extension: File extension the plugin writes to
99- no_validate_test: Don't create plugin validation test (not recommended)
100- **kwargs: Passed to underling cc_binary
101- """
102- cc_binary (
103- name = "{}_bin" .format (name ),
104- srcs = srcs + [
105- "@ecsact_runtime//dylib:dylib.cc" ,
106- ":{}__pn" .format (name ),
107- ],
108- deps = deps + [
109- "@ecsact_runtime//:dylib" ,
110- "@ecsact_runtime//dylib:meta" ,
111- "@ecsact_runtime//:codegen_plugin" ,
112- "@ecsact_runtime//:codegen_plugin_cc" ,
113- ],
114- defines = defines + ["ECSACT_META_API_LOAD_AT_RUNTIME" ],
115- linkshared = True ,
116- ** kwargs
117- )
118-
119- _cc_ecsact_codegen_plugin_src (
120- name = "{}__pn" .format (name ),
121- output_extension = output_extension ,
122- )
123-
124- _cc_ecsact_codegen_plugin (
125- name = name ,
126- cc_binary = ":{}_bin" .format (name ),
127- output_extension = output_extension ,
128- )
129-
130- if not no_validate_test :
131- cc_test (
132- name = "{}__validate" .format (name ),
133- srcs = ["@ecsact_runtime//:ecsact/codegen/ecsact_codegen_plugin_test.cc" ],
134- args = ["$(rootpath :{}_bin)" .format (name )],
135- data = [":{}_bin" .format (name )],
136- deps = [
137- "@bazel_tools//tools/cpp/runfiles" ,
138- "@ecsact_runtime//:codegen_plugin_validate" ,
139- ],
140- ** kwargs
141- )
0 commit comments