Skip to content

Conversation

@Kyle-Ye
Copy link
Collaborator

@Kyle-Ye Kyle-Ye commented Oct 4, 2025

Summary

This PR adds comprehensive Swift-DocC documentation generation and deployment to GitHub Pages, replacing the previous Swift Package Index approach. The documentation is now live at:

https://openswiftuiproject.github.io/OpenSwiftUI/documentation/openswiftui/

Changes

Documentation Scripts

  1. Scripts/build-documentation.sh - Build and preview documentation locally

    • Supports local HTTP server preview
    • Configurable symbol visibility (public/internal/private)
    • Incremental builds for fast iteration
    • Port conflict detection and resolution
    • Source code linking to GitHub
  2. Scripts/update-gh-pages-documentation.sh - Deploy documentation to GitHub Pages

    • Automated gh-pages branch management via git worktree
    • Symbol graph filtering to remove re-exported system frameworks (CoreFoundation, CoreGraphics)
    • Force push by default to prevent repository size growth
    • --echo-without-push flag for testing deployments
    • Documentation placed in gh-pages/docs/ subdirectory

Key Features

  • Symbol Filtering: Automatically filters out ~5,700 re-exported symbols from system frameworks, keeping only ~4,300 OpenSwiftUI/OpenSwiftUICore symbols
  • Re-export Support: Properly handles @_exported import OpenSwiftUICore to show all APIs under the OpenSwiftUI module
  • Incremental Builds: Reuses existing symbol graphs and build artifacts for faster iterations
  • GitHub Integration: Adds source code links to GitHub for easy navigation

Technical Improvements

  • Auto-clean when symbol graphs are missing
  • Specific glob patterns to avoid matching OpenSwiftUICore symbol graphs
  • Git worktree approach for clean gh-pages branch management
  • Python-based symbol graph filtering using Swift name mangling parsing
  • Proper handling of .gitignore when force-adding files in gh-pages branch

Documentation

Added comprehensive Docs/Documentation.md explaining:

  • How to use both scripts
  • GitHub Pages configuration
  • Why we chose self-hosting over Swift Package Index
  • Troubleshooting guide
  • Advanced usage examples
  • Technical implementation details
  • Future improvements (default implementation filtering, GitHub Actions migration)

Motivation

