| Crates.io | ccode_runner |
| lib.rs | ccode_runner |
| version | 0.3.7 |
| created_at | 2025-02-22 00:02:13.969081+00 |
| updated_at | 2025-11-02 07:16:48.863193+00 |
| description | Run/compiles files and executes them efficiently |
| homepage | https://rootcircle.github.io/blog/project/cpast.html |
| repository | https://github.com/rootCircle/cpast_mono |
| max_upload_size | |
| id | 1564899 |
| size | 143,680 |
ccode_runner is a component designed to run arbitrary program code on local devices. It compiles or interprets code and sends the output, making it an essential part of the cpast ecosystem.
Ensure you have the necessary compilers and interpreters installed for the languages you intend to use.
Clone the repository and navigate to the ccode_runner directory:
git clone https://github.com/rootCircle/cpast_mono.git
cd cpast_mono/ccode_runner
To use ccode_runner, you need to integrate it within your cpast testing workflow. Below is an example of how to use it:
use ccode_runner::lang_runner::program_store::ProgramStore;
use std::path::Path;
fn main() {
let correct_file = Path::new("path/to/correct_file.rs");
let test_file = Path::new("path/to/test_file.rs");
let do_force_compile = true;
let program_store = ProgramStore::new(correct_file, test_file, do_force_compile).unwrap();
let stdin_content = "input data";
let (is_different, correct_output, test_output) = program_store
.run_codes_and_compare_output(stdin_content)
.unwrap();
println!("Outputs are different: {}", is_different);
println!("Correct Output: {}", correct_output);
println!("Test Output: {}", test_output);
}
You can configure time and memory limits to prevent infinite loops and excessive resource consumption:
Platform Support:
setrlimit(RLIMIT_AS)Note: Execution limits apply only to program execution, not compilation. Compilation always runs without limits to ensure successful builds.
use ccode_runner::lang_runner::program_store::ProgramStore;
use ccode_runner::ExecutionLimits;
use std::path::Path;
fn main() {
let correct_file = Path::new("path/to/correct_file.rs");
let test_file = Path::new("path/to/test_file.rs");
let do_force_compile = true;
// Configure limits: 5 second timeout and 512MB memory limit
let limits = ExecutionLimits::new()
.with_time_limit(5000) // 5000 milliseconds
.with_memory_limit(512 * 1024 * 1024); // 512 MB
let program_store = ProgramStore::new_with_limits(
correct_file,
test_file,
do_force_compile,
limits
).unwrap();
let stdin_content = "input data";
let result = program_store.run_codes_and_compare_output(stdin_content);
match result {
Ok((is_different, correct_output, test_output)) => {
println!("Outputs are different: {}", is_different);
println!("Correct Output: {}", correct_output);
println!("Test Output: {}", test_output);
}
Err(e) => {
eprintln!("Execution failed: {}", e);
}
}
}
.rs.py.c.cpp, .cxx, .c++, .cc, .C.java.js.rbccode_runner uses different strategies for different languages:
ccode_runner is well suited when repeated compilation might be required for one code like in case for cpast, it intelligently skips those cases for you, making it lot faster!
We welcome contributions! Please read our Contributing Guidelines for more details.