Skip to content

Add support for Apple .doccarchive#2007

Merged
brentleyjones merged 1 commit intobazelbuild:masterfrom
luispadron:lpadron/add-bazel-docc-support
Sep 7, 2023
Merged

Add support for Apple .doccarchive#2007
brentleyjones merged 1 commit intobazelbuild:masterfrom
luispadron:lpadron/add-bazel-docc-support

Conversation

@luispadron
Copy link
Copy Markdown
Contributor

@luispadron luispadron commented Jul 4, 2023

Summary

Closes #1420

This adds support for building .doccarchive for rules_apple targets. It uses the symbol_graph feature from rules_swift to collect the symbol graph. It then invokes xcrun to find docc and create the .doccarchive.

Example:

docc_archive(
    name = "HelloWorldSwift.doccarchive",
    dep = ":HelloWorldSwift",
    fallback_bundle_identifier = "com.example.hello-world-swift",
    fallback_bundle_version = "1.0.0",
    fallback_display_name = "HelloWorldSwift",
)

Build it:

bazel build //examples/ios/HelloWorldSwift:HelloWorldSwift.doccarchive
xed  bazel-bin/examples/ios/HelloWorldSwift/HelloWorldSwift.doccarchive

Preview the docs:

bazel run //examples/ios/HelloWorldSwift:HelloWorldSwift.doccarchive

Tasks

  • Support ios_*_framework, ios_application like bundling rules.
  • Use transition for enabling symbol graph outputs.
  • Determine if Info.plist needs to be provided / copied.
  • Add support for including any .docc bundles defined in data.
  • Tests
  • Documentation

@luispadron luispadron mentioned this pull request Jul 4, 2023
@louwers
Copy link
Copy Markdown
Contributor

louwers commented Jul 4, 2023

This is awesome!

Objective-C support would be highly appreciated.

@luispadron
Copy link
Copy Markdown
Contributor Author

Objective-C support would be highly appreciated.

I think we'd need to follow what @keith mentioned in #1420 and use the flag in: https://forums.swift.org/t/clang-support-for-objective-c-symbol-graph-generation/57689/4.

It's possible we could transition on that flag in this rule as well, but not sure if we need to add more details to some objective-c provider somewhere to pass along the symbol graph directory.

If anyone has more details let me know! Working through Swift support since it probably addresses most use cases and worst case we follow up with Objective-C support

@luispadron
Copy link
Copy Markdown
Contributor Author

luispadron commented Jul 4, 2023

I'm also wondering if we need to create two rules one for the .docc bundle and another for .doccarchive?

Maybe. It might not be required if the docc_archive handles the internal .docc for the target. We still might want a docc_bundle rule similar to apple_resource_bundle, but since this would be its own target it would have no attached symbol_graph so doubt it would provide too much value to build that on it's own.

@luispadron luispadron force-pushed the lpadron/add-bazel-docc-support branch 3 times, most recently from 037fde2 to 83838d3 Compare July 4, 2023 22:12
@luispadron
Copy link
Copy Markdown
Contributor Author

Updated the PR! What I have is good enough to get existing swift_library, ios_application, etc building valid .doccarchives for their srcs 🎉

I've updated the tasks with some next steps I think I need to address, if you have thoughts on design so far please let me know!

@jerrymarino
Copy link
Copy Markdown
Contributor

@luispadron this is great, thanks so much for adding it. Really excited to pull it down and give it a whirl 🚀

It seems like we'll need some Xcode bits to get it working in the GUI in addition to this?

@luispadron luispadron force-pushed the lpadron/add-bazel-docc-support branch from f20bd52 to cc50603 Compare July 5, 2023 22:25
@luispadron
Copy link
Copy Markdown
Contributor Author

It seems like we'll need some Xcode bits to get it working in the GUI in addition to this?

I'll open a separate issue in rules_xcodeproj for .docc build support but with the rule in this PR: bazel build <target> && xed <target_output_path> will add the archive to the Documentation window in Xcode which is essentially what Build for Documentation does.

