apple-cf
Safe, dependency-free Rust bindings for Apple's shared Core* frameworks — the foundation underneath the doom-fish macOS Rust suite.
Status:
v0.7.1tightens the safety documentation — everyunsafe impl Send/Syncnow carries a// SAFETY:justification comment, Drop implementations uniformly null-guard their release calls, and thedoom-fish-utilsversion constraint follows the crate-family>=X.Y, <X.(Y+2)convention. SeeCOVERAGE.mdfor the framework summary andCOVERAGE_AUDIT_V2.mdfor the full symbol audit.
What's in the box
| Module | Framework | Feature flag | Status |
|---|---|---|---|
cf |
CoreFoundation values, collections, property lists, locale/formatter helpers, runtime primitives | — | ✅ |
raw |
Exhaustive low-level CoreFoundation/CoreMedia/CoreVideo/IOSurface/Dispatch bindings | — | ✅ |
cg |
CoreGraphics value types + bitmap drawing wrappers | cg |
✅ |
iosurface |
IOSurface (zero-copy GPU buffers, multi-planar formats) | iosurface |
✅ |
dispatch_queue |
Dispatch queues, async/apply helpers, groups, semaphores, timer sources | dispatch |
✅ |
cm |
CMTime, CMTimeRange, CMTimebase, CMSampleBuffer, CMBlockBuffer, CMFormatDescription, CMMetadataFormatDescription |
cm |
✅ |
cv |
CVBuffer, CVImageBuffer, CVPixelBuffer, CVPixelBufferPool, CVMetalTextureCache |
cv |
✅ |
utils |
Shared FFI helpers (always on) | — | ✅ |
Why this crate exists
Every doom-fish crate that wraps a media-adjacent Apple framework needs the same primitives — CFString, CGRect, CVPixelBuffer, IOSurface, dispatch queues, time values. Instead of re-vendoring those inside every crate (and drifting), this crate owns them once.
Safe Rust wrappers
├── CoreFoundation / Dispatch / CoreMedia / CoreVideo ergonomic APIs
├── exhaustive raw C bindings in `apple_cf::raw`
├── direct C FFI for value-only primitives where appropriate
└── Swift @_cdecl bridge for reference-counted / callback-heavy surfaces
Requirements
- macOS 13.0+
- Xcode toolchain (Swift 5.9+); Command Line Tools alone is not enough —
xcrun --sdk macosx --show-sdk-versionmust succeed - Apple Silicon or Intel Mac
Installation
[]
= "0.7"
Or pick only the frameworks you need:
[]
= { = ">=0.7, <0.9", = false, = ["cg", "cm", "cv", "dispatch", "iosurface"] }
Quick examples
Build CoreFoundation values and collections
use ;
let first = new;
let second = new;
let array = from_values;
assert_eq!;
Create a timer-backed dispatch source
use DispatchSource;
use thread;
use Duration;
let source = timer;
source.resume;
sleep;
source.cancel;
assert!;
Allocate an IOSurface-backed CVPixelBuffer
use CVPixelBuffer;
let pixel_buffer = create
.expect;
assert_eq!;
Architecture
This crate uses the same Swift-bridge pattern as the rest of the doom-fish crates:
swift-bridge/Sources/<Framework>Bridge/exposes thin@_cdeclentry pointssrc/ffi/*.rsdeclares the matchingextern "C"bindingssrc/<framework>/provides the safe Rust API on top
The Rust crate has zero runtime dependencies.
Examples and tests
This release ships 15 numbered examples plus dedicated smoke tests for:
- CoreFoundation primitives, collections, property lists, resources, runtime helpers
- Dispatch queues,
dispatch_async,dispatch_async_and_wait,dispatch_apply, groups, semaphores, timer sources, and raw main-queue access CMTimeRange,CMTimebase,CMMetadataFormatDescription, and low-levelCMTag/CMSynccoverage throughapple_cf::rawCVBuffer,CVImageBuffer,CVPixelBuffer,CVMetalTextureCache, and the remaining CVMetal entry points throughapple_cf::raw- Exhaustive low-level constants / inline helpers surfaced by
apple_cf::raw
CVDisplayLink remains exempt in the audit because Apple deprecated the family on macOS 15.
License
Licensed under either of Apache-2.0 or MIT at your option.