Skip to content

fix: link CoreGraphics framework for Metal device detection#78

Merged
evilsocket merged 1 commit into
evilsocket:mainfrom
aupadhyay:fix/metal-coregraphics-linkage
Apr 5, 2026
Merged

fix: link CoreGraphics framework for Metal device detection#78
evilsocket merged 1 commit into
evilsocket:mainfrom
aupadhyay:fix/metal-coregraphics-linkage

Conversation

@aupadhyay

Copy link
Copy Markdown
Contributor

Summary

cake chat panics on a fresh macOS clone with --features metal:

swap_remove index (is 0) should be < len (is 0)
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: alloc::vec::Vec<T,A>::swap_remove::assert_failed
   3: candle_core::metal_backend::<impl candle_core::backend::BackendDevice for candle_core::metal_backend::device::MetalDevice>::new
   4: cake_core::utils::get_inference_device
   5: cake_core::cake::Context::from_args
   6: cake::main::{{closure}}
   7: tokio::runtime::runtime::Runtime::block_on
   8: cake::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
zsh: abort      RUST_BACKTRACE=1 ./target/release/cake chat Qwen/Qwen3-0.6B

Fix

  • The call chain leads us to candle_core and candle-metal-kernels lines 50-55 which calls MTLCreateSystemDefaultDevice() and collects into a Vec.

  • MTLCreateSystemDefaultDevice() returns None because CoreGraphics is not linked. Documented requirement in objc2-metal (see objc2-metal/src/lib.rs lines 14-16):

    NOTE: To use MTLCreateSystemDefaultDevice you need to link to CoreGraphics

  • candle-metal-kernels doesn't add this linkage, and neither does cake

  • One line fix in cake-core/build.rs

  • Verified chat works on metal after fix

MTLCreateSystemDefaultDevice() returns None when CoreGraphics is not
linked, causing a panic (swap_remove on empty vec) during Metal device
initialization. This affects fresh clones on macOS where nothing else
pulls in CoreGraphics.
@evilsocket
evilsocket merged commit 3870042 into evilsocket:main Apr 5, 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.

2 participants