Rust workspace
This page describes the crate split, module responsibilities, public interfaces and extension points of the launcher for readers who change the launcher or add a device model.
Workspace Layout
The workspace contains the cosim-topology, cosim-runtime and cosim-cli crates. cosim-cli depends on the other two, and cosim-runtime depends on cosim-topology. The dependency direction encodes the rule that document parsing does not touch the host while only execution logic does.
flowchart TD
C[cosim-cli] --> T[cosim-topology]
C --> R[cosim-runtime]
R --> T
Module Responsibilities
Path |
Responsibility |
|---|---|
|
Clap subcommands, signal escalation, the standard-input lifeline, event output and the verdict line. |
|
Decoded input types, validated types ( |
|
Imports, merge keys, template inheritance, workspace-relative resource paths, count expansion and validation. |
|
The |
|
Memory pools and guest physical ranges for a given |
|
|
|
Session resources, node type states, dependency leases, readiness probes and the verdict. |
|
Process groups, file and lock owners, image creation and overlays, and |
Public Interfaces
cosim-topologyexposesload,graphandschema. Validated types render launch arguments fromDeviceContextandVhostContext.cosim-runtimeexposesplan,run,clean,check_assets,RunOptions,ShutdownandEvent.Planrecords programs, arguments, environments, dependencies, readiness probes, shared memory regions, disk targets and lock paths;cosim run --dry-runprints it.
Extension Points: Adapters and Command Templates
The device adapter is expressed by the
Adapterenum:gem5-mi300xruns one GPU per process,qemu-deviceexports a QEMU functional device, and the template adapter renders a command from YAML.Readiness is expressed by
Probe: log markers, Unix socket existence and QMP negotiation. An adapter returns these probes in evaluation order.vHost kinds render QEMU arguments from a YAML
commandtemplate. A kind declared underkindswithrole: deviceprovidesargvorcommandand requiresready_log.runtime.argvorruntime.commandcan replace the command of any device adapter, but the replacement must provide its own readiness contract and resource behavior.gem5-mi300xrequiresconfig, exactly onevramregion whose size is a power of two, and MI300X PCI metadata.num_compute_unitsranges from 1 to 1024 and defaults to 40.qemu-devicerequiresargs.device.driver, defaultsidtodevice0, accepts no private memory regions and needsruntime.binary.
Adding a Model
Add a template under
resources/devices/declaring thekind,configorruntime, memory regions and PCI metadata.Use a built-in adapter, or declare a template kind under
kindswithrole: deviceand provide its command andready_log.Add a machine sample under
resources/machines/that uses the template, then runcosim validateandcosim run --dry-runto check the rendering.If the model needs a new readiness condition or argument semantics, change
crates/cosim-topology/src/adapter/and add Rust tests.
Dependencies and Safety Rules
YAML syntax and merge keys use
serde_yaml_ng; Serde performs typed decoding.MiniJinja renders argument templates, Schemars produces JSON Schema, and
parse-sizeparses size expressions.Tokio runs the session on one thread,
futures-utildrives the process nodes concurrently, andnixprovides process-group signals, page size and filesystem statistics.Project Rust crates inherit
unsafe_code = "forbid"from the workspace. Device models enter through the adapter boundary; the launcher does not touch model internals directly.Checks:
just check-cosimruns formatting, clippy and unit tests;just test-cosim-integrationruns integration tests with real processes and disks.
Sources
Crate manifests and dependencies:
crates/cosim-cli/Cargo.toml,crates/cosim-runtime/Cargo.tomlandcrates/cosim-topology/Cargo.toml.Adapter implementations:
crates/cosim-topology/src/adapter/gem5.rs,qemu_device.rsandtemplate.rs.Runtime exports:
crates/cosim-runtime/src/lib.rs.Rust guidelines:
docs/en/contributing/rust_guidelines.rst.