We initially used Swift Package Index for documentation, which worked well but had limitations:

  1. Binary Target Issues - SwiftPM has problems with binary targets in documentation builds (#7580)
  2. Exported Symbol Handling - SwiftPM doesn't properly handle @_exported import (#9101)
  3. Limited Customization - Plugin-based approach lacks fine-grained control over symbol filtering and generation

Self-hosting provides full control over the documentation pipeline and resolves these architectural constraints.

Testing

  • ✅ Local preview working on port 8000
  • ✅ Documentation successfully deployed to GitHub Pages
  • ✅ All resource paths correct with --hosting-base-path /OpenSwiftUI
  • ✅ Symbol filtering removes system framework symbols
  • ✅ Only OpenSwiftUI module appears in documentation (OpenSwiftUICore symbols included via re-export)
  • ✅ Source code links working correctly

Checklist

  • Documentation scripts created and tested
  • Symbol graph filtering implemented
  • GitHub Pages deployment working
  • Documentation added to Docs/Documentation.md
  • .gitignore updated to exclude gh-pages/ worktree
  • All resource paths use correct base path for GitHub Pages
  • Commits are atomic and well-documented

Future Work

  • Remove default implementations from protocol extensions
  • Migrate to GitHub Actions for automated deployment

Kyle-Ye added 17 commits October 4, 2025 17:24
- Generates symbol graphs and builds documentation using docc
- --preview: Local preview server with configurable port
- --port: Specify preview server port (default: 8000)
- --clean: Force rebuild of symbol graphs
- --minimum-access-level: Control symbol visibility (public/internal/private)
- --target: Specify module to document
- Automatic port conflict detection with user prompt
- Reuses existing build artifacts for fast preview iterations
- GitHub Pages deployment via gh-pages branch
- Create build-documentation.sh for building and previewing documentation
- Refactor update-gh-pages-documentation.sh to focus only on GitHub Pages deployment
- Add --source-service and --source-service-base-url options to enable source code links
- update-gh-pages-documentation.sh now calls build-documentation.sh internally
- Support --no-build option to deploy pre-built documentation
- Default --source-service to 'github'
- Default --source-service-base-url to OpenSwiftUI main branch
- Source links are now enabled by default
- Can still be overridden for forks or custom branches
- Detect module name from data/documentation/*.json files
- Use lowercase module name for preview URL (e.g., openswiftuicore)
- Fixes 404 errors when accessing documentation preview
- Use --target OpenSwiftUI when generating symbol graphs
- Only include OpenSwiftUI and OpenSwiftUICore symbol graphs
- Exclude re-exported system modules (Foundation, CoreFoundation, etc.)
- Documentation now shows OpenSwiftUI as main entry point
- Force push to gh-pages by default to avoid accumulating large binary files
- Add --no-force flag to preserve history if needed
- Prevents repo from growing rapidly with each documentation update
- Reference: uxlfoundation/oneAPI-spec#334
- Add Python script to filter symbol graph JSON files
- Extract module names from Swift mangled identifiers
- Only keep OpenSwiftUI and OpenSwiftUICore symbols
- Remove CoreFoundation, CoreGraphics, and other system framework symbols
- Reduces symbol count from 10,185 to 4,298 (OpenSwiftUI + OpenSwiftUICore only)
- Automatically run swift package clean when no symbol graphs exist
- Ensures symbol graphs are always generated on first run
- Prevents 'Symbol graph generation failed' error when build is up-to-date
- Subsequent runs reuse existing symbol graphs for fast iterations
- Check for TARGET_NAME.symbols.json instead of just the directory
- Prevents false positive when only dependency symbol graphs exist
- Ensures OpenSwiftUI symbol graphs are always generated
Only copy OpenSwiftUI*.symbols.json files, not OpenSwiftUICore*.symbols.json.
Since OpenSwiftUI uses @_exported import OpenSwiftUICore, the OpenSwiftUI
symbol graph already contains all re-exported OpenSwiftUICore symbols.

This ensures only one documentation module (openswiftui) is generated,
with all OpenSwiftUICore symbols appearing under openswiftui instead of
a separate openswiftuicore module.
The previous pattern OpenSwiftUI*.symbols.json incorrectly matched
OpenSwiftUICore.symbols.json because 'OpenSwiftUICore' starts with 'OpenSwiftUI'.

Changed to use two explicit copy commands:
1. OpenSwiftUI.symbols.json (exact match)
2. OpenSwiftUI@*.symbols.json (extension symbol graphs like @AppKit, @swift)

This ensures only OpenSwiftUI's own symbol graphs are included, not OpenSwiftUICore's.
Since OpenSwiftUI uses @_exported import OpenSwiftUICore, all OpenSwiftUICore symbols
are already included in OpenSwiftUI.symbols.json.
…reation

- Use 'git add -Af .' to override .gitignore rules that prevent tracking
  files in the .docs directory
- Create orphan branch in main working tree before creating worktree to
  ensure the branch exists properly
- This fixes deployment failures where files were ignored and the
  gh-pages branch wasn't created
- Add git_push() function to support --echo-without-push for testing
- Add --echo-without-push CLI option to echo push commands without executing
- Change gh-pages worktree location from .docs/gh-pages to gh-pages/
- Copy documentation files to gh-pages/docs/ subdirectory instead of root
- Add gh-pages to .gitignore to exclude worktree from main branch
- This fixes the issue where .docs, Example, and .swiftpm folders were
  incorrectly included in gh-pages branch
- Explain documentation architecture and hosting setup
- Provide usage instructions for build-documentation.sh script
- Provide usage instructions for update-gh-pages-documentation.sh script
- Document why self-hosted was chosen over Swift Package Index
- Include troubleshooting guide and advanced usage examples
- Explain technical details of symbol filtering and deployment process
- Add TODO for removing default implementations from docs
- Add TODO for migrating to GitHub Actions for automated deployment
- Add link to new GitHub Pages documentation as primary source
- Mention legacy SwiftPackageIndex version with OpenSwiftUICore limitation
- Use concise link labels for better readability
@Kyle-Ye Kyle-Ye force-pushed the feature/docc-github-pages branch from 7276332 to 9430cde Compare October 4, 2025 16:47
@Kyle-Ye Kyle-Ye merged commit d6cd066 into main Oct 4, 2025
7 checks passed
@Kyle-Ye Kyle-Ye deleted the feature/docc-github-pages branch October 4, 2025 16:51
@Kyle-Ye Kyle-Ye added the documentation Improvements or additions to documentation label Oct 4, 2025
@codecov
Copy link

codecov bot commented Oct 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 24.31%. Comparing base (ee10119) to head (9430cde).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #541   +/-   ##
=======================================
  Coverage   24.31%   24.31%           
=======================================
  Files         506      506           
  Lines       28979    28979           
=======================================
  Hits         7047     7047           
  Misses      21932    21932           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Doc] SPI documentation does not contains OpenSwiftUICore symbol

2 participants