Skip to content

Commit

Permalink
[rules_swift] Stop generating compile info in ObjcProvider
Browse files Browse the repository at this point in the history
Step 3 of 3-step plan:
1. Migrate the definitions.
2. Migrate the uses.
3. Delete old ObjcProvider definitions.

See bazelbuild/bazel#10674.

A couple extra notes:

- Also migrated a couple remaining uses in
  swift_clang_module_aspect.bzl.  Some Starlark rules still export a
  (empty) ObjcProvider but not a CcInfo, so we still need to handle
  that case.

- Use of "header" is not removed, because it still populates direct
  fields in ObjcProvider.

RELNOTES: None
PiperOrigin-RevId: 320402849
  • Loading branch information
googlewalt authored and swiple-rules-gardener committed Jul 9, 2020
1 parent da184ed commit d5a55fe
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 29 deletions.
10 changes: 0 additions & 10 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1766,22 +1766,18 @@ def find_swift_version_copt_value(copts):

def new_objc_provider(
deps,
include_path,
link_inputs,
linkopts,
module_map,
static_archives,
swiftmodules,
defines = [],
objc_header = None):
"""Creates an `apple_common.Objc` provider for a Swift target.
Args:
deps: The dependencies of the target being built, whose `Objc` providers
will be passed to the new one in order to propagate the correct
transitive fields.
include_path: A header search path that should be propagated to
dependents.
link_inputs: Additional linker input files that should be propagated to
dependents.
linkopts: Linker options that should be propagated to dependents.
Expand All @@ -1791,8 +1787,6 @@ def new_objc_provider(
archives (`.a` files) containing the target's compiled code.
swiftmodules: A list (typically of one element) of the `.swiftmodule`
files for the compiled target.
defines: A list of `defines` from the propagating `swift_library` that
should also be defined for `objc_library` targets that depend on it.
objc_header: The generated Objective-C header for the Swift target. If
`None`, no headers will be propagated. This header is only needed
for Swift code that defines classes that should be exposed to
Expand Down Expand Up @@ -1826,10 +1820,6 @@ def new_objc_provider(
order = "topological",
)

if include_path:
objc_provider_args["include"] = depset(direct = [include_path])
if defines:
objc_provider_args["define"] = depset(direct = defines)
if objc_header:
objc_provider_args["header"] = depset(direct = [objc_header])
if linkopts:
Expand Down
17 changes: 4 additions & 13 deletions swift/internal/swift_clang_module_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ def _handle_cc_target(
"""
attr = aspect_ctx.rule.attr

# TODO(b/142867898): Only check `CcInfo` once all native rules correctly
# propagate both.
# TODO(b/142867898): Only check `CcInfo` once all rules correctly propagate
# it.
if CcInfo in target:
compilation_context = target[CcInfo].compilation_context
else:
compilation_context = target[apple_common.Objc].compilation_context
compilation_context = None

if swift_infos:
merged_swift_info = create_swift_info(swift_infos = swift_infos)
Expand Down Expand Up @@ -233,18 +233,9 @@ def _handle_cc_target(
CcInfo(compilation_context = compilation_context),
]
for dep in getattr(attr, "deps", []):
# TODO(b/142867898): Only check `CcInfo` once all native rules
# correctly propagate both.
if CcInfo in dep:
dep_context = dep[CcInfo].compilation_context
elif apple_common.Objc in dep:
dep_context = dep[apple_common.Objc].compilation_context
else:
dep_context = None

if dep_context:
target_and_deps_cc_infos.append(
CcInfo(compilation_context = dep_context),
CcInfo(compilation_context = dep[CcInfo].compilation_context),
)

compilation_context_to_compile = cc_common.merge_cc_infos(
Expand Down
1 change: 0 additions & 1 deletion swift/internal/swift_grpc_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ def _swift_grpc_library_impl(ctx):
if swift_toolchain.supports_objc_interop:
providers.append(new_objc_provider(
deps = compile_deps,
include_path = ctx.bin_dir.path,
link_inputs = compilation_outputs.linker_inputs,
linkopts = compilation_outputs.linker_flags,
module_map = compilation_outputs.generated_module_map,
Expand Down
1 change: 0 additions & 1 deletion swift/internal/swift_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def _swift_import_impl(ctx):
# ignored on non-Apple platforms anyway.
new_objc_provider(
deps = deps,
include_path = None,
link_inputs = [],
linkopts = [],
module_map = None,
Expand Down
2 changes: 0 additions & 2 deletions swift/internal/swift_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,11 @@ def _swift_library_impl(ctx):
# targets.
if swift_toolchain.supports_objc_interop:
providers.append(new_objc_provider(
defines = ctx.attr.defines,
# We must include private_deps here because some of the information
# propagated here is related to linking.
# TODO(allevato): This means we can't yet completely avoid
# propagating headers/module maps from impl-only Obj-C dependencies.
deps = deps + private_deps,
include_path = ctx.bin_dir.path,
link_inputs = compilation_outputs.linker_inputs + additional_inputs,
linkopts = compilation_outputs.linker_flags + linkopts,
module_map = compilation_outputs.generated_module_map,
Expand Down
1 change: 0 additions & 1 deletion swift/internal/swift_module_alias.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def _swift_module_alias_impl(ctx):
if swift_toolchain.supports_objc_interop:
providers.append(new_objc_provider(
deps = deps,
include_path = ctx.bin_dir.path,
link_inputs = compilation_outputs.linker_inputs,
linkopts = compilation_outputs.linker_flags,
module_map = compilation_outputs.generated_module_map,
Expand Down
1 change: 0 additions & 1 deletion swift/internal/swift_protoc_gen_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ def _swift_protoc_gen_aspect_impl(target, aspect_ctx):

includes = [aspect_ctx.bin_dir.path]
objc_info = apple_common.new_objc_provider(
include = depset(includes),
providers = objc_infos,
uses_swift = True,
**objc_info_args
Expand Down

0 comments on commit d5a55fe

Please sign in to comment.