Apple platforms for MoonBit: macOS, iOS, tvOS, watchOS, visionOS, and Mac Catalyst. Generated packages cover the system frameworks. A hand-written runtime supplies objects, blocks, and a scoped lock around calls into the Objective-C runtime.
./scripts/objc2-build.sh is the entry point: generate, check, test, build, run, bundle, and pack. ./scripts/ci.sh is the full gate. ./scripts/new-app.sh scaffolds an example. Commands and invariants are in AGENTS.md.
Frameworks are generated from the Apple SDK. The layering follows the Rust objc2 project: a runtime, a generated raw layer, and a typed overlay where strings and errors should be MoonBit values. The deployment floor is enforced by scripts/min-os.env. An API newer than that floor fails with CocoaError instead of crashing.
examples/hello is a headless Foundation smoke test. It builds a string, a data blob, and an array:
fn main {
let hello = @Foundation.NSString::of("hello, objc2")
println("length=\{hello.length()} text=\{hello.to_string()}")
let data = @Foundation.NSData::from_bytes(b"objc2")
println("bytes=\{data.length()}")
let arr = @Foundation.NSArray::of([hello])
println("count=\{arr.count()}")
}examples/showcase opens a window with AppKit controls and a Metal view. examples/menubar is a menu-bar app. examples/counter and examples/habits are small interactive apps.
Objc2Runtime is the runtime: objects, blocks, dispatch, and errors. Generated framework packages are the raw selectors and C functions. Typed helpers, such as NSString::of, accept and return MoonBit strings.
Most top-level framework directories are generated bindings linked from the generated/ submodule (opraying/mbt-generated, branch objc2). Focus edits on the hand-written core and generator:
- Objc2Encode/ — Objective-C type encoding (
@encode). - Objc2Runtime/ — runtime spine: objects, blocks, class declaration,
CocoaError, and async bridges. - Objc2Tools/ — libclang IR parser and MoonBit/Objective-C binding generator (
TRANSLATOR.md). - Darwin/, Dispatch/, and Sqlite3/ — hand-written Libsystem/Mach, GCD, and SQLite wrappers.
- Primary typed overlays (non-
*.generated.*files): Foundation/, AppKit/, UIKit/, CoreFoundation/, CoreGraphics/, CoreText/, CoreVideo/, IOSurface/, QuartzCore/, Security/, Network/. - scripts/ — build/CI entry points (
objc2-build.sh,prebuild.mjs,min-os.env).
MoonBit's native reference-counting runtime uses a scoped GIL (Objc2Runtime) and must never be entered from a Mach real-time thread (THREAD_TIME_CONSTRAINT_POLICY, such as a CoreAudio / AudioUnit render callback). Call @Objc2Runtime.is_realtime_thread() to detect real-time threads, keep audio/DSP render callbacks in lock-free C/ObjC, and set OBJC2_ABORT_ON_RT_GIL=1 during testing to fail loudly if any callback attempts to acquire the MoonBit GIL on a real-time thread.
Apache-2.0. Copyright the opraying contributors.