Skip to content

BR-3: macOS Mach-O bridge — reld links via ld64.lld (rust-lld) #29

Closed

Description

@zackees

Part of #17 (phase BR-3, adapted to the bridge strategy). Follows BR-1 (#20, Windows COFF bridge).

Goal

Make reld link a real program on macOS / aarch64-apple-darwin by delegating Mach-O links to ld64.lld (the Mach-O driver in rust-lld), exactly as BR-1 did for Windows/COFF. This completes the "runs everywhere" promise (Linux native + Windows bridge + macOS bridge). Native Mach-O codegen (the wild skeleton, #8) remains a separate, later effort; the bridge makes macOS work now.

Design — generalize the existing bridge to be format-aware

Today crates/reld-core/src/bridge.rs is COFF-only: it discovers lld-link and prepends -flavor link for rust-lld. Generalize it to a target format:

  • Introduce a BridgeTarget { Coff, MachO } (or reuse PlatformKind) passed into run_bridge/discover_linker.
  • COFF: discover lld-link (rust-lld -flavor link, then gcc-ld/lld-link, then PATH) — unchanged behavior.
  • Mach-O: discover ld64.lld (rust-lld -flavor darwin, then gcc-ld/ld64.lld, then ld64.lld on PATH). RELD_BRIDGE_LINKER override still honored; if it resolves to rust-lld, prepend the target's flavor (link vs darwin).
  • Route Mach-O to the bridge: add pub fn is_macho(&self) on Args, and in crates/reld/src/main.rs route if args.is_coff() || args.is_macho() { return reld_core::run_bridge(std::env::args_os(), <target>); } BEFORE args.parse(). Keep ELF untouched. Leave the Args::MachO(_) => ... skeleton dispatch in lib.rs as a defensive fallback.
  • Keep exit-code propagation and the -flavor de-duplication from BR-1 intact for both formats.

macOS CI e2e (mirror BR-2)

Add a macos-arm64 step to phase1-native in .github/workflows/ci.yml that builds ci/e2e/sqlite-bridge with reld as the linker and runs it (OK, exit 0). Key subtlety: on macOS rustc invokes the linker via the cc driver by default, which passes clang-driver args, NOT ld64 args. To hand reld the ld64-native argv it forwards to ld64.lld, the build must select a direct ld64 linker flavor (research the exact rustc 1.94 spelling — likely -C linker-flavor=ld64 via CARGO_TARGET_AARCH64_APPLE_DARWIN_RUSTFLAGS, plus CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER=<reld>). ld64.lld performs ad-hoc signing itself, so D6 is deferred, not solved.

Verification

  • Windows (local, regression): the COFF bridge must be unchanged — ci/e2e/sqlite-bridge still links via reld and runs.
  • Unit tests: discovery + flavor selection for both Coff and MachO (hermetic, temp files; no real linker spawned).
  • macOS (CI): the new macos-arm64 e2e step is the real proof — it runs on the runner's ld64.lld (brew llvm@18, already installed in CI).

Done when

reld links + runs ci/e2e/sqlite-bridge on the macos-arm64 CI runner; the Windows COFF bridge and ELF paths are unchanged (their e2e/CI stay green); unit tests cover both formats; PR merged, issue closed, branch rebased on origin/main.

Activity

  1. added
    enhancement
    on Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions