Skip to content

Support SwiftPM and add Swift bindings for v6#2958

Draft
Lancelotbronner wants to merge 2 commits into
capstone-engine:nextfrom
Lancelotbronner:next
Draft

Support SwiftPM and add Swift bindings for v6#2958
Lancelotbronner wants to merge 2 commits into
capstone-engine:nextfrom
Lancelotbronner:next

Conversation

@Lancelotbronner

Copy link
Copy Markdown

Your checklist for this pull request

  • I've documented or updated the documentation of every API function and struct this PR changes.
  • I've added tests that prove my fix is effective or that my feature works (if possible)

Detailed description

I'm depending on capstone v6 for a macOS app prototype, as such I need Swift bindings and integration into SwiftPM.

While there is already another PR that did so, it seemed extremely intrusive to capstone, attempting to force it into SwiftPM's default convention rather than configuring SwiftPM appropriately.

Here are my changes to support building capstone with SwiftPM:

  • Add Package.swift, the capstone target builds capstone
    • It emits "unknown build rule" for each .inc file, they can be manually added to exclude to avoid them but I didn't feel like doing that yet.
  • Add module.modulemap, this is needed by Clang as part of Xcode's build system

Here are my changes to add (nice, safer) Swift bindings:

  • In Package.swift, the CapstoneKit target wraps capstone where possible.
  • Add Capstone.apinotes, a sidecar file that provides Clang with additional information and renames to make the automatically generated Swift bindings more "Swifty". It's very incomplete and some parts could likely be script-generated. See Clang's documentation. See Swift's extensions.
  • Add bindings/swift/CapstoneKit.swift with a few work-in-progress wrapper types

Test plan

All Capstone.apinotes bindings are automatically generated by Swift.
There is no need to separately test them.

Only the APIs in bindings/swift need to be tested, and I'm using them in my prototype.

@Lancelotbronner Lancelotbronner marked this pull request as draft June 7, 2026 21:47
@Lancelotbronner Lancelotbronner changed the title [Draft] Support SwiftPM and add Swift bindings for v6 Support SwiftPM and add Swift bindings for v6 Jun 7, 2026
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.

1 participant