39
39
"SWIFT_FEATURE_EMIT_BC" ,
40
40
"SWIFT_FEATURE_EMIT_C_MODULE" ,
41
41
"SWIFT_FEATURE_EMIT_SWIFTINTERFACE" ,
42
+ "SWIFT_FEATURE_EMIT_SYMBOL_GRAPH" ,
42
43
"SWIFT_FEATURE_ENABLE_BATCH_MODE" ,
43
44
"SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION" ,
44
45
"SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES" ,
@@ -703,6 +704,15 @@ def compile_action_configs(
703
704
SWIFT_FEATURE_USE_PCH_OUTPUT_DIR ,
704
705
],
705
706
),
707
+ swift_toolchain_config .action_config (
708
+ actions = [
709
+ swift_action_names .COMPILE ,
710
+ ],
711
+ configurators = [_emit_symbol_graph_configurator ],
712
+ features = [
713
+ SWIFT_FEATURE_EMIT_SYMBOL_GRAPH ,
714
+ ],
715
+ ),
706
716
707
717
# When using C modules, disable the implicit search for module map files
708
718
# because all of them, including system dependencies, will be provided
@@ -1608,6 +1618,21 @@ def _pch_output_dir_configurator(prerequisites, args):
1608
1618
paths .join (prerequisites .bin_dir .path , "_pch_output_dir" ),
1609
1619
)
1610
1620
1621
+ def _emit_symbol_graph_configurator (prerequisites , args ):
1622
+ """Adds flags for `-emit-symbol-graph` configuration to the command line.
1623
+
1624
+ This is a directory to persist symbol graph files that can be used by
1625
+ tools such as DocC or jazzy to generate documentation.
1626
+ """
1627
+ args .add (
1628
+ "-Xfrontend" ,
1629
+ "-emit-symbol-graph" ,
1630
+ )
1631
+ args .add (
1632
+ "-emit-symbol-graph-dir" ,
1633
+ prerequisites .symbol_graph_directory .path ,
1634
+ )
1635
+
1611
1636
def _global_index_store_configurator (prerequisites , args ):
1612
1637
"""Adds flags for index-store generation to the command line."""
1613
1638
out_dir = prerequisites .indexstore_directory .dirname .split ("/" )[0 ]
@@ -1867,6 +1892,7 @@ def compile(
1867
1892
all_compile_outputs = compact ([
1868
1893
compile_outputs .swiftinterface_file ,
1869
1894
compile_outputs .indexstore_directory ,
1895
+ compile_outputs .symbol_graph_directory ,
1870
1896
]) + compile_outputs .object_files
1871
1897
all_derived_outputs = compact ([
1872
1898
# The `.swiftmodule` file is explicitly listed as the first output
@@ -1890,6 +1916,7 @@ def compile(
1890
1916
compile_outputs .swiftsourceinfo_file ,
1891
1917
compile_outputs .generated_header_file ,
1892
1918
compile_outputs .indexstore_directory ,
1919
+ compile_outputs .symbol_graph_directory ,
1893
1920
]) + compile_outputs .object_files + other_outputs
1894
1921
all_derived_outputs = []
1895
1922
@@ -2073,6 +2100,7 @@ def compile(
2073
2100
other_compilation_outputs = struct (
2074
2101
ast_files = compile_outputs .ast_files ,
2075
2102
indexstore = compile_outputs .indexstore_directory ,
2103
+ symbol_graph = compile_outputs .symbol_graph_directory ,
2076
2104
)
2077
2105
2078
2106
return module_context , cc_compilation_outputs , other_compilation_outputs
@@ -2511,11 +2539,24 @@ def _declare_compile_outputs(
2511
2539
else :
2512
2540
indexstore_directory = None
2513
2541
2542
+ emit_symbol_graph = is_feature_enabled (
2543
+ feature_configuration = feature_configuration ,
2544
+ feature_name = SWIFT_FEATURE_EMIT_SYMBOL_GRAPH ,
2545
+ )
2546
+ if (emit_symbol_graph ):
2547
+ symbol_graph_directory = derived_files .symbol_graph_directory (
2548
+ actions = actions ,
2549
+ target_name = target_name ,
2550
+ )
2551
+ else :
2552
+ symbol_graph_directory = None
2553
+
2514
2554
compile_outputs = struct (
2515
2555
ast_files = ast_files ,
2516
2556
generated_header_file = generated_header ,
2517
2557
generated_module_map_file = generated_module_map ,
2518
2558
indexstore_directory = indexstore_directory ,
2559
+ symbol_graph_directory = symbol_graph_directory ,
2519
2560
object_files = object_files ,
2520
2561
output_file_map = output_file_map ,
2521
2562
derived_files_output_file_map = derived_files_output_file_map ,
@@ -2836,6 +2877,11 @@ def output_groups_from_other_compilation_outputs(*, other_compilation_outputs):
2836
2877
other_compilation_outputs .indexstore ,
2837
2878
])
2838
2879
2880
+ if other_compilation_outputs .symbol_graph :
2881
+ output_groups ["swift_symbol_graph" ] = depset ([
2882
+ other_compilation_outputs .symbol_graph ,
2883
+ ])
2884
+
2839
2885
return output_groups
2840
2886
2841
2887
def swift_library_output_map (name ):
0 commit comments