@luispadron luispadron force-pushed the lpadron/add-bazel-docc-support branch 3 times, most recently from 886d2f9 to 91a3ae6 Compare July 5, 2023 22:44
@luispadron
Copy link
Copy Markdown
Contributor Author

This is probably ready for an initial pass! I'll add tests and docs after any changes from that.

The HelloWorldSwift example showcases some simple symbol graph + .docc bundle support. Try both build and run!

@luispadron luispadron force-pushed the lpadron/add-bazel-docc-support branch 6 times, most recently from 28a2d4e to 2b6e71d Compare July 7, 2023 20:54
Copy link
Copy Markdown
Member

@BalestraPatrick BalestraPatrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall!

@BalestraPatrick
Copy link
Copy Markdown
Member

@luispadron If you fix the buildifier errors and regenerate the docs we should be good to go.

Copy link
Copy Markdown
Contributor

@louwers louwers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The (lack of) Objective-C support should be documented.

@luispadron
Copy link
Copy Markdown
Contributor Author

luispadron commented Aug 16, 2023

@luispadron If you fix the buildifier errors and regenerate the docs we should be good to go.

@BalestraPatrick Thanks for the review! I'm going to add some tests before I un-draft it this month and update documentation.

@louwers I'd love to add Objective-C support, I'll see if I can spend time looking at it more, if not will update docs to note as such.

@luispadron luispadron force-pushed the lpadron/add-bazel-docc-support branch 2 times, most recently from c418a68 to 76166de Compare August 17, 2023 19:24
@luispadron luispadron marked this pull request as ready for review August 17, 2023 19:24
@luispadron luispadron requested a review from jszumski August 17, 2023 19:24
@luispadron
Copy link
Copy Markdown
Contributor Author

Added tests and documentation, think this is ready for initial support for .doccarchive once we get enough reviews.

@luispadron luispadron force-pushed the lpadron/add-bazel-docc-support branch 2 times, most recently from a3a2d82 to 488d074 Compare August 17, 2023 19:51
@luispadron luispadron requested a review from louwers August 17, 2023 21:06
@luispadron luispadron force-pushed the lpadron/add-bazel-docc-support branch 2 times, most recently from 1f217fd to 9b0bb58 Compare August 21, 2023 15:01
@luispadron luispadron closed this Aug 21, 2023
@luispadron luispadron force-pushed the lpadron/add-bazel-docc-support branch from 9b0bb58 to 7a25733 Compare August 21, 2023 15:02
@luispadron luispadron reopened this Aug 21, 2023
@luispadron luispadron force-pushed the lpadron/add-bazel-docc-support branch 3 times, most recently from 160d9ef to 0a2f2af Compare August 22, 2023 21:37
@brentleyjones
Copy link
Copy Markdown
Collaborator

@jpsim I know you had interest in this before. Pinging for visibility.

@luispadron luispadron force-pushed the lpadron/add-bazel-docc-support branch from 0a2f2af to be812fd Compare September 7, 2023 17:16
@brentleyjones brentleyjones merged commit 11471c5 into bazelbuild:master Sep 7, 2023

This aspect works with targets that have a .docc bundle in their data, or which bundle a target that does.
""",
attr_aspects = ["data", "deps"],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if need private_deps here too

arguments.add(docc_bundle_info.bundle)

# TODO: no-sandbox seems to be required when running docc convert with a .docc bundle provided
# in the sandbox the tool is unable to open the .docc bundle.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is likely expected (we do the same with some other Xcode tools IIRC), but do you remember what exactly was the error in this particular situation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont have the exact error but essentially the .docc bundle was missing from the sandbox so it would fail along the lines of "bundle not found"

@jpsim
Copy link
Copy Markdown
Contributor

jpsim commented Sep 13, 2023

Thanks for adding this, @luispadron 🙏

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DocC Rule

7 participants