From a127f44a2b4f8732b3ad9d84fda616d486054ee2 Mon Sep 17 00:00:00 2001 From: Luis Padron Date: Tue, 9 Jul 2024 13:29:02 -0400 Subject: [PATCH] Update extract symbol graphs rule to include swiftdoc (#1286) This updates the symbol graph extract configurator to additionally include the `.swiftdoc` files created by the the Swift module compilation. This is required to produce documentation comments in the `.symbolgraphs` when using the symbol graph extract rule. --- swift/internal/symbol_graph_extracting.bzl | 4 ++++ swift/toolchains/config/compile_config.bzl | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/swift/internal/symbol_graph_extracting.bzl b/swift/internal/symbol_graph_extracting.bzl index 78867b4d2..1caabe25b 100644 --- a/swift/internal/symbol_graph_extracting.bzl +++ b/swift/internal/symbol_graph_extracting.bzl @@ -80,16 +80,20 @@ def extract_symbol_graph( # conditionally. transitive_modules = merged_swift_info.transitive_modules.to_list() + direct_swiftdocs = [] transitive_swiftmodules = [] for module in transitive_modules: swift_module = module.swift if swift_module: transitive_swiftmodules.append(swift_module.swiftmodule) + if module.name == module_name and swift_module.swiftdoc: + direct_swiftdocs.append(swift_module.swiftdoc) prerequisites = struct( bin_dir = feature_configuration._bin_dir, cc_compilation_context = merged_compilation_context, developer_dirs = swift_toolchain.developer_dirs, + direct_swiftdocs = direct_swiftdocs, emit_extension_block_symbols = emit_extension_block_symbols, genfiles_dir = feature_configuration._genfiles_dir, include_dev_srch_paths = include_dev_srch_paths, diff --git a/swift/toolchains/config/compile_config.bzl b/swift/toolchains/config/compile_config.bzl index 315bb8032..a6d630dd0 100644 --- a/swift/toolchains/config/compile_config.bzl +++ b/swift/toolchains/config/compile_config.bzl @@ -43,6 +43,7 @@ load( "SWIFT_FEATURE_DISABLE_SYSTEM_INDEX", "SWIFT_FEATURE_EMIT_BC", "SWIFT_FEATURE_EMIT_PRIVATE_SWIFTINTERFACE", + "SWIFT_FEATURE_EMIT_SWIFTDOC", "SWIFT_FEATURE_EMIT_SWIFTINTERFACE", "SWIFT_FEATURE_ENABLE_BATCH_MODE", "SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION", @@ -815,9 +816,15 @@ def compile_action_configs( # swift-symbolgraph-extract doesn't yet support explicit Swift module # maps. + ActionConfigInfo( + actions = [SWIFT_ACTION_SYMBOL_GRAPH_EXTRACT], + configurators = [_dependencies_swiftmodules_and_swiftdocs_configurator], + features = [SWIFT_FEATURE_EMIT_SWIFTDOC], + ), ActionConfigInfo( actions = [SWIFT_ACTION_SYMBOL_GRAPH_EXTRACT], configurators = [_dependencies_swiftmodules_configurator], + not_features = [SWIFT_FEATURE_EMIT_SWIFTDOC], ), ]) @@ -1671,6 +1678,20 @@ def _swift_module_search_path_map_fn(module): else: return None +def _dependencies_swiftmodules_and_swiftdocs_configurator(prerequisites, args): + """Adds `.swiftmodule` and `.swiftdoc` files from the transitive modules to search paths and action inputs.""" + args.add_all( + prerequisites.transitive_modules, + format_each = "-I%s", + map_each = _swift_module_search_path_map_fn, + uniquify = True, + ) + + return ConfigResultInfo( + inputs = prerequisites.transitive_swiftmodules + + prerequisites.direct_swiftdocs, + ) + def _dependencies_swiftmodules_configurator(prerequisites, args): """Adds `.swiftmodule` files from deps to search paths and action inputs.""" args.add_all(