xtask: slightly neater
This commit is contained in:
parent
88cc5e2687
commit
b5ea1d9e99
|
@ -1,5 +1,5 @@
|
|||
[alias]
|
||||
xtask = "run --package xtask --"
|
||||
xtask = "run -q --package xtask --"
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 1
|
||||
|
|
|
@ -9,11 +9,7 @@ mod types;
|
|||
static METADATA: std::sync::OnceLock<cargo_metadata::Metadata> = std::sync::OnceLock::new();
|
||||
static OUTPUT_DIR: std::sync::OnceLock<std::path::PathBuf> = std::sync::OnceLock::new();
|
||||
|
||||
fn executable_dir(
|
||||
binary: Binary,
|
||||
triple: &cfg_expr::targets::Triple,
|
||||
renderer: Renderer,
|
||||
) -> String {
|
||||
fn executable_dir(binary: Binary, triple: impl std::fmt::Display, renderer: Renderer) -> String {
|
||||
format!("{}_{}_{}", binary.name(), triple, renderer.as_feature())
|
||||
}
|
||||
|
||||
|
@ -341,18 +337,18 @@ fn cargo_exec(
|
|||
|
||||
Ok(
|
||||
cargo_metadata::Message::parse_stream(std::io::BufReader::new(output)).inspect(move |v| {
|
||||
if let Some(pb) = pb.as_mut() {
|
||||
match v {
|
||||
Ok(cargo_metadata::Message::BuildScriptExecuted(_))
|
||||
| Ok(cargo_metadata::Message::CompilerArtifact(_)) => {
|
||||
match v {
|
||||
Ok(cargo_metadata::Message::BuildScriptExecuted(_))
|
||||
| Ok(cargo_metadata::Message::CompilerArtifact(_)) => {
|
||||
if let Some(pb) = pb.as_mut() {
|
||||
pb.inc();
|
||||
}
|
||||
Ok(cargo_metadata::Message::CompilerMessage(message)) => {
|
||||
eprintln!("{message}");
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
Ok(cargo_metadata::Message::CompilerMessage(message)) => {
|
||||
eprintln!("{message}");
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
@ -372,24 +368,92 @@ fn build_vst(
|
|||
renderer: Renderer,
|
||||
debug: bool,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let triple_str = triple.map(|t| t.to_string());
|
||||
let mut args = if platform == Platform::Mac {
|
||||
vec!["bundle-universal"]
|
||||
} else {
|
||||
vec!["bundle", "--target", triple_str.as_ref().unwrap().as_str()]
|
||||
vec!["bundle"]
|
||||
};
|
||||
if !debug {
|
||||
args.push("--release");
|
||||
}
|
||||
let more_args = "-q -p twinc_emu_vst --no-default-features -F plugin";
|
||||
let more_args = "twinc_emu_vst --no-default-features -F plugin";
|
||||
for arg in more_args.split_whitespace() {
|
||||
args.push(arg);
|
||||
}
|
||||
args.push("-F");
|
||||
args.push(renderer.as_feature());
|
||||
if !debug {
|
||||
args.push("--release");
|
||||
}
|
||||
|
||||
// we need the &str to live for this whole function
|
||||
let triple_str = triple.map(|t| t.to_string());
|
||||
if platform != Platform::Mac {
|
||||
args.push("--target");
|
||||
args.push(triple_str.as_ref().unwrap().as_str());
|
||||
}
|
||||
args.push("-F");
|
||||
let renderer = renderer.as_feature();
|
||||
args.push(renderer);
|
||||
let target_dir = METADATA
|
||||
.get()
|
||||
.unwrap()
|
||||
.target_directory
|
||||
.join(format!("xtargets/{renderer}"));
|
||||
std::fs::create_dir_all(&target_dir)?;
|
||||
std::env::set_var("CARGO_TARGET_DIR", target_dir.as_str());
|
||||
|
||||
let build_plan =
|
||||
nih_plug_xtask::get_build_plan("cargo xtask", args.clone().into_iter().map(String::from))?;
|
||||
let mut build_plan_iter = build_plan.into_iter();
|
||||
let mut pb = build_plan_iter.next().map(|(arch, num)| {
|
||||
let mut pb = pbr::ProgressBar::new(num.try_into().unwrap());
|
||||
if let Some(arch) = arch {
|
||||
pb.message(format!("({arch}) Building crate ").as_str());
|
||||
} else {
|
||||
pb.message("Building crate ");
|
||||
}
|
||||
pb.show_time_left = false;
|
||||
pb.show_speed = false;
|
||||
pb
|
||||
});
|
||||
|
||||
let args = ["xtask"]
|
||||
.into_iter()
|
||||
.chain(args)
|
||||
.chain(["--message-format=json-render-diagnostics"])
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// nih_plug_xtask::ch
|
||||
let output = duct::cmd("cargo", args)
|
||||
.env("CARGO_TARGET_DIR", target_dir)
|
||||
.stdout_capture()
|
||||
.stderr_capture()
|
||||
.reader()?;
|
||||
|
||||
for v in cargo_metadata::Message::parse_stream(std::io::BufReader::new(output)) {
|
||||
match v {
|
||||
Ok(cargo_metadata::Message::BuildScriptExecuted(_))
|
||||
| Ok(cargo_metadata::Message::CompilerArtifact(_)) => {
|
||||
if pb.as_ref().is_some_and(|pb| pb.is_finish) {
|
||||
pb = build_plan_iter.next().map(|(arch, num)| {
|
||||
let mut pb = pbr::ProgressBar::new(num.try_into().unwrap());
|
||||
if let Some(arch) = arch {
|
||||
pb.message(format!("({arch}) Building crate ").as_str());
|
||||
} else {
|
||||
pb.message("Building crate ");
|
||||
}
|
||||
pb.show_time_left = false;
|
||||
pb.show_speed = false;
|
||||
pb
|
||||
});
|
||||
}
|
||||
if let Some(pb) = pb.as_mut() {
|
||||
pb.inc();
|
||||
}
|
||||
}
|
||||
Ok(cargo_metadata::Message::CompilerMessage(message)) => {
|
||||
eprintln!("{message}");
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
eprintln!("building vst...");
|
||||
nih_plug_xtask::main_with_args("cargo xtask", args.into_iter().map(String::from))?;
|
||||
eprintln!("\t...complete!");
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue