Skip to content

ObjC: replace libffi with an owned native ABI dispatcher #463

Description

@chrisbbreuer

Parent: #459
Depends on: #462

Goal

Remove the Objective-C bridge's libffi dependency and implement the required native-call ABI machinery in zig-utils-owned Zig/assembly code.

Today src/objc_bridge.m includes <ffi/ffi.h> and Objective-C bridge tests link -lffi. This violates the owned-dependency target even though the core engine is pure Zig.

Scope

  • Inventory every Objective-C/block signature the pinned macOS bridge profile accepts: integer widths/signs, floats, doubles, pointers/objects/selectors/classes, void, and supported struct returns/arguments (CGPoint, CGSize, CGRect, NSRange, including ABI classification).
  • Define a stable Zig call descriptor and architecture-specific lowering for supported macOS AArch64 and x86-64 ABIs.
  • Preserve block invocation, exported-method dispatch, exceptions, autorelease/lifetime behavior, reentrancy, recursive/cyclic Foundation conversion, and failure injection.
  • Reject unsupported encodings explicitly before invocation; do not silently reinterpret, truncate, or route through a slower foreign library.
  • Keep Foundation/Objective-C as the platform API being implemented, not as a source of JavaScript execution.

No-workaround rules

  • Do not vendor or dynamically load libffi.
  • Do not shell out, use generated C trampolines per call, restrict the published profile to avoid hard signatures, or retain a hidden -lffi fallback.
  • Do not use undefined Zig calling-convention/layout behavior; ABI conformance needs byte-level fixtures.

Acceptance

  • No ffi/ffi.h, ffi_*, -lffi, or linkSystemLibrary("ffi") remains.
  • Header, runtime, lifetime, sanitizer, and fault-injection Objective-C suites pass on every declared macOS architecture.
  • Differential transcripts against the pinned system JSC bridge remain exact.
  • ABI fixtures cover register/stack splits, alignment, mixed scalar/struct signatures, return conventions, exceptions, and nested/reentrant calls.
  • The owned dispatcher has focused microbenchmarks and does not regress bridge call throughput by more than the accepted noise gate.

Foundation

The completed bridge inventory and semantics are tracked by #138 and its children; preserve that contract exactly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    dependenciesDependency ownership and offline build policyembeddingZig, C, private ABI, and Objective-C embeddingenhancementNew feature or requestperformanceMeasured runtime, memory, scaling, or build performance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions