From 4430543b6220c668235dc21110ff339840b862a3 Mon Sep 17 00:00:00 2001 From: Tony Allevato Date: Fri, 28 Mar 2025 07:17:25 -0700 Subject: [PATCH 1/2] Upstream: Update the API of `swift_common.compile_module_interface`. This adds the `target_name` argument that is present in other compile APIs so that supplemental outputs can get unique names based on the name of the Bazel target being compiled (will be used in a follow-up change). Likewise, this changes the return type of the function from just the module context to a `struct` that contains two fields: `module_context` (the original value), and `supplemental_outputs`, which will eventually be used to provide an indexstore (supported starting from Swift 6.2/Xcode 16.3). PiperOrigin-RevId: 741516048 --- swift/internal/compiling.bzl | 30 +++++++++++++++++++++++------- swift/swift_import.bzl | 5 +++-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/swift/internal/compiling.bzl b/swift/internal/compiling.bzl index 0382e6c41..0d748f094 100644 --- a/swift/internal/compiling.bzl +++ b/swift/internal/compiling.bzl @@ -180,12 +180,22 @@ def compile_module_interface( `run_toolchain_action`. Returns: - 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 module. This should typically be - propagated by a `SwiftInfo` provider of the calling rule, and the - `CcCompilationContext` inside the Clang module substructure should be - propagated by the `CcInfo` provider of the calling rule. + A `struct` with the following fields: + + * `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 + module. This should typically be propagated by a `SwiftInfo` + provider of the calling rule, and the `CcCompilationContext` inside + the Clang module substructure should be propagated by the `CcInfo` + provider of the calling rule. + + * `supplemental_outputs`: A `struct` representing supplemental, + optional outputs. Its fields are: + + * `indexstore_directory`: A directory-type `File` that represents + the indexstore output files created when the feature + `swift.index_while_building` is enabled. """ swiftmodule_file = actions.declare_file("{}.swiftmodule".format(module_name)) @@ -308,7 +318,13 @@ def compile_module_interface( ), ) - return module_context + return struct( + module_context = module_context, + supplemental_outputs = struct( + # TODO: b/401305010 - Generate indexstore when requested. + indexstore_directory = None, + ), + ) def compile( *, diff --git a/swift/swift_import.bzl b/swift/swift_import.bzl index b939b83c5..f613101ac 100644 --- a/swift/swift_import.bzl +++ b/swift/swift_import.bzl @@ -96,7 +96,7 @@ def _swift_import_impl(ctx): swift_infos = get_providers(deps, SwiftInfo) if swiftinterface: - module_context = compile_module_interface( + compile_result = compile_module_interface( actions = ctx.actions, compilation_contexts = get_compilation_contexts(ctx.attr.deps), feature_configuration = feature_configuration, @@ -104,8 +104,9 @@ def _swift_import_impl(ctx): swiftinterface_file = swiftinterface, swift_infos = swift_infos, swift_toolchain = swift_toolchain, - target_name = ctx.attr.name, + target_name = ctx.label.name, ) + module_context = compile_result.module_context swift_outputs = [ module_context.swift.swiftmodule, ] + compact([module_context.swift.swiftdoc]) From 836e93019a8139e97cf7c8c623e6584957451923 Mon Sep 17 00:00:00 2001 From: Luis Padron Date: Wed, 28 May 2025 21:45:02 -0400 Subject: [PATCH 2/2] Update documentation for compile_module_interface --- doc/api.md | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/doc/api.md b/doc/api.md index fa78c9e0f..55c130183 100644 --- a/doc/api.md +++ b/doc/api.md @@ -279,12 +279,22 @@ Compiles a Swift module interface. **RETURNS** -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 module. This should typically be - propagated by a `SwiftInfo` provider of the calling rule, and the - `CcCompilationContext` inside the Clang module substructure should be - propagated by the `CcInfo` provider of the calling rule. +A `struct` with the following fields: + + * `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 + module. This should typically be propagated by a `SwiftInfo` + provider of the calling rule, and the `CcCompilationContext` inside + the Clang module substructure should be propagated by the `CcInfo` + provider of the calling rule. + + * `supplemental_outputs`: A `struct` representing supplemental, + optional outputs. Its fields are: + + * `indexstore_directory`: A directory-type `File` that represents + the indexstore output files created when the feature + `swift.index_while_building` is enabled.