complete_usage/
complete_usage.rs

1use parabuild::{
2    CompliationErrorHandlingMethod, Parabuilder, RunMethod, IGNORE_ON_ERROR_DEFAULT_RUN_FUNC,
3};
4use serde_json::{json, Value as JsonValue};
5
6fn main() {
7    let project_path = "tests/example_run_time_consuming_project"; // your project path
8    let workspaces_path = "workspaces"; // where to store the workspaces, executables, etc.
9    let template_path = "src/main.cpp.template"; // template file in the project
10    let target_executable_file = "build/main"; // target executable file
11    let mut datas = (1..=100)
12        .map(|i| json!({"N": i}))
13        .collect::<Vec<JsonValue>>();
14    let error_data = json!({"N": "a"});
15    datas.push(error_data.clone());
16    let init_bash_script = r#"cmake -B build -S . -DPARABUILD=ON"#;
17    let compile_bash_script = r#"cmake --build build --target all -- -B"#;
18    let mut parabuilder = Parabuilder::new(
19        project_path,
20        workspaces_path,
21        template_path,
22        &[target_executable_file],
23    )
24    .init_bash_script(init_bash_script)
25    .compile_bash_script(compile_bash_script)
26    // .run_bash_script(format!(r#"./{}"#, target_executable_file).as_str())
27    .build_workers(4)
28    .run_method(RunMethod::OutOfPlace(2)) // 4 threads compile, 1 thread run
29    // .run_method(RunMethod::Exclusive) // 4 threads compile, 1 thread run
30    .compilation_error_handling_method(CompliationErrorHandlingMethod::Collect) // collect data that has compilation error
31    .auto_gather_array_data(true) // when each run thread finishes, gather the data into one array when every thread returns an array
32    .run_func(IGNORE_ON_ERROR_DEFAULT_RUN_FUNC)
33    .in_place_template(false)
34    .disable_progress_bar(false);
35    // let sender = parabuilder.get_data_queue_sender().unwrap();
36    parabuilder.set_datas(datas).unwrap();
37    parabuilder.init_workspace().unwrap();
38    let (run_data, compile_error_datas, _processed_data_ids): (
39        JsonValue,
40        Vec<JsonValue>,
41        Vec<usize>,
42    ) = parabuilder.run().unwrap();
43    println!(
44        "run_data: {}",
45        serde_json::to_string_pretty(&run_data).unwrap()
46    );
47    println!("compile_error_datas: {:?}", compile_error_datas);
48}