Files
diviocityandAlexander Medvednikov cc240baa64 gg, macos: fix default Metal shaders and Intel NSRect returns (#31217)
* macos: use objc_msgSend_stret for struct returns on x86_64

macos_objc_msg_rect dispatched every -[NSView bounds] style message
through plain objc_msgSend. On Apple Silicon the 32-byte NSRect comes
back in registers, so that worked; on Intel a structure this size is
answered through memory, which only objc_msgSend_stret does. Calling
plain objc_msgSend shifted every argument by the hidden return-slot
pointer and crashed at the first rect query, for example ui2's
native_bounds during applicationDidFinishLaunching on an Intel Mac.

macos_point and macos_range fit in registers on both architectures and
keep the direct call.

* gg: fail with a clear message when macOS has no Metal device

On macOS, sokol's Metal backend asserts when gfx.setup gets no device. That
happens in virtual machines without GPU access, where MTLCreateSystemDefaultDevice
returns nil. Check for the device first and panic with a message that names the
cause.

* gg: document the default macOS Metal device requirement

* gg: select Metal shaders for the default macOS backend

---------

Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>
2026-10-26 23:48:54 +03:00
..

macos

The macos module provides typed access to the Objective-C runtime on macOS. It includes Objective-C object, selector, rectangle, point, and range types together with typed message senders.

Choose the message sender whose return and argument types exactly match the Objective-C method. For example:

import macos

value := macos.msg_id_range(
	macos.get_class('NSValue'),
	'valueWithRange:',
	macos.range(2, 5),
)
result := macos.msg_range(value, 'rangeValue')
println('${result.location}, ${result.length}')

The typed senders hide the platform-specific objc_msgSend casts. Framework-specific methods still require the corresponding #flag darwin -framework ... declaration in the importing program.

The bridge supports the bundled TCC on older macOS SDKs whose runtime headers expose an unguarded Blocks declaration. Blocks-based runtime APIs still require a C compiler with Blocks support.