-
Notifications
You must be signed in to change notification settings - Fork 14
Reboot #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Reboot #24
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
54a14a6
Upgrade bindgen
youknowone ccca782
edition 2024
youknowone 717c1dc
restructure workspace and add prebuilt bindings
youknowone 4d7a2f5
fix ci
youknowone e215b2d
fix fraction parameter collision and missing TWRequestMethod type alias
youknowone b1bb01e
handle multi-line msg_send! blocks in fix_msg_send_type_collisions
youknowone c39cc42
convert cross-framework pub use self aliases to type aliases and fix …
youknowone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Project Overview | ||
|
|
||
| apple-sys is a Rust FFI bindings generator for Apple frameworks. It provides auto-generated bindgen bindings for 200+ Apple frameworks (CoreFoundation, UIKit, AVFoundation, AppKit, etc.) across macOS and iOS platforms. | ||
|
|
||
| The workspace contains four crates: | ||
| - **crates/apple-sys/** - The main `apple-sys` crate with feature-gated bindings for 200+ Apple frameworks | ||
| - **crates/apple-bindgen/** - The `apple-bindgen` CLI tool and library for generating framework bindings | ||
| - **crates/apple-sys-prebuilt-macosx/** - Pre-generated macOS bindings for faster builds without local SDK | ||
| - **crates/apple-sys-prebuilt-iphoneos/** - Pre-generated iOS bindings for `prebuilt` builds targeting iOS | ||
|
|
||
| ## Build Commands | ||
|
|
||
| ```bash | ||
| # Build with specific framework features | ||
| cargo build --manifest-path=crates/apple-sys/Cargo.toml --features CoreFoundation,IOKit | ||
|
|
||
| # Build for iOS | ||
| cargo build --target=aarch64-apple-ios --manifest-path=crates/apple-sys/Cargo.toml --features UIKit | ||
| ``` | ||
|
|
||
| ## apple-bindgen CLI | ||
|
|
||
| ```bash | ||
| # Generate bindings for a framework | ||
| cargo run --features=bin --manifest-path=crates/apple-bindgen/Cargo.toml -- generate CoreFoundation --sdk macosx | ||
|
|
||
| # Analyze framework dependencies | ||
| cargo run --features=bin --manifest-path=crates/apple-bindgen/Cargo.toml -- analyze-deps AppKit --sdk macosx | ||
| ``` | ||
|
|
||
| ## Testing | ||
|
|
||
| ```bash | ||
| # Run bindgen crate tests | ||
| cargo test --manifest-path=crates/apple-bindgen/Cargo.toml | ||
|
|
||
| # Run a single test | ||
| cargo test --manifest-path=crates/apple-bindgen/Cargo.toml generate_core_foundation | ||
|
|
||
| # Verify a framework builds (macOS) | ||
| cargo build --manifest-path=crates/apple-sys/Cargo.toml --features AGL | ||
|
|
||
| # Verify a framework builds (iOS) | ||
| cargo build --target=aarch64-apple-ios --manifest-path=crates/apple-sys/Cargo.toml --features ARKit | ||
| ``` | ||
|
|
||
| ## Formatting | ||
|
|
||
| ```bash | ||
| cargo fmt | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### Generation Pipeline | ||
|
|
||
| 1. User enables frameworks via Cargo features (feature names match framework names) | ||
| 2. `crates/apple-sys/build.rs` reads enabled features and calls `apple_bindgen::Builder` for each | ||
| 3. Builder loads configuration from `crates/apple-bindgen/Bindgen.toml` (opaque types, blocklists, replacements) | ||
| 4. Generates Rust FFI bindings via bindgen from Apple SDK headers | ||
| 5. Post-processes bindings with regex replacements to fix name collisions and Objective-C quirks | ||
| 6. Writes `{framework}.rs` files to `OUT_DIR` | ||
| 7. `crates/apple-sys/src/lib.rs` includes generated files conditionally per target OS and features | ||
|
|
||
| ### Key Files | ||
|
|
||
| - `crates/apple-bindgen/Bindgen.toml` - Framework-specific bindgen rules (replacements for name collisions, opaque types, deps) | ||
| - `crates/apple-bindgen/src/deps/` - Dependency analysis module (type extraction, ownership, symbol isolation) | ||
| - `crates/apple-sys/build.rs` - Build script that orchestrates binding generation with ownership-based deduplication | ||
| - `crates/apple-sys/configure.py` - Python script to regenerate lib.rs, Cargo.toml, and platform includes from Xcode SDKs | ||
|
|
||
| ### Bindgen.toml Configuration | ||
|
|
||
| The config file handles: | ||
| - **opaque_types**: Types to make opaque (workarounds for bindgen bugs) | ||
| - **replacements**: Regex-like fixes for Foundation/AppKit/UIKit name collisions (e.g., `timezone` → `timezone_`) | ||
| - **deps**: Framework dependencies (e.g., Quartz depends on PDFKit) | ||
| - **impl_debugs**: Types needing manual Debug impl | ||
|
|
||
| ### Dependency Isolation | ||
|
|
||
| The build.rs pipeline automatically deduplicates symbols across frameworks using an ownership-based approach: | ||
| 1. Scans SDK framework headers to build a global ownership map (symbol → owning framework) | ||
| 2. Computes unique symbols per framework via topological ordering and dependency closure | ||
| 3. Filters generated bindings to only include each framework's unique symbols | ||
| 4. Earlier frameworks (in topological order) are imported via `use crate::FrameworkName::*` | ||
|
|
||
| ## Contributing | ||
|
|
||
| This project manages bindgen rules, not generated code. Changes go in `crates/apple-bindgen/Bindgen.toml` for framework-specific fixes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,16 @@ | ||
| [workspace] | ||
| resolver = "2" | ||
| resolver = "3" | ||
| members = [ | ||
| "sys", | ||
| "bindgen", | ||
| "crates/apple-sys", | ||
| "crates/apple-bindgen", | ||
| "crates/apple-sys-prebuilt-macosx", | ||
| "crates/apple-sys-prebuilt-iphoneos", | ||
| ] | ||
|
|
||
| [workspace.package] | ||
| edition = "2024" | ||
| version = "0.3.0" | ||
| authors = ["Jeong YunWon <jeong@youknowone.org>"] | ||
| repository = "https://github.com/youknowone/apple-sys/" | ||
| license = "BSD-2-Clause" | ||
| readme = "README.md" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.