diff --git a/doc/api.md b/doc/api.md index 0e5e9b127..9bd7c5b07 100644 --- a/doc/api.md +++ b/doc/api.md @@ -171,6 +171,14 @@ Compiles a Swift module. A `struct` with the following fields: + * `swift_info`: A `SwiftInfo` provider whose list of direct modules + contains the single Swift module context produced by this function + (identical to the `module_context` field below) and whose transitive + modules represent the transitive non-private dependencies. Rule + implementations that call this function can typically return this + provider directly, except in rare cases like making multiple calls + to `swift_common.compile` that need to be merged. + * `module_context`: A Swift module context (as returned by `create_swift_module_context`) that contains the Swift (and potentially C/Objective-C) compilation prerequisites of the compiled diff --git a/swift/internal/compiling.bzl b/swift/internal/compiling.bzl index c80266269..7759ec1e5 100644 --- a/swift/internal/compiling.bzl +++ b/swift/internal/compiling.bzl @@ -374,6 +374,14 @@ def compile( Returns: A `struct` with the following fields: + * `swift_info`: A `SwiftInfo` provider whose list of direct modules + contains the single Swift module context produced by this function + (identical to the `module_context` field below) and whose transitive + modules represent the transitive non-private dependencies. Rule + implementations that call this function can typically return this + provider directly, except in rare cases like making multiple calls + to `swift_common.compile` that need to be merged. + * `module_context`: A Swift module context (as returned by `create_swift_module_context`) that contains the Swift (and potentially C/Objective-C) compilation prerequisites of the compiled @@ -511,18 +519,27 @@ def compile( providers = objc_infos + swift_toolchain.implicit_deps_providers.objc_infos, ) - merged_swift_info = SwiftInfo( - swift_infos = ( - swift_infos + - private_swift_infos + - swift_toolchain.implicit_deps_providers.swift_infos + - _cross_imported_swift_infos( - swift_toolchain = swift_toolchain, - user_swift_infos = swift_infos + private_swift_infos, - ) - ), + # These are the `SwiftInfo` providers that will be merged with the compiled + # module context and returned as the `swift_info` field of this function's + # result. Note that private deps are explicitly not included here, as they + # are not supposed to be propagated. + # + # TODO(allevato): It would potentially clean things up if we included the + # toolchain's implicit dependencies here as well. Do this and make sure it + # doesn't break anything unexpected. + swift_infos_to_propagate = swift_infos + _cross_imported_swift_infos( + swift_toolchain = swift_toolchain, + user_swift_infos = swift_infos + private_swift_infos, + ) + + all_swift_infos = ( + swift_infos_to_propagate + + private_swift_infos + + swift_toolchain.implicit_deps_providers.swift_infos ) + merged_swift_info = SwiftInfo(swift_infos = all_swift_infos) + # Flattening this `depset` is necessary because we need to extract the # module maps or precompiled modules out of structured values and do so # conditionally. This should not lead to poor performance because the @@ -789,6 +806,10 @@ to use swift_common.compile(include_dev_srch_paths = ...) instead.\ indexstore_directory = compile_outputs.indexstore_directory, macro_expansion_directory = compile_outputs.macro_expansion_directory, ), + swift_info = SwiftInfo( + modules = [module_context], + swift_infos = swift_infos_to_propagate, + ), ) def precompile_clang_module( diff --git a/swift/swift_compiler_plugin.bzl b/swift/swift_compiler_plugin.bzl index c984c1056..b181f2673 100644 --- a/swift/swift_compiler_plugin.bzl +++ b/swift/swift_compiler_plugin.bzl @@ -183,9 +183,7 @@ def _swift_compiler_plugin_impl(ctx): ), executable = binary_linking_outputs.executable, module_names = depset([module_name]), - swift_info = SwiftInfo( - modules = [module_context], - ), + swift_info = compile_result.swift_info, ), ] diff --git a/swift/swift_library.bzl b/swift/swift_library.bzl index d0f5d4ca3..666ca91d7 100644 --- a/swift/swift_library.bzl +++ b/swift/swift_library.bzl @@ -259,12 +259,7 @@ def _swift_library_impl(ctx): extensions = ["swift"], source_attributes = ["srcs"], ), - SwiftInfo( - modules = [module_context], - # Note that private_deps are explicitly omitted here; they should - # not propagate. - swift_infos = swift_infos, - ), + compile_result.swift_info, OutputGroupInfo( **supplemental_compilation_output_groups(supplemental_outputs) ), diff --git a/swift/swift_module_alias.bzl b/swift/swift_module_alias.bzl index d48ba20b2..227adba77 100644 --- a/swift/swift_module_alias.bzl +++ b/swift/swift_module_alias.bzl @@ -119,10 +119,7 @@ def _swift_module_alias_impl(ctx): compilation_context = module_context.clang.compilation_context, linking_context = linking_context, ), - SwiftInfo( - modules = [module_context], - swift_infos = swift_infos, - ), + compile_result.swift_info, ] # Propagate an `apple_common.Objc` provider with linking info about the diff --git a/swift/swift_test.bzl b/swift/swift_test.bzl index c81424551..80a9a3218 100644 --- a/swift/swift_test.bzl +++ b/swift/swift_test.bzl @@ -429,10 +429,7 @@ def _swift_test_impl(ctx): compilation_outputs = compile_result.compilation_outputs all_supplemental_outputs.append(compile_result.supplemental_outputs) - swift_infos_including_owner = [SwiftInfo( - modules = [compile_result.module_context], - swift_infos = deps_swift_infos, - )] + swift_infos_including_owner = [compile_result.swift_info] # If we're going to do test discovery below, extract the symbol graph of # the module that we just compiled so that we can discover any tests in