| Crates.io | cu-run-in-sim |
| lib.rs | cu-run-in-sim |
| version | 0.9.1 |
| created_at | 2025-09-12 21:06:38.168726+00 |
| updated_at | 2025-09-12 21:06:38.168726+00 |
| description | Example for forcing Copper to compile in and run a source or a sink in simulation mode |
| homepage | https://github.com/copper-project |
| repository | https://github.com/copper-project/copper-rs |
| max_upload_size | |
| id | 1836825 |
| size | 57,658 |
This demo shows how to control task behavior in simulation using run_in_sim and a simulation callback.
What the demo does:
In this implementation:
process runs and prints).run_in_sim is ignored for regular tasks.When running in simulation, sources and sinks can be either:
The run_in_sim flag determines which behavior is used for sources and sinks during simulation. This demo shows a mixed
setup where:
This lets you inject synthetic inputs at the beginning of the pipeline while keeping the real behavior at the output end.
The runtime generates a SimStep enum that indicates which task and lifecycle stage is happening. The demo’s callback
does this:
Process step: it sets the output payload (e.g., a monotonically increasing counter) and returns
ExecutedBySim, meaning “the simulator handled it; skip the real implementation.”Process step: it returns ExecuteByRuntime so the real code runs and doubles the value.Process step: it returns ExecuteByRuntime so the real sink runs and prints the result.ExecuteByRuntime.From your workspace, run the example using your preferred method, for example:
cargo run -p cu_run_in_simcargo runYou should see output similar to:
17:32:05 [DEBUG] (1) cu29_log: 0 ns [Debug]: Logger created at logs/run_in_sim.copper. This is a simulation.
17:32:05 [DEBUG] (1) cu29_log: CuConfig: Using the original configuration the project was compiled with: ...
[MySink] got value = 2
[MySink] got value = 4
[MySink] got value = 6
[MySink] got value = 8
[MySink] got value = 10
Flushing the unified Logger ...
Unified Logger flushed.