Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
81 changes: 55 additions & 26 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ env:

jobs:
bindgen:
runs-on: macos-latest
runs-on: macos-26
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Test
run: cargo test --manifest-path=bindgen/Cargo.toml --verbose
run: cargo test --manifest-path=crates/apple-bindgen/Cargo.toml --verbose
- name: Tool
run: cargo run --features=bin --manifest-path=bindgen/Cargo.toml --verbose CoreFoundation --sdk macosx
run: cargo run --features=bin --manifest-path=crates/apple-bindgen/Cargo.toml --verbose -- generate CoreFoundation --sdk macosx

sys-macos:
strategy:
matrix:
feature: [
AGL,
AVFAudio,
AVFoundation,
AVKit,
Expand All @@ -34,7 +33,6 @@ jobs:
AdServices,
AdSupport,
AddressBook,
AppIntents,
AppKit,
AppTrackingTransparency,
AppleScriptKit,
Expand Down Expand Up @@ -78,7 +76,6 @@ jobs:
CoreSpotlight,
CoreTelephony,
CoreText,
CoreTransferable,
CoreVideo,
CoreWLAN,
CryptoTokenKit,
Expand All @@ -93,7 +90,6 @@ jobs:
ExceptionHandling,
ExecutionPolicy,
ExposureNotification,
ExtensionFoundation,
ExtensionKit,
ExternalAccessory,
FileProvider,
Expand All @@ -110,7 +106,6 @@ jobs:
HealthKit,
Hypervisor,
ICADevices,
IMServicePlugIn,
IOBluetooth,
IOBluetoothUI,
IOKit,
Expand All @@ -124,12 +119,9 @@ jobs:
InstantMessage,
Intents,
IntentsUI,
JavaNativeFoundation,
JavaRuntimeSupport,
JavaScriptCore,
Kerberos,
KernelManagement,
LDAP,
LatentSemanticMapping,
LinkPresentation,
LocalAuthentication,
Expand Down Expand Up @@ -219,11 +211,56 @@ jobs:
iTunesLibrary,
vmnet
]
runs-on: macos-latest
runs-on: macos-26
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build
run: cargo build --manifest-path=sys/Cargo.toml --verbose --features ${{ matrix.feature }}
run: cargo build --manifest-path=crates/apple-sys/Cargo.toml --verbose --features ${{ matrix.feature }}

