Skip to content

Commit af531c8

Browse files
evil159github-actions[bot]
authored andcommitted
filter char8_t from public symbols (#11881)
GitOrigin-RevId: 33f604843aa97f4f8f5b83eb069c42c3a5bb957e
1 parent a37b6c9 commit af531c8

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python3
2+
"""Remove compiler-artifact symbols from DocC symbol graph JSON files.
3+
4+
Newer Swift compilers (Xcode 16.3+) import `char8_t` from auto-generated
5+
-Swift.h bridging headers as a public typealias. When the dependency module
6+
is re-exported (via @_exported import), these symbols leak into the
7+
MapboxMaps documentation. This script strips them from the symbol graphs
8+
before DocC processes them.
9+
"""
10+
11+
import json
12+
import os
13+
import sys
14+
15+
# Symbols that are compiler artifacts and should not appear in public docs.
16+
ARTIFACTS = {"char8_t"}
17+
18+
19+
def strip(path):
20+
with open(path) as f:
21+
sg = json.load(f)
22+
23+
artifact_ids = set()
24+
filtered_symbols = []
25+
for sym in sg.get("symbols", []):
26+
if sym["names"]["title"] in ARTIFACTS:
27+
artifact_ids.add(sym["identifier"]["precise"])
28+
else:
29+
filtered_symbols.append(sym)
30+
31+
if not artifact_ids:
32+
return
33+
34+
sg["symbols"] = filtered_symbols
35+
sg["relationships"] = [
36+
r for r in sg.get("relationships", []) if r["source"] not in artifact_ids and r["target"] not in artifact_ids
37+
]
38+
39+
with open(path, "w") as f:
40+
json.dump(sg, f)
41+
42+
basepath = os.path.relpath(path, sys.argv[1])
43+
print(f" Stripped {artifact_ids} from {basepath}")
44+
45+
46+
def main():
47+
symbol_graph_dir = sys.argv[1]
48+
print(f"Stripping compiler artifacts from symbol graphs in {symbol_graph_dir}")
49+
for root, _, files in os.walk(symbol_graph_dir):
50+
for name in files:
51+
if name.endswith(".symbols.json"):
52+
strip(os.path.join(root, name))
53+
54+
55+
if __name__ == "__main__":
56+
main()

scripts/doc-generation/xcode-rebuild-docc.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ generateSymbolGraphs() {
8585
# Rename MapboxCoreMaps to MapboxMaps in the extension symbol graph so docc
8686
# correctly associates extensions with the renamed module.
8787
mv "$SWIFTEXTRACT_OUTPUT_DIR/MapboxMaps@MapboxCoreMaps.symbols.json" "$SWIFTEXTRACT_OUTPUT_DIR/MapboxMaps@MapboxMaps.symbols.json"
88+
89+
# Remove compiler-artifact symbols (e.g. char8_t leaked via -Swift.h bridging
90+
# headers) from all symbol graphs so they don't appear in published docs.
91+
"$MAPBOXMAPS_PATH/scripts/doc-generation/strip-compiler-artifacts.py" "$SYMBOL_GRAPH_DIR"
8892
}
8993

9094
# Generate a dependency file to support incremental builds

0 commit comments

Comments
 (0)