@@ -4,6 +4,12 @@ load("//ecsact/private:ecsact_build_recipe.bzl", "EcsactBuildRecipeInfo")
44
55def _ecsact_binary_impl (ctx ):
66 cc_toolchain = find_cc_toolchain (ctx )
7+ feature_configuration = cc_common .configure_features (
8+ ctx = ctx ,
9+ cc_toolchain = cc_toolchain ,
10+ requested_features = ctx .features ,
11+ unsupported_features = ctx .disabled_features ,
12+ )
713
814 temp_dir = ctx .actions .declare_directory ("{}.ecsact_binary" .format (ctx .attr .name ))
915
@@ -27,11 +33,16 @@ def _ecsact_binary_impl(ctx):
2733
2834 ecsact_toolchain = ctx .toolchains ["//ecsact:toolchain_type" ].ecsact_info
2935
30- preferred_output_extension = ctx .attr .lib_extension
36+ preferred_output_extension = ctx .attr .shared_library_extension
3137
3238 runtime_output_file = ctx .actions .declare_file ("{}{}" .format (ctx .attr .name , preferred_output_extension ))
33- outputs = [runtime_output_file ]
39+ interface_output_file = None
40+ if ctx .attr .interface_library_extension :
41+ interface_output_file = ctx .actions .declare_file ("{}{}" .format (ctx .attr .name , ctx .attr .interface_library_extension ))
3442 tools = [] + ecsact_toolchain .tool_files
43+ outputs = [runtime_output_file ]
44+ if interface_output_file != None :
45+ outputs .append (interface_output_file )
3546
3647 args = ctx .actions .args ()
3748 args .add ("build" )
@@ -89,7 +100,29 @@ def _ecsact_binary_impl(ctx):
89100 toolchain = Label ("//ecsact:toolchain_type" ),
90101 )
91102
103+ library_to_link = cc_common .create_library_to_link (
104+ actions = ctx .actions ,
105+ feature_configuration = feature_configuration ,
106+ cc_toolchain = cc_toolchain ,
107+ static_library = None ,
108+ pic_static_library = None ,
109+ interface_library = interface_output_file ,
110+ dynamic_library = runtime_output_file ,
111+ alwayslink = False ,
112+ )
113+
114+ linker_input = cc_common .create_linker_input (
115+ libraries = depset ([library_to_link ]),
116+ user_link_flags = depset (ctx .attr .linkopts ),
117+ owner = ctx .label ,
118+ )
119+
120+ linking_context = cc_common .create_linking_context (
121+ linker_inputs = depset ([linker_input ]),
122+ )
123+
92124 return [
125+ CcInfo (linking_context = linking_context ),
93126 DefaultInfo (
94127 files = depset (outputs ),
95128 ),
@@ -111,22 +144,35 @@ _ecsact_binary = rule(
111144 "@rules_cc//cc:current_cc_toolchain" ,
112145 ),
113146 ),
114- "lib_extension " : attr .string (
147+ "shared_library_extension " : attr .string (
115148 mandatory = True ,
116149 ),
150+ "interface_library_extension" : attr .string (
151+ mandatory = True ,
152+ ),
153+ "linkopts" : attr .string_list (
154+ mandatory = False ,
155+ ),
117156 },
118157 toolchains = ["//ecsact:toolchain_type" ] + use_cc_toolchain (),
119158 fragments = ["cpp" ],
120159)
121160
122161def ecsact_binary (** kwargs ):
123162 _ecsact_binary (
124- lib_extension = select ({
163+ shared_library_extension = select ({
125164 "@platforms//os:windows" : ".dll" ,
126165 "@platforms//os:linux" : ".so" ,
127166 "@platforms//os:macos" : ".dylib" ,
128167 "@platforms//os:wasi" : ".wasm" ,
129168 "@platforms//os:none" : ".wasm" , # for non-wasi
130169 }),
170+ interface_library_extension = select ({
171+ "@platforms//os:windows" : ".lib" ,
172+ "@platforms//os:linux" : "" ,
173+ "@platforms//os:macos" : "" ,
174+ "@platforms//os:wasi" : "" ,
175+ "@platforms//os:none" : "" , # for non-wasi
176+ }),
131177 ** kwargs
132178 )
0 commit comments