Skip to content

docs: add usage guides for WITOverlayGenerator and WITExtractor#343

Open
shivanshu877 wants to merge 2 commits into
swiftwasm:mainfrom
shivanshu877:docs/71-wit-tools-usage
Open

docs: add usage guides for WITOverlayGenerator and WITExtractor#343
shivanshu877 wants to merge 2 commits into
swiftwasm:mainfrom
shivanshu877:docs/71-wit-tools-usage

Conversation

@shivanshu877
Copy link
Copy Markdown

Addresses the two open items in #71 ("Enhance documentation"):

  • Example and usage of WITOverlayGenerator
  • Example and usage of WITExtractor

Both documents are derived from reading the source of the respective modules (WITOverlayGen.swift, WITExtractor.swift) and their SPM plugins (WITOverlayPlugin, WITExtractorPlugin).

The intent is the same as the existing module docs in WasmKit's docc bundle — make the WIT tooling discoverable for users coming from outside the project.

Test plan

  • Docs build cleanly with the existing docc setup.
  • A maintainer review on the prose / accuracy is welcome — I worked from the source, but anyone closer to the API will see corner cases I missed.

Addresses the two open items in issue swiftwasm#71 ("Enhance documentation"):
- Example and usage of WITOverlayGenerator
- Example and usage of WITExtractor

Both documents are derived from the source code of the respective
modules (WITOverlayGen.swift, WITExtractor.swift) and their SPM
plugins (WITOverlayPlugin, WITExtractorPlugin).
For scripted use, call the `extract-wit` subcommand directly:

```sh
swift run wit-tool extract-wit \
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.

It doesn't look like these instructions were verified end-to-end, or at least not verified with the state of the repository as I see it? swift run wit-tool won't work. This will fail with error: no executable product named wit-tool

Suggested change
swift run wit-tool extract-wit \
swift run WITTool extract-wit \


```swift
// Sources/MathLib/MathLib.swift
public struct Vector2 {
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.

IIRC WITExtractor only extracts decls with @_spi(WIT) on them.

swift run wit-tool extract-wit \
--swift-api-digester $(xcrun --find swift-api-digester) \
--module-name MyLibrary \
--package-name my-library \
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.

the plugin form only accepts --target, --sdk, --output-mapping. It auto-derives the WIT package name from context.package.displayName. This snippet conflates the plugin and the CLI

Three issues:
1. CLI executable name was wrong — `wit-tool` doesn't exist; the
   Package.swift declares `WITTool`. Changed `swift run wit-tool` to
   `swift run WITTool`.
2. End-to-end example mixed the plugin form (`--target`) with the CLI
   `--package-name` arg. The plugin only accepts `--target`, `--sdk`,
   and `--output-mapping`, and auto-derives the WIT package name from
   `context.package.displayName`. Reworked the "Running…" snippet to
   use the plugin form properly, with a parenthetical pointing at the
   CLI form for callers that need to override the package name.
3. WITExtractor only extracts declarations annotated with
   `@_spi(WIT)` (confirmed in `Sources/WITExtractor/SourceSummary.swift`
   line 221). Added a note in the "When to use it" section and applied
   `@_spi(WIT)` to the example's `Vector2` and `addVectors`.
@shivanshu877
Copy link
Copy Markdown
Author

Thanks @MaxDesiatov — all three addressed in ef224eb:

  1. swift run wit-toolswift run WITTool (verified WITTool is the actual executable name in Package.swift).
  2. End-to-end example no longer conflates plugin and CLI. Reworked the "Running…" snippet to use the plugin form (swift package plugin extract-wit --target MathLib) with a parenthetical pointing at the CLI form for callers that need to override the package name.
  3. Documented the @_spi(WIT) opt-in requirement. Added a callout in the "When to use it" section explaining only @_spi(WIT)-annotated declarations are extracted, and applied @_spi(WIT) to the example's Vector2 and addVectors so the snippet actually produces the WIT shown below it (verified against Sources/WITExtractor/SourceSummary.swift line 221: guard let spiGroup = decl.body.spi_group_names, spiGroup.contains(\"WIT\") else { return false }).

Ready for re-review.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants