babble-bridge
BabbleSim + Zephyr nRF RPC simulation bridge. Provides:
- Test harness — spawn a full BabbleSim simulation from Rust integration tests
- xtask CLI — setup, sim lifecycle, and Docker management commands
- Programmatic API — call setup and spawn functions directly from
build.rsor code
Quickstart for downstream crate authors
1. Add the dependency
Root Cargo.toml:
[]
= ["your-app", "xtask"]
[]
= "0.1.0"
Your crate's Cargo.toml:
[]
= true
2. Create an xtask crate
xtask/Cargo.toml:
[]
= "xtask"
= "0.1.0"
= "2021"
[]
= true
xtask/src/main.rs:
.cargo/config.toml:
[]
= "run -p xtask --"
Platform setup
Linux (native or inside a container)
Also creates tests/sockets/ with restricted permissions (0700).
macOS
BabbleSim only runs on Linux. Use the --container flag — it manages a
persistent Docker container for you:
On first run per workspace this also runs zephyr-setup --prebuilt inside the container
to fetch Linux binaries.
Simulation lifecycle
| Command | Description |
|---|---|
cargo xtask start-sim |
Start PHY + Zephyr RPC server + CGM peripheral + socat bridge (Linux only) |
cargo xtask start-sim --container |
Same, but runs inside a managed container (macOS) |
cargo xtask stop-sim |
Kill simulation processes and clean up BabbleSim IPC |
cargo xtask clean-sockets |
Remove all *.sock files from tests/sockets/ |
Options for start-sim:
--sim-id <id> Socket name and BabbleSim identifier (default: sim)
--sim-dir <path> Directory for the socket file (default: <workspace>/tests/sockets)
--container Build image if needed and run inside a container (macOS)
The socket is created at tests/sockets/<sim-id>.sock.
Connecting to the simulation
From Linux (or inside the container)
use UnixStream;
let socket = connect?;
From macOS
Unix sockets don't cross the OS boundary. start-sim --container automatically
starts a TCP bridge inside the container and publishes it to 127.0.0.1 on your Mac:
TCP bridge ready: connect from macOS at 127.0.0.1:<port>
The port is stable and derived from your workspace path:
use TcpStream;
let stream = connect?;
To run code that needs to reach the socket from macOS, use exec to run it
inside the container instead:
Integration tests
use HashSet;
use Path;
let tests_dir = new;
let =
spawn_zephyr_rpc_server_with_socat;
// Connect to socket_path with a UnixStream, run test logic, then:
processes.search_stdout_for_strings;
Enable verbose output to see labelled per-process logs during a test run:
Tests require Linux — run them inside the container on macOS:
Docker commands
| Command | Description |
|---|---|
cargo xtask docker-build |
Build the dev-container image |
cargo xtask docker-attach |
Open an interactive shell in the container |
cargo xtask docker-run -- <cmd> |
Run a one-off command in a fresh container |
cargo xtask exec -- <cmd> |
Run a command in the persistent sim container |
docker-run creates a fresh container each time (no running sim).
exec targets the persistent container started by start-sim --container,
where the simulation socket is reachable.