@@ -25,6 +25,11 @@ def _rust_stdlib_filegroup_impl(ctx):
2525 between_core_and_std_files = []
2626 std_files = []
2727 alloc_files = []
28+ self_contained_files = [
29+ file
30+ for file in rust_lib
31+ if file .basename .endswith (".o" ) and "self-contained" in file .path
32+ ]
2833
2934 std_rlibs = [f for f in rust_lib if f .basename .endswith (".rlib" )]
3035 if std_rlibs :
@@ -67,6 +72,7 @@ def _rust_stdlib_filegroup_impl(ctx):
6772 between_core_and_std_files = between_core_and_std_files ,
6873 std_files = std_files ,
6974 alloc_files = alloc_files ,
75+ self_contained_files = self_contained_files ,
7076 ),
7177 ]
7278
@@ -115,7 +121,7 @@ def _make_libstd_and_allocator_ccinfo(ctx, rust_lib, allocator_library):
115121 A CcInfo object for the required libraries, or None if no such libraries are available.
116122 """
117123 cc_toolchain , feature_configuration = find_cc_toolchain (ctx )
118- link_inputs = []
124+ cc_infos = []
119125
120126 if not rust_common .stdlib_info in ctx .attr .rust_lib :
121127 fail (dedent ("""\
@@ -126,6 +132,23 @@ def _make_libstd_and_allocator_ccinfo(ctx, rust_lib, allocator_library):
126132 """ ).format (ctx .label , ctx .attr .rust_lib ))
127133 rust_stdlib_info = ctx .attr .rust_lib [rust_common .stdlib_info ]
128134
135+ if rust_stdlib_info .self_contained_files :
136+ compilation_outputs = cc_common .create_compilation_outputs (
137+ objects = depset (rust_stdlib_info .self_contained_files ),
138+ )
139+
140+ linking_context , _linking_outputs = cc_common .create_linking_context_from_compilation_outputs (
141+ name = ctx .label .name ,
142+ actions = ctx .actions ,
143+ feature_configuration = feature_configuration ,
144+ cc_toolchain = cc_toolchain ,
145+ compilation_outputs = compilation_outputs ,
146+ )
147+
148+ cc_infos .append (CcInfo (
149+ linking_context = linking_context ,
150+ ))
151+
129152 if rust_stdlib_info .std_rlibs :
130153 alloc_inputs = depset (
131154 [_ltl (f , ctx , cc_toolchain , feature_configuration ) for f in rust_stdlib_info .alloc_files ],
@@ -151,22 +174,29 @@ def _make_libstd_and_allocator_ccinfo(ctx, rust_lib, allocator_library):
151174 order = "topological" ,
152175 )
153176
154- link_inputs . append ( cc_common .create_linker_input (
177+ link_inputs = cc_common .create_linker_input (
155178 owner = rust_lib .label ,
156179 libraries = std_inputs ,
157- ))
180+ )
158181
159- allocator_inputs = None
160- if allocator_library :
161- allocator_inputs = [allocator_library [CcInfo ].linking_context .linker_inputs ]
182+ allocator_inputs = None
183+ if allocator_library :
184+ allocator_inputs = [allocator_library [CcInfo ].linking_context .linker_inputs ]
185+
186+ cc_infos .append (CcInfo (
187+ linking_context = cc_common .create_linking_context (
188+ linker_inputs = depset (
189+ [link_inputs ],
190+ transitive = allocator_inputs ,
191+ order = "topological" ,
192+ ),
193+ ),
194+ ))
162195
163- libstd_and_allocator_ccinfo = None
164- if link_inputs :
165- return CcInfo (linking_context = cc_common .create_linking_context (linker_inputs = depset (
166- link_inputs ,
167- transitive = allocator_inputs ,
168- order = "topological" ,
169- )))
196+ if cc_infos :
197+ return cc_common .merge_cc_infos (
198+ direct_cc_infos = cc_infos ,
199+ )
170200 return None
171201
172202def _rust_toolchain_impl (ctx ):
0 commit comments