#[path = "support/objects.rs"]
mod objects;
use rayon::prelude::*;
use qld::args::{InputAttrs, InputKind, LinkOptions, OutputBuffer, OutputKind};
use qld::diag::Collect;
fn link(value: u8) -> qld::Result<Vec<u8>> {
let mut options = LinkOptions::new();
options.kind = OutputKind::StaticExecutable;
options.push_input(
InputKind::bytes("main.o", objects::main_object()),
InputAttrs::default(),
);
options.push_input(
InputKind::bytes("answer.o", objects::answer_object(value)),
InputAttrs::default(),
);
let buffer = OutputBuffer::new();
options.output_buffer = Some(buffer.clone());
qld::link(&options, &Collect::new())?;
buffer
.take()
.ok_or_else(|| qld::Error::Internal("no output".into()))
}
fn main() -> qld::Result<()> {
let pool = rayon::ThreadPoolBuilder::new()
.num_threads(4)
.thread_name(|index| format!("build-worker-{index}"))
.build()
.map_err(|error| qld::Error::Internal(error.to_string()))?;
let single = pool.install(|| link(1))?;
println!("one link in the pool: {} bytes", single.len());
let images = pool.install(|| {
(0..16u8)
.into_par_iter()
.map(link)
.collect::<qld::Result<Vec<_>>>()
})?;
println!("{} concurrent links in the pool", images.len());
assert_eq!(images[1], single, "the same inputs give the same output");
assert_eq!(link(1)?, single);
Ok(())
}