Skip to content

fix: link CoreGraphics framework for Metal device detection#78

Open
aupadhyay wants to merge 1 commit intoevilsocket:mainfrom
aupadhyay:fix/metal-coregraphics-linkage
Open

fix: link CoreGraphics framework for Metal device detection#78
aupadhyay wants to merge 1 commit intoevilsocket:mainfrom
aupadhyay:fix/metal-coregraphics-linkage

Conversation

@aupadhyay
Copy link

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.
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.

1 participant