Skip to content

Conversation

@lthibault
Copy link
Contributor

This PR reorganizes the cell module structure by flattening the nested directory and renaming types to better reflect the architecture where cells orchestrate one or more procs.

🟠 Merge after #26. Ready for initial review.

Changes

Module Structure

  • Moved cell/proc.rssrc/proc.rs - Low-level WASM process execution primitive
  • Moved cell/streams.rssrc/streams.rs - Stream adapters utility module
  • Moved cell/executor.rssrc/cell.rs - Cell abstraction that orchestrates procs
  • Moved cell/streams_test.rssrc/streams_test.rs - Tests moved to top level
  • Removed cell/mod.rs - No longer needed with flattened structure

Type Renaming

  • CommandCell - Better reflects that cells are higher-level abstractions
  • CommandBuilderCellBuilder - Consistent with Cell naming
  • Loader trait moved into cell.rs (cells need loaders)

Import Updates

  • Updated all imports across the codebase to use new module paths
  • proc.rs now uses crate::{streams, Loader}
  • cell.rs uses crate::proc::Builder as ProcBuilder
  • loaders.rs uses crate::Loader (re-exported from lib.rs)
  • cli/main.rs updated to use cell::CellBuilder

Architecture Clarity

This reorganization makes the architecture clearer:

  • Proc = Low-level WASM execution primitive (single WASM instance)
  • Cell = Higher-level abstraction that can orchestrate one or more procs
  • streams = Shared utility module for async readers and writers

- Add ChannelReader: AsyncRead implementation for mpsc receivers
- Add ChannelWriter: AsyncWrite implementation for mpsc senders
- Add create_channel_pair() helper for bidirectional channels
- Add comprehensive unit tests for async streaming
- All tests passing with full async/await support
- Define wetware:streams package with connection resource
- Connection resource provides get-input-stream-handle and get-output-stream-handle
- create-connection function to instantiate connection resources
- Returns u32 handles for use with WASI stream APIs
- Export streams module for stream adapters
- Add streams_test module for unit tests
- Add bindgen! macro to generate bindings from WIT interface
- Add data_stream_channels to ComponentRunStates for channel storage
- Add guest_to_host_rx field for host-side receiver access
- Add Builder::with_data_streams() API for enabling data streams
- Add DataStreamHandles struct for host access to channels
- Implement add_streams_to_linker() with full resource integration:
  * create-connection: Creates connection resource with WASI streams
  * get-input-stream-handle: Returns input stream handle from connection
  * get-output-stream-handle: Returns output stream handle from connection
- Add Proc::guest_output_receiver() for host to read guest output
- Streams are added to WASI resource table and exposed to guests
- Full async support throughout the implementation
- Add type aliases for complex channel tuple types (DataStreamChannel, DataStreamChannelPair, ChannelPair)
- Use inline format args in panic messages
- Replace vec! with arrays in test code
- All clippy warnings resolved, tests passing
- Move proc.rs from cell/ to src/ (low-level WASM process execution)
- Move streams.rs from cell/ to src/ (stream adapters utility)
- Move executor.rs to cell.rs and rename Command/CommandBuilder to Cell/CellBuilder
- Move Loader trait into cell.rs
- Update all imports across the codebase
- Remove old cell/ directory structure

This reorganization better reflects the architecture where:
- Proc = low-level WASM execution primitive
- Cell = higher-level abstraction that orchestrates one or more procs
- streams = shared utility module
@lthibault lthibault requested a review from mikelsr November 30, 2025 23:18
@lthibault lthibault self-assigned this Nov 30, 2025
- Fix format string in loaders.rs: use positional placeholders instead of field access
- Add missing PathBuf import
- Fix HostPath::new to use correct parameter name
- Fix HostPath instantiation in main.rs to use new() with PathBuf
- Rename spawn() method to start() for better clarity
- Update call site in cli/main.rs
- DataStreamChannel -> GuestChannels (3 channels for guest)
- DataStreamChannelPair -> ChannelSet (complete 4-channel set)
mikelsr and others added 5 commits December 21, 2025 10:13
Why: The “bidirectional” stream was effectively one-way—handles dropped the guest→host
receiver and Proc only exposed a borrowed receiver that couldn’t outlive run(self).
Hosts couldn’t read guest output (Capnp/Protobuf/etc.) while the guest booted.

What:
- Make DataStreamHandles own the guest→host receiver and expose take_guest_output_receiver()
  so hosts can move it into long-lived async tasks.
- Remove Proc’s borrowed receiver and rely solely on the handles to avoid lifetime traps.
- Wire with_data_streams() into Command::spawn via spawn_with_streams(); return the join
  handle plus handles, keep them alive for the run, and drain guest output if unused.
- Add a full-duplex regression test in src/cell/proc.rs to prove host→guest and
  guest→host delivery via the returned handles.
- Simplify channel plumbing by dropping unused builder/proc receiver fields.
- Move proc.rs from cell/ to src/ (low-level WASM process execution)
- Move streams.rs from cell/ to src/ (stream adapters utility)
- Move executor.rs to cell.rs and rename Command/CommandBuilder to Cell/CellBuilder
- Move Loader trait into cell.rs
- Update all imports across the codebase
- Remove old cell/ directory structure

This reorganization better reflects the architecture where:
- Proc = low-level WASM execution primitive
- Cell = higher-level abstraction that orchestrates one or more procs
- streams = shared utility module
- Rename spawn() method to start() for better clarity
- Update call site in cli/main.rs
- DataStreamChannel -> GuestChannels (3 channels for guest)
- DataStreamChannelPair -> ChannelSet (complete 4-channel set)
- Remove stray `let Cell {` that broke `Cell::start` compilation
- Fix `HostPath` read borrow to preserve error context
- Avoid double-ownership of `guest_to_host_rx` while keeping host/guest async streams intact

# Conflicts:
#	src/proc.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants