Skip to content

EXAMPLE-ARCH: platform-* driver tier and abi-buf crate pattern#3

Merged
algesten merged 3 commits into
mainfrom
platform-drivers-and-abi-buf
Apr 21, 2026
Merged

EXAMPLE-ARCH: platform-* driver tier and abi-buf crate pattern#3
algesten merged 3 commits into
mainfrom
platform-drivers-and-abi-buf

Conversation

@lolgesten
Copy link
Copy Markdown
Collaborator

Summary

Two additions to EXAMPLE-ARCH.md prompted by building a mobile (iOS + Android) teleconferencing client on top of drv and hitting questions the doc didn't already answer.

1. platform-* driver tier. Shared primitives — UDP, HTTP, timers, keychain — that multiple domain drivers call into. Sit below domain drivers in the Cargo graph; cross-driver imports into them are expected. Three-tier dep rule added (state-*platform-*driver-*runtime). Guideline 8 gains a one-paragraph exception pointing at the new guideline 13.

Careful about the promotion criterion: called by multiple domain drivers, not wraps a platform API and not observed by many parts of the app. Singleton event-observed drivers (lifecycle, foreground/background) stay as regular driver-* even when cross-cutting.

2. Crossing the ABI: foreign-owned buffers. New top-level section covering Rust ↔ Swift / Kotlin byte-buffer ownership — the thing the original doc's terminal-editor example didn't hit. Picks Arc<[u8]> over Arc<Vec<u8>> / bytes::Bytes with reasoning, gives the RustBuf + rust_buf_free pattern for Rust → native, notes that native → Rust usually needs no refcount because the borrow is call-scoped, and carves out platform-typed GPU buffers (CVPixelBuffer, HardwareBuffer) as needing their own per-driver ABI rather than fitting in abi-buf. New guideline 14 codifies the abi-* crate prefix.

TOC renumbered (section 9 inserted; old 9→10, etc.). No existing guidelines removed or renumbered.

Test plan

  • Read the additions end-to-end for flow against existing sections
  • Check that the three-tier Cargo dep rule doesn't contradict any existing guidance
  • Spot-check anchor links in the updated TOC

🤖 Generated with Claude Code

algesten and others added 3 commits April 21, 2026 11:13
Two additions prompted by building out a mobile teleconferencing
client on top of drv where the original doc left gaps:

* A platform-* tier sitting below domain drivers in the Cargo graph,
  for primitives that multiple domain drivers actively call into
  (UDP, HTTP, timers, keychain). Cross-driver imports into these are
  expected; the isolation rule in guideline 8 is carved out for
  them. Criterion is "called by multiple domain drivers," not
  "wraps a platform API" — observed-by-many singletons like
  lifecycle stay as regular driver-*.

* A Crossing the ABI section covering foreign-owned byte buffers
  across Rust -> Swift / Kotlin. Arc<[u8]> picked over Arc<Vec<u8>>
  and bytes::Bytes, with the RustBuf / NativeBuf handoff pattern
  and the ownership invariant spelled out. Kept in its own abi-*
  tier separate from drivers since this is type contracts, not
  behaviour.

Two new guidelines (13, 14) codify both; guideline 8 gains a
one-paragraph exception note pointing at 13.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Which ref-counted byte container (Arc<[u8]>, Bytes, Vec<u8>, ...) an
application chooses is situation-specific — driven by what upstream
libraries hand over and whether slicing is in the hot path. Not a
design-doc decision. Replace the prescriptive "pick Arc<[u8]>"
subsection with a short "picking a container" paragraph that
acknowledges the choice exists without taking one.

The Rust -> native handoff code example still uses Arc<[u8]> but now
explicitly as a concrete illustration rather than a recommendation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The rest of the document works at an architectural-pattern level with
sparing code examples and almost no platform-API name-dropping. The
new ABI section was written at tutorial level — RustBuf struct + impl
+ extern fn, plus specific Swift/Kotlin API calls
(Data(bytesNoCopy:...), NewDirectByteBuffer, withUnsafeBytes, etc.).
Out of tone.

Cut the code block, the per-platform API names, the subsection
headers, and the inline crates/abi-buf tree (already in the master
crate layout). What remains: one paragraph stating the concern, a
two-bullet summary of the two directions (Rust-owned vs foreign-owned),
and a closing paragraph on what the layer doesn't cover (GPU-typed
opaque buffers).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@algesten algesten merged commit 9ee22ba into main Apr 21, 2026
5 checks passed
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.

2 participants