Skip to content

Commit 375c90d

Browse files
committed
Revert "Migrate to the modern Starlark linker input API. (#512)"
This reverts commit aff1754.
1 parent 8141f74 commit 375c90d

11 files changed

+76
-100
lines changed

swift/internal/linking.bzl

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,17 @@ def _register_static_library_link_action(
9595
)
9696

9797
def register_libraries_to_link(
98-
owning_label,
9998
actions,
10099
alwayslink,
101100
cc_feature_configuration,
102101
is_dynamic,
103102
is_static,
104103
library_name,
105104
objects,
106-
swift_toolchain,
107-
user_link_flags,
108-
additional_inputs):
105+
swift_toolchain):
109106
"""Declares the requested libraries and registers actions to link them.
110107
111108
Args:
112-
owning_label: Label executing rule (i.e., ctx.label).
113109
actions: The object used to register actions.
114110
alwayslink: If True, create a static library that should be
115111
always-linked (having a `.lo` extension instead of `.a`). This
@@ -124,11 +120,9 @@ def register_libraries_to_link(
124120
linked.
125121
swift_toolchain: The Swift toolchain provider to use when constructing
126122
the action.
127-
user_link_flags: Extra link flags to be passed with the library.
128-
additional_inputs: Extra inputs for a link action involving the library.
129123
130124
Returns:
131-
A `LinkerInput` object containing the libraries that were created.
125+
A `LibraryToLink` object containing the libraries that were created.
132126
"""
133127
dynamic_library = None
134128
if is_dynamic:
@@ -151,24 +145,16 @@ def register_libraries_to_link(
151145
else:
152146
static_library = None
153147

154-
return cc_common.create_linker_input(
155-
owner = owning_label,
156-
libraries = depset(direct = [
157-
cc_common.create_library_to_link(
158-
actions = actions,
159-
alwayslink = alwayslink,
160-
cc_toolchain = swift_toolchain.cc_toolchain_info,
161-
feature_configuration = cc_feature_configuration,
162-
pic_static_library = static_library,
163-
dynamic_library = dynamic_library,
164-
),
165-
]),
166-
additional_inputs = depset(direct = additional_inputs),
167-
user_link_flags = depset(direct = user_link_flags),
148+
return cc_common.create_library_to_link(
149+
actions = actions,
150+
alwayslink = alwayslink,
151+
cc_toolchain = swift_toolchain.cc_toolchain_info,
152+
feature_configuration = cc_feature_configuration,
153+
pic_static_library = static_library,
154+
dynamic_library = dynamic_library,
168155
)
169156

170157
def register_link_binary_action(
171-
owning_label,
172158
actions,
173159
additional_inputs,
174160
additional_linking_contexts,
@@ -184,7 +170,6 @@ def register_link_binary_action(
184170
"""Registers an action that invokes the linker to produce a binary.
185171
186172
Args:
187-
owning_label: Label of the rule creating the link action.
188173
actions: The object used to register actions.
189174
additional_inputs: A list of additional inputs to the link action,
190175
such as those used in `$(location ...)` substitution, linker
@@ -246,12 +231,7 @@ def register_link_binary_action(
246231

247232
linking_contexts.append(
248233
cc_common.create_linking_context(
249-
linker_inputs = depset(direct = [
250-
cc_common.create_linker_input(
251-
owner = owning_label,
252-
user_link_flags = depset(direct = dep_link_flags),
253-
),
254-
])
234+
user_link_flags = dep_link_flags,
255235
),
256236
)
257237

swift/internal/swift_binary_test.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ def _swift_linking_rule_impl(
237237
user_link_flags.extend(ctx.fragments.cpp.linkopts)
238238

239239
linking_outputs = register_link_binary_action(
240-
owning_label = ctx.label,
241240
actions = ctx.actions,
242241
additional_inputs = additional_inputs_to_linker,
243242
additional_linking_contexts = additional_linking_contexts,

swift/internal/swift_grpc_library.bzl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ def _swift_grpc_library_impl(ctx):
293293
target_name = ctx.label.name,
294294
)
295295

296-
linker_input = register_libraries_to_link(
297-
owning_label = ctx.label,
296+
library_to_link = register_libraries_to_link(
298297
actions = ctx.actions,
299298
alwayslink = False,
300299
cc_feature_configuration = swift_common.cc_feature_configuration(
@@ -305,16 +304,14 @@ def _swift_grpc_library_impl(ctx):
305304
library_name = ctx.label.name,
306305
objects = compilation_outputs.object_files,
307306
swift_toolchain = swift_toolchain,
308-
additional_inputs = compilation_outputs.linker_inputs,
309-
user_link_flags = compilation_outputs.linker_flags,
310307
)
311308

312309
providers = [
313310
DefaultInfo(
314311
files = depset(direct = generated_files + compact([
315312
compilation_outputs.swiftdoc,
316313
compilation_outputs.swiftmodule,
317-
linker_input.libraries[0].pic_static_library,
314+
library_to_link.pic_static_library,
318315
])),
319316
),
320317
OutputGroupInfo(**output_groups_from_compilation_outputs(
@@ -323,7 +320,7 @@ def _swift_grpc_library_impl(ctx):
323320
create_cc_info(
324321
cc_infos = get_providers(compile_deps, CcInfo),
325322
compilation_outputs = compilation_outputs,
326-
linker_inputs = [linker_input],
323+
libraries_to_link = [library_to_link],
327324
),
328325
deps[0][SwiftProtoInfo],
329326
swift_common.create_swift_info(
@@ -349,7 +346,7 @@ def _swift_grpc_library_impl(ctx):
349346
link_inputs = compilation_outputs.linker_inputs,
350347
linkopts = compilation_outputs.linker_flags,
351348
module_map = compilation_outputs.generated_module_map,
352-
static_archives = compact([linker_input.libraries[0].pic_static_library]),
349+
static_archives = compact([library_to_link.pic_static_library]),
353350
swiftmodules = [compilation_outputs.swiftmodule],
354351
objc_header = compilation_outputs.generated_header,
355352
))

swift/internal/swift_import.bzl

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,14 @@ def _swift_import_impl(ctx):
3838
unsupported_features = ctx.disabled_features,
3939
)
4040

41-
linker_inputs = [
42-
cc_common.create_linker_input(
43-
libraries = depset(direct = [
44-
cc_common.create_library_to_link(
45-
actions = ctx.actions,
46-
cc_toolchain = cc_toolchain,
47-
feature_configuration = cc_feature_configuration,
48-
static_library = archive,
49-
)
50-
for archive in archives
51-
]),
52-
),
41+
libraries_to_link = [
42+
cc_common.create_library_to_link(
43+
actions = ctx.actions,
44+
cc_toolchain = cc_toolchain,
45+
feature_configuration = cc_feature_configuration,
46+
static_library = archive,
47+
)
48+
for archive in archives
5349
]
5450

5551
providers = [
@@ -63,7 +59,7 @@ def _swift_import_impl(ctx):
6359
),
6460
create_cc_info(
6561
cc_infos = get_providers(deps, CcInfo),
66-
linker_inputs = linker_inputs,
62+
libraries_to_link = libraries_to_link,
6763
),
6864
# Propagate an `Objc` provider so that Apple-specific rules like
6965
# apple_binary` will link the imported library properly. Typically we'd

swift/internal/swift_library.bzl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ def _swift_library_impl(ctx):
179179
else:
180180
clang_module = None
181181

182-
linker_input = register_libraries_to_link(
183-
owning_label = ctx.label,
182+
library_to_link = register_libraries_to_link(
184183
actions = ctx.actions,
185184
alwayslink = ctx.attr.alwayslink,
186185
cc_feature_configuration = swift_common.cc_feature_configuration(
@@ -191,16 +190,14 @@ def _swift_library_impl(ctx):
191190
library_name = ctx.label.name,
192191
objects = compilation_outputs.object_files,
193192
swift_toolchain = swift_toolchain,
194-
user_link_flags = linkopts,
195-
additional_inputs = compilation_outputs.linker_inputs,
196193
)
197194

198195
direct_output_files = compact([
199196
compilation_outputs.generated_header,
200197
compilation_outputs.swiftdoc,
201198
compilation_outputs.swiftinterface,
202199
compilation_outputs.swiftmodule,
203-
linker_input.libraries[0].pic_static_library,
200+
library_to_link.pic_static_library,
204201
])
205202

206203
providers = [
@@ -216,12 +213,14 @@ def _swift_library_impl(ctx):
216213
compilation_outputs = compilation_outputs,
217214
)),
218215
create_cc_info(
216+
additional_inputs = additional_inputs,
219217
cc_infos = get_providers(deps, CcInfo),
220218
compilation_outputs = compilation_outputs,
221219
defines = ctx.attr.defines,
222220
includes = [ctx.bin_dir.path],
223-
linker_inputs = [linker_input],
221+
libraries_to_link = [library_to_link],
224222
private_cc_infos = get_providers(private_deps, CcInfo),
223+
user_link_flags = linkopts,
225224
),
226225
coverage_common.instrumented_files_info(
227226
ctx,
@@ -262,7 +261,7 @@ def _swift_library_impl(ctx):
262261
link_inputs = compilation_outputs.linker_inputs + additional_inputs,
263262
linkopts = compilation_outputs.linker_flags + linkopts,
264263
module_map = compilation_outputs.generated_module_map,
265-
static_archives = compact([linker_input.libraries[0].pic_static_library]),
264+
static_archives = compact([library_to_link.pic_static_library]),
266265
swiftmodules = [compilation_outputs.swiftmodule],
267266
objc_header = compilation_outputs.generated_header,
268267
))

swift/internal/swift_module_alias.bzl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ def _swift_module_alias_impl(ctx):
7272
target_name = ctx.label.name,
7373
)
7474

75-
linker_input = register_libraries_to_link(
76-
owning_label = ctx.label,
75+
library_to_link = register_libraries_to_link(
7776
actions = ctx.actions,
7877
alwayslink = False,
7978
cc_feature_configuration = swift_common.cc_feature_configuration(
@@ -84,16 +83,15 @@ def _swift_module_alias_impl(ctx):
8483
library_name = ctx.label.name,
8584
objects = compilation_outputs.object_files,
8685
swift_toolchain = swift_toolchain,
87-
additional_inputs = compilation_outputs.linker_inputs,
8886
)
8987

9088
providers = [
9189
DefaultInfo(
9290
files = depset(compact([
9391
compilation_outputs.swiftdoc,
9492
compilation_outputs.swiftmodule,
95-
linker_input.libraries[0].dynamic_library,
96-
linker_input.libraries[0].pic_static_library,
93+
library_to_link.dynamic_library,
94+
library_to_link.pic_static_library,
9795
])),
9896
),
9997
OutputGroupInfo(**output_groups_from_compilation_outputs(
@@ -107,7 +105,7 @@ def _swift_module_alias_impl(ctx):
107105
cc_infos = get_providers(deps, CcInfo),
108106
compilation_outputs = compilation_outputs,
109107
includes = [ctx.bin_dir.path],
110-
linker_inputs = [linker_input],
108+
libraries_to_link = [library_to_link],
111109
),
112110
swift_common.create_swift_info(
113111
modules = [
@@ -132,7 +130,7 @@ def _swift_module_alias_impl(ctx):
132130
link_inputs = compilation_outputs.linker_inputs,
133131
linkopts = compilation_outputs.linker_flags,
134132
module_map = compilation_outputs.generated_module_map,
135-
static_archives = compact([linker_input.libraries[0].pic_static_library]),
133+
static_archives = compact([library_to_link.pic_static_library]),
136134
swiftmodules = [compilation_outputs.swiftmodule],
137135
objc_header = compilation_outputs.generated_header,
138136
))

swift/internal/swift_protoc_gen_aspect.bzl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,7 @@ def _swift_protoc_gen_aspect_impl(target, aspect_ctx):
428428
target_name = target.label.name,
429429
)
430430

431-
linker_input = register_libraries_to_link(
432-
owning_label = aspect_ctx.label,
431+
library_to_link = register_libraries_to_link(
433432
actions = aspect_ctx.actions,
434433
alwayslink = False,
435434
cc_feature_configuration = swift_common.cc_feature_configuration(
@@ -443,8 +442,6 @@ def _swift_protoc_gen_aspect_impl(target, aspect_ctx):
443442
library_name = "{}.swift".format(target.label.name),
444443
objects = compilation_outputs.object_files,
445444
swift_toolchain = swift_toolchain,
446-
additional_inputs = compilation_outputs.linker_inputs,
447-
user_link_flags = compilation_outputs.linker_flags,
448445
)
449446

450447
# It's bad practice to attach providers you don't own to other targets,
@@ -480,9 +477,9 @@ def _swift_protoc_gen_aspect_impl(target, aspect_ctx):
480477
objc_info_args["header"] = depset([
481478
compilation_outputs.generated_header,
482479
])
483-
if linker_input.libraries[0].pic_static_library:
480+
if library_to_link.pic_static_library:
484481
objc_info_args["library"] = depset(
485-
[linker_input.libraries[0].pic_static_library],
482+
[library_to_link.pic_static_library],
486483
order = "topological",
487484
)
488485
if compilation_outputs.linker_flags:
@@ -519,7 +516,7 @@ def _swift_protoc_gen_aspect_impl(target, aspect_ctx):
519516
cc_infos = cc_infos,
520517
compilation_outputs = compilation_outputs,
521518
includes = includes,
522-
linker_inputs = [linker_input],
519+
libraries_to_link = [library_to_link],
523520
),
524521
objc_info = objc_info,
525522
),

0 commit comments

Comments
 (0)