Skip to content

Commit

Permalink
Add support for emit-extension-block-symbols flag
Browse files Browse the repository at this point in the history
This flag can be used when emitting a symbol graph to additionally include the symbols from the extension blocks.
This is useful when generating documentation with DocC so that the symbols from the extension blocks are included in the documentation.
  • Loading branch information
luispadron committed Apr 12, 2024
1 parent 6e48feb commit 712bb69
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
18 changes: 18 additions & 0 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ load(
"SWIFT_FEATURE_EMIT_SWIFTINTERFACE",
"SWIFT_FEATURE_EMIT_SWIFTSOURCEINFO",
"SWIFT_FEATURE_EMIT_SYMBOL_GRAPH",
"SWIFT_FEATURE_EMIT_SYMBOL_GRAPH_EXTENSION_BLOCKS",
"SWIFT_FEATURE_ENABLE_BATCH_MODE",
"SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION",
"SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES",
Expand Down Expand Up @@ -859,6 +860,17 @@ def compile_action_configs(
],
not_features = [SWIFT_FEATURE_SPLIT_DERIVED_FILES_GENERATION],
),
swift_toolchain_config.action_config(
actions = [
swift_action_names.COMPILE,
],
configurators = [_emit_symbol_graph_extension_blocks_configurator],
features = [
SWIFT_FEATURE_EMIT_SYMBOL_GRAPH,
SWIFT_FEATURE_EMIT_SYMBOL_GRAPH_EXTENSION_BLOCKS,
],
not_features = [SWIFT_FEATURE_SPLIT_DERIVED_FILES_GENERATION],
),
swift_toolchain_config.action_config(
actions = [
swift_action_names.DERIVE_FILES,
Expand Down Expand Up @@ -2014,6 +2026,12 @@ def _emit_symbol_graph_configurator(prerequisites, args):
prerequisites.symbol_graph_directory.path,
)

def _emit_symbol_graph_extension_blocks_configurator(_prerequisites, args):
args.add(
"-Xfrontend",
"-emit-extension-block-symbols",
)

def _global_index_store_configurator(prerequisites, args):
"""Adds flags for index-store generation to the command line."""
out_dir = prerequisites.indexstore_directory.dirname.split("/")[0]
Expand Down
3 changes: 3 additions & 0 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ SWIFT_FEATURE_INDEX_WHILE_BUILDING = "swift.index_while_building"
# If enabled, the compilation action for a target will produce a symbol graph.
SWIFT_FEATURE_EMIT_SYMBOL_GRAPH = "swift.emit_symbol_graph"

# If enabled when `SWIFT_FEATURE_EMIT_SYMBOL_GRAPH` is enabled, emits symbols for extension code blocks.
SWIFT_FEATURE_EMIT_SYMBOL_GRAPH_EXTENSION_BLOCKS = "swift.emit_symbol_graph_extension_blocks"

# If enabled the compilation action will not produce indexes for system modules.
SWIFT_FEATURE_DISABLE_SYSTEM_INDEX = "swift.disable_system_index"

Expand Down
23 changes: 23 additions & 0 deletions test/split_derived_files_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ default_no_split_swiftmodule_symbol_graph_test = make_action_command_line_test_r
],
},
)
default_no_split_swiftmodule_symbol_graph_extension_blocks_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:features": [
"swift.emit_symbol_graph",
"swift.emit_symbol_graph_extension_blocks",
],
},
)

def split_derived_files_test_suite(name):
"""Test suite for split derived files options.
Expand Down Expand Up @@ -320,6 +328,21 @@ def split_derived_files_test_suite(name):
"-emit-symbol-graph",
"-emit-symbol-graph-dir",
],
not_expected_argv = [
"-emit-extension-block-symbols",
],
mnemonic = "SwiftCompile",
tags = [name],
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

default_no_split_swiftmodule_symbol_graph_extension_blocks_test(
name = "{}_default_no_split_symbol_graph_extension_blocks_in_compile_action".format(name),
expected_argv = [
"-emit-symbol-graph",
"-emit-symbol-graph-dir",
"-emit-extension-block-symbols",
],
mnemonic = "SwiftCompile",
tags = [name],
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
Expand Down

0 comments on commit 712bb69

Please sign in to comment.