Skip to content

Commit 0004e22

Browse files
committed
Do not propagate module_map and umbrella_headers of objc private deps
1 parent 329d00a commit 0004e22

6 files changed

+33
-6
lines changed

swift/internal/linking.bzl

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def new_objc_provider(
220220
additional_objc_infos = [],
221221
alwayslink = False,
222222
deps,
223+
private_deps,
223224
feature_configuration,
224225
is_test,
225226
libraries_to_link,
@@ -239,6 +240,9 @@ def new_objc_provider(
239240
deps: The dependencies of the target being built, whose `Objc` providers
240241
will be passed to the new one in order to propagate the correct
241242
transitive fields.
243+
private_deps: The private dependencies of the target being built,
244+
whose `Objc` providers will be passed to the new one in order to
245+
propagate the correct transitive fields.
242246
feature_configuration: The Swift feature configuration.
243247
is_test: Represents if the `testonly` value of the context.
244248
libraries_to_link: A list (typically of one element) of the
@@ -263,7 +267,8 @@ def new_objc_provider(
263267
# the Obj-C and C++ rules, we need to collect libraries from `CcInfo` and
264268
# put them into the new `Objc` provider.
265269
transitive_cc_libs = []
266-
for cc_info in get_providers(deps, CcInfo):
270+
all_deps = deps + private_deps
271+
for cc_info in get_providers(all_deps, CcInfo):
267272
static_libs = []
268273
for linker_input in cc_info.linking_context.linker_inputs.to_list():
269274
for library_to_link in linker_input.libraries:
@@ -302,6 +307,26 @@ def new_objc_provider(
302307
):
303308
extra_linkopts.append("-ObjC")
304309

310+
providers = get_providers(
311+
deps,
312+
apple_common.Objc,
313+
)
314+
for private_dep in private_deps:
315+
if apple_common.Objc in private_dep:
316+
# For private deps, we only need to propagate linker inputs with Objc provider, but no compilation artifacts (eg module_map, umbrella_header).
317+
private_dep_objc_provider_kwargs = {
318+
"force_load_library": private_dep[apple_common.Objc].force_load_library,
319+
"imported_library": private_dep[apple_common.Objc].imported_library,
320+
"library": private_dep[apple_common.Objc].library,
321+
"linkopt": private_dep[apple_common.Objc].linkopt,
322+
"sdk_dylib": private_dep[apple_common.Objc].sdk_dylib,
323+
"sdk_framework": private_dep[apple_common.Objc].sdk_framework,
324+
"source": private_dep[apple_common.Objc].source,
325+
"weak_sdk_framework": private_dep[apple_common.Objc].weak_sdk_framework,
326+
}
327+
objc_provider = apple_common.new_objc_provider(**private_dep_objc_provider_kwargs)
328+
providers.append(objc_provider)
329+
305330
return apple_common.new_objc_provider(
306331
force_load_library = depset(
307332
force_load_libraries,
@@ -314,10 +339,7 @@ def new_objc_provider(
314339
),
315340
link_inputs = depset(additional_link_inputs + debug_link_inputs),
316341
linkopt = depset(user_link_flags + extra_linkopts),
317-
providers = get_providers(
318-
deps,
319-
apple_common.Objc,
320-
) + additional_objc_infos,
342+
providers = providers + additional_objc_infos,
321343
)
322344

323345
def register_link_binary_action(

swift/internal/swift_grpc_library.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ def _swift_grpc_library_impl(ctx):
346346
swift_toolchain.implicit_deps_providers.objc_infos
347347
),
348348
deps = compile_deps,
349+
private_deps = [],
349350
feature_configuration = feature_configuration,
350351
is_test = ctx.attr.testonly,
351352
module_context = module_context,

swift/internal/swift_import.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def _swift_import_impl(ctx):
9191
# ignored on non-Apple platforms anyway.
9292
new_objc_provider(
9393
deps = deps,
94+
private_deps = [],
9495
feature_configuration = None,
9596
is_test = ctx.attr.testonly,
9697
libraries_to_link = libraries_to_link,

swift/internal/swift_library.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ def _swift_library_impl(ctx):
268268
additional_link_inputs = additional_inputs,
269269
additional_objc_infos = implicit_deps_providers.objc_infos,
270270
alwayslink = ctx.attr.alwayslink,
271-
deps = deps + private_deps,
271+
deps = deps,
272+
private_deps = private_deps,
272273
feature_configuration = feature_configuration,
273274
is_test = ctx.attr.testonly,
274275
module_context = module_context,

swift/internal/swift_module_alias.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def _swift_module_alias_impl(ctx):
121121
swift_toolchain.implicit_deps_providers.objc_infos
122122
),
123123
deps = deps,
124+
private_deps = [],
124125
feature_configuration = feature_configuration,
125126
is_test = ctx.attr.testonly,
126127
module_context = module_context,

swift/internal/swift_protoc_gen_aspect.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ def _swift_protoc_gen_aspect_impl(target, aspect_ctx):
498498
# We pass an empty list here because we already extracted the
499499
# `Objc` providers from `SwiftProtoCcInfo` above.
500500
deps = [],
501+
private_deps = [],
501502
feature_configuration = feature_configuration,
502503
is_test = False,
503504
module_context = module_context,

0 commit comments

Comments
 (0)