prebuilt-examples:
runs-on: macos-26
steps:
- uses: actions/checkout@v4
- name: Build examples
run: >
cargo build --manifest-path=crates/apple-sys/Cargo.toml
--no-default-features
--features "prebuilt,
AVFAudio,AVFoundation,AVKit,AVRouting,Accelerate,Accessibility,Accounts,
AdServices,AdSupport,AddressBook,AppKit,AppTrackingTransparency,AppleScriptKit,
AppleScriptObjC,ApplicationServices,AudioToolbox,AudioUnit,AudioVideoBridging,
AuthenticationServices,AutomaticAssessmentConfiguration,Automator,BackgroundAssets,
BackgroundTasks,BrowserEngineCore,BusinessChat,CFNetwork,CalendarStore,CallKit,
Carbon,Cinematic,ClassKit,CloudKit,Cocoa,Collaboration,ColorSync,Contacts,
ContactsUI,CoreAudio,CoreAudioKit,CoreBluetooth,CoreData,CoreFoundation,
CoreGraphics,CoreHaptics,CoreImage,CoreLocation,CoreMIDI,CoreML,CoreMedia,
CoreMediaIO,CoreMotion,CoreServices,CoreSpotlight,CoreTelephony,CoreText,
CoreVideo,CoreWLAN,CryptoTokenKit,DVDPlayback,DataDetection,DeviceCheck,
DeviceDiscoveryExtension,DirectoryService,DiscRecording,DiscRecordingUI,
DiskArbitration,EventKit,ExceptionHandling,ExecutionPolicy,ExtensionKit,
ExternalAccessory,FSKit,FileProvider,FileProviderUI,FinderSync,ForceFeedback,
Foundation,GLKit,GLUT,GSS,GameController,GameKit,GameSave,GameplayKit,
HealthKit,Hypervisor,ICADevices,IOBluetooth,IOBluetoothUI,IOKit,IOSurface,
IOUSBHost,IdentityLookup,ImageCaptureCore,ImageIO,InputMethodKit,InstallerPlugins,
InstantMessage,Intents,IntentsUI,JavaRuntimeSupport,JavaScriptCore,Kerberos,
LatentSemanticMapping,LinkPresentation,LocalAuthentication,
LocalAuthenticationEmbeddedUI,MLCompute,MailKit,MapKit,Matter,MediaAccessibility,
MediaExtension,MediaLibrary,MediaPlayer,MediaToolbox,Metal,MetalFX,MetalKit,
MetalPerformanceShaders,MetalPerformanceShadersGraph,MetricKit,ModelIO,
MultipeerConnectivity,NaturalLanguage,NearbyInteraction,NetFS,Network,
NetworkExtension,NotificationCenter,OSAKit,OSLog,OpenAL,OpenCL,OpenDirectory,
OpenGL,PCSC,PDFKit,PHASE,ParavirtualizedGraphics,PassKit,PencilKit,Photos,
PhotosUI,PreferencePanes,PushKit,Quartz,QuartzCore,QuickLook,QuickLookThumbnailing,
QuickLookUI,ReplayKit,SafariServices,SafetyKit,SceneKit,
ScreenSaver,ScreenTime,ScriptingBridge,Security,SecurityFoundation,
SecurityInterface,SecurityUI,SensitiveContentAnalysis,SensorKit,ServiceManagement,
SharedWithYou,SharedWithYouCore,ShazamKit,Social,SoundAnalysis,Speech,SpriteKit,
StoreKit,SwiftUI,Symbols,SyncServices,SystemConfiguration,SystemExtensions,
TWAIN,Tcl,ThreadNetwork,UniformTypeIdentifiers,UserNotifications,
UserNotificationsUI,VideoDecodeAcceleration,VideoSubscriberAccount,VideoToolbox,
Virtualization,Vision,WebKit,WidgetKit,iTunesLibrary,vmnet"
--examples

sys-ios:
strategy:
matrix:
Expand All @@ -236,13 +273,11 @@ jobs:
Accelerate,
Accessibility,
Accounts,
ActivityKit,
AdServices,
AdSupport,
AddressBook,
# AddressBookUI,
AppClip,
AppIntents,
AppTrackingTransparency,
AssetsLibrary,
AudioToolbox,
Expand Down Expand Up @@ -280,7 +315,6 @@ jobs:
CoreSpotlight,
CoreTelephony,
CoreText,
CoreTransferable,
CoreVideo,
CryptoTokenKit,
DataDetection,
Expand All @@ -289,7 +323,6 @@ jobs:
EventKit,
EventKitUI,
ExposureNotification,
ExtensionFoundation,
ExtensionKit,
ExternalAccessory,
FileProvider,
Expand Down Expand Up @@ -317,7 +350,6 @@ jobs:
MLCompute,
MapKit,
Matter,
MatterSupport,
MediaAccessibility,
MediaPlayer,
MediaSetup,
Expand All @@ -337,7 +369,6 @@ jobs:
NearbyInteraction,
Network,
NetworkExtension,
NewsstandKit,
NotificationCenter,
OSLog,
OpenAL,
Expand All @@ -348,14 +379,12 @@ jobs:
PencilKit,
Photos,
PhotosUI,
ProximityReader,
PushKit,
PushToTalk,
QuartzCore,
QuickLook,
QuickLookThumbnailing,
ReplayKit,
RoomPlan,
SafariServices,
SafetyKit,
SceneKit,
Expand Down Expand Up @@ -387,12 +416,12 @@ jobs:
WidgetKit,
iAd
]
runs-on: macos-latest
runs-on: macos-26
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: prepare iOS build
uses: dtolnay/rust-toolchain@stable
with:
target: aarch64-apple-ios
- name: Build
run: cargo build --target=aarch64-apple-ios --manifest-path=sys/Cargo.toml --verbose --features ${{ matrix.feature }}
run: cargo build --target=aarch64-apple-ios --manifest-path=crates/apple-sys/Cargo.toml --verbose --features ${{ matrix.feature }}
94 changes: 94 additions & 0 deletions CLAUDE.md
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.
16 changes: 13 additions & 3 deletions Cargo.toml
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"
Loading