@@ -25,6 +25,11 @@ def _rust_stdlib_filegroup_impl(ctx):
25
25
between_core_and_std_files = []
26
26
std_files = []
27
27
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
+ ]
28
33
29
34
std_rlibs = [f for f in rust_lib if f .basename .endswith (".rlib" )]
30
35
if std_rlibs :
@@ -67,6 +72,7 @@ def _rust_stdlib_filegroup_impl(ctx):
67
72
between_core_and_std_files = between_core_and_std_files ,
68
73
std_files = std_files ,
69
74
alloc_files = alloc_files ,
75
+ self_contained_files = self_contained_files ,
70
76
),
71
77
]
72
78
@@ -115,7 +121,7 @@ def _make_libstd_and_allocator_ccinfo(ctx, rust_lib, allocator_library):
115
121
A CcInfo object for the required libraries, or None if no such libraries are available.
116
122
"""
117
123
cc_toolchain , feature_configuration = find_cc_toolchain (ctx )
118
- link_inputs = []
124
+ cc_infos = []
119
125
120
126
if not rust_common .stdlib_info in ctx .attr .rust_lib :
121
127
fail (dedent ("""\
@@ -126,6 +132,23 @@ def _make_libstd_and_allocator_ccinfo(ctx, rust_lib, allocator_library):
126
132
""" ).format (ctx .label , ctx .attr .rust_lib ))
127
133
rust_stdlib_info = ctx .attr .rust_lib [rust_common .stdlib_info ]
128
134
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
+
129
152
if rust_stdlib_info .std_rlibs :
130
153
alloc_inputs = depset (
131
154
[_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):
151
174
order = "topological" ,
152
175
)
153
176
154
- link_inputs . append ( cc_common .create_linker_input (
177
+ link_inputs = cc_common .create_linker_input (
155
178
owner = rust_lib .label ,
156
179
libraries = std_inputs ,
157
- ))
180
+ )
158
181
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
+ ))
162
195
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
+ )
170
200
return None
171
201
172
202
def _rust_toolchain_impl (ctx ):
0 commit comments