@@ -11,6 +11,11 @@ def _rust_stdlib_filegroup_impl(ctx):
1111 between_core_and_std_files = []
1212 std_files = []
1313 alloc_files = []
14+ self_contained_files = [
15+ file
16+ for file in rust_lib
17+ if file .basename .endswith (".o" ) and "self-contained" in file .path
18+ ]
1419
1520 std_rlibs = [f for f in rust_lib if f .basename .endswith (".rlib" )]
1621 if std_rlibs :
@@ -53,6 +58,7 @@ def _rust_stdlib_filegroup_impl(ctx):
5358 between_core_and_std_files = between_core_and_std_files ,
5459 std_files = std_files ,
5560 alloc_files = alloc_files ,
61+ self_contained_files = self_contained_files ,
5662 ),
5763 ]
5864
@@ -101,7 +107,7 @@ def _make_libstd_and_allocator_ccinfo(ctx, rust_lib, allocator_library):
101107 A CcInfo object for the required libraries, or None if no such libraries are available.
102108 """
103109 cc_toolchain , feature_configuration = find_cc_toolchain (ctx )
104- link_inputs = []
110+ cc_infos = []
105111
106112 if not rust_common .stdlib_info in ctx .attr .rust_lib :
107113 fail (dedent ("""\
@@ -112,6 +118,23 @@ def _make_libstd_and_allocator_ccinfo(ctx, rust_lib, allocator_library):
112118 """ ).format (ctx .label , ctx .attr .rust_lib ))
113119 rust_stdlib_info = ctx .attr .rust_lib [rust_common .stdlib_info ]
114120
121+ if rust_stdlib_info .self_contained_files :
122+ compilation_outputs = cc_common .create_compilation_outputs (
123+ objects = depset (rust_stdlib_info .self_contained_files ),
124+ )
125+
126+ linking_context , _linking_outputs = cc_common .create_linking_context_from_compilation_outputs (
127+ name = ctx .label .name ,
128+ actions = ctx .actions ,
129+ feature_configuration = feature_configuration ,
130+ cc_toolchain = cc_toolchain ,
131+ compilation_outputs = compilation_outputs ,
132+ )
133+
134+ cc_infos .append (CcInfo (
135+ linking_context = linking_context ,
136+ ))
137+
115138 if rust_stdlib_info .std_rlibs :
116139 alloc_inputs = depset (
117140 [_ltl (f , ctx , cc_toolchain , feature_configuration ) for f in rust_stdlib_info .alloc_files ],
@@ -160,22 +183,29 @@ def _make_libstd_and_allocator_ccinfo(ctx, rust_lib, allocator_library):
160183 order = "topological" ,
161184 )
162185
163- link_inputs . append ( cc_common .create_linker_input (
186+ link_inputs = cc_common .create_linker_input (
164187 owner = rust_lib .label ,
165188 libraries = std_inputs ,
166- ))
189+ )
167190
168- allocator_inputs = None
169- if allocator_library :
170- allocator_inputs = [allocator_library [CcInfo ].linking_context .linker_inputs ]
191+ allocator_inputs = None
192+ if allocator_library :
193+ allocator_inputs = [allocator_library [CcInfo ].linking_context .linker_inputs ]
194+
195+ cc_infos .append (CcInfo (
196+ linking_context = cc_common .create_linking_context (
197+ linker_inputs = depset (
198+ [link_inputs ],
199+ transitive = allocator_inputs ,
200+ order = "topological" ,
201+ ),
202+ ),
203+ ))
171204
172- libstd_and_allocator_ccinfo = None
173- if link_inputs :
174- return CcInfo (linking_context = cc_common .create_linking_context (linker_inputs = depset (
175- link_inputs ,
176- transitive = allocator_inputs ,
177- order = "topological" ,
178- )))
205+ if cc_infos :
206+ return cc_common .merge_cc_infos (
207+ direct_cc_infos = cc_infos ,
208+ )
179209 return None
180210
181211def _rust_toolchain_impl (ctx ):
0 commit comments