Use the faster and newer MiMalloc memory allocator for all endpoints in the workspace. Change-Id: Ic60237284ed168e46ec6e8f28e2710bae4385c6f Reviewed-on: https://cl.tvl.fyi/c/depot/+/12149 Tested-by: BuildkiteCI Reviewed-by: aspen <root@gws.fyi>
47 lines
1.5 KiB
Rust
47 lines
1.5 KiB
Rust
use std::{collections::BTreeMap, io::Read};
|
|
|
|
use nix_compat::derivation::Derivation;
|
|
use serde_json::json;
|
|
|
|
use mimalloc::MiMalloc;
|
|
|
|
#[global_allocator]
|
|
static GLOBAL: MiMalloc = MiMalloc;
|
|
|
|
/// construct a serde_json::Value from a Derivation.
|
|
/// Some environment values can be non-valid UTF-8 strings.
|
|
/// `serde_json` prints them out really unreadable.
|
|
/// This is a tool to print A-Terms in a more readable fashion, so we brutally
|
|
/// use the [std::string::ToString] implementation of [bstr::BString] to get
|
|
/// a UTF-8 string (replacing invalid characters with the Unicode replacement
|
|
/// codepoint).
|
|
fn build_serde_json_value(drv: Derivation) -> serde_json::Value {
|
|
json!({
|
|
"args": drv.arguments,
|
|
"builder": drv.builder,
|
|
"env": drv.environment.into_iter().map(|(k,v)| (k, v.to_string())).collect::<BTreeMap<String, String>>(),
|
|
"inputDrvs": drv.input_derivations,
|
|
"inputSrcs": drv.input_sources,
|
|
"outputs": drv.outputs,
|
|
"system": drv.system,
|
|
})
|
|
}
|
|
|
|
fn main() {
|
|
// read A-Term from stdin
|
|
let mut buf = Vec::new();
|
|
std::io::stdin()
|
|
.read_to_end(&mut buf)
|
|
.expect("failed to read from stdin");
|
|
|
|
match Derivation::from_aterm_bytes(&buf) {
|
|
Ok(drv) => {
|
|
println!(
|
|
"{}",
|
|
serde_json::to_string_pretty(&build_serde_json_value(drv))
|
|
.expect("unable to serialize")
|
|
);
|
|
}
|
|
Err(e) => eprintln!("unable to parse derivation: {:#?}", e),
|
|
}
|
|
}
|