Skip to main content

mtl_sys/
lib.rs

1//! Low-level Objective-C runtime bindings for Metal.
2//!
3//! This crate provides the foundational FFI layer for communicating with
4//! the Objective-C runtime. It includes:
5//!
6//! - Architecture-aware message sending (`objc_msgSend` variants)
7//! - Selector and class caching
8//! - Objective-C block support (Clang ABI)
9//! - Custom macros for enums and bitflags
10//!
11//! # Safety
12//!
13//! This crate is intentionally unsafe. All public functions are marked
14//! `unsafe` and require the caller to uphold Objective-C runtime invariants.
15//! Higher-level safe wrappers are provided by the `metal` crate.
16
17#![allow(non_upper_case_globals)]
18#![allow(non_camel_case_types)]
19
20mod block;
21mod functions;
22mod macros;
23mod msg_send;
24mod runtime;
25
26// Re-export runtime types
27pub use runtime::{CachedClass, CachedSel, Class, MethodDescription, Protocol, Sel, get_protocol};
28
29// Re-export message sending functions
30pub use msg_send::{
31    msg_send_0, msg_send_1, msg_send_2, msg_send_3, msg_send_4, msg_send_5, msg_send_6, msg_send_7,
32    msg_send_8, msg_send_9, msg_send_10,
33};
34
35// Re-export block types
36pub use block::{
37    BlockLiteral, CommandBufferHandler, DeallocatorBlock, DeviceNotificationHandler,
38    DrawablePresentedHandler, EventBlock, HeapOneArgBlock, LogHandlerBlock,
39    NewComputePipelineStateCompletionHandler,
40    NewComputePipelineStateWithReflectionCompletionHandler, NewLibraryCompletionHandler,
41    NewRenderPipelineStateCompletionHandler, NewRenderPipelineStateWithReflectionCompletionHandler,
42    OneArgBlock, RcBlock, SharedEventNotificationHandler, ThreeArgBlock, TwoArgBlock, VoidBlock,
43};
44
45// Re-export Metal C functions
46pub use functions::{
47    DeviceObserver, IOCompressionContext, IOCompressionMethod, IOCompressionStatus,
48    MTLCreateSystemDefaultDevice, MTLIOCompressionContextAppendData,
49    MTLIOCompressionContextDefaultChunkSize, MTLIOCreateCompressionContext,
50    MTLIOFlushAndDestroyCompressionContext, create_system_default_device,
51    io_compression_default_chunk_size,
52};
53
54#[cfg(target_os = "macos")]
55pub use functions::{
56    MTLCopyAllDevices, MTLCopyAllDevicesWithObserver, MTLRemoveDeviceObserver, copy_all_devices,
57};