Skip to content

Commit

Permalink
Update extract symbol graphs rule to include swiftdoc
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 3a7119b
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,11 +80,14 @@ def extract_symbol_graph(
# conditionally.
transitive_modules = merged_swift_info.transitive_modules.to_list()

transitive_swiftdocs = []
transitive_swiftmodules = []
for module in transitive_modules:
swift_module = module.swift
if swift_module:
transitive_swiftmodules.append(swift_module.swiftmodule)
if swift_module.swiftdoc:
transitive_swiftdocs.append(swift_module.swiftdoc)

prerequisites = struct(
bin_dir = feature_configuration._bin_dir,
Expand All @@ -99,6 +102,7 @@ def extract_symbol_graph(
output_dir = output_dir,
target_label = feature_configuration._label,
transitive_modules = transitive_modules,
transitive_swiftdocs = transitive_swiftdocs,
transitive_swiftmodules = transitive_swiftmodules,
)

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` file 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.transitive_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 3a7119b

Please sign in to comment.