Skip to content

Commit

Permalink
Update extract symbol graphs rule to include swiftdoc (#1286)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
luispadron committed Jul 9, 2024
1 parent b65d9ad commit a127f44
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions swift/internal/symbol_graph_extracting.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions swift/toolchains/config/compile_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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],
),
])

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a127f44

Please sign in to comment.