rqbit/crates/librqbit/build.rs

46 lines
1.5 KiB
Rust
Raw Normal View History

2024-08-12 20:59:21 +01:00
use anyhow::Context;
use std::path::Path;
use std::process::Command;
fn main() {
#[cfg(feature = "webui")]
{
let webui_dir = Path::new("webui");
let webui_src_dir = webui_dir.join("src");
println!("cargo:rerun-if-changed={}", webui_src_dir.to_str().unwrap());
2024-08-12 21:05:59 +01:00
#[cfg(target_os = "windows")]
2024-08-12 21:19:05 +01:00
let (shell, shell_args) = (
r#"C:\Program Files\PowerShell\7\pwsh.EXE"#,
["-command"].as_slice(),
);
#[cfg(not(target_os = "windows"))]
let (shell, shell_args) = ("bash", ["-c"].as_slice());
2024-08-12 21:05:59 +01:00
// Run "npm install && npm run build" in the webui directory
2024-08-12 21:19:05 +01:00
for cmd in ["npm install", "npm run build"] {
// Run "npm install" in the webui directory
2024-08-12 21:19:05 +01:00
let output = Command::new(shell)
.args(shell_args)
.arg(cmd)
.current_dir(webui_dir)
.output()
2024-08-12 21:19:05 +01:00
.with_context(|| format!("Failed to execute {} in {:?}", cmd, webui_dir))
2024-08-12 20:59:21 +01:00
.unwrap();
if !output.status.success() {
panic!(
2024-08-12 21:19:05 +01:00
"{} failed. stderr: {}. stdout: {}",
cmd,
2024-08-12 20:57:33 +01:00
String::from_utf8_lossy(&output.stderr),
String::from_utf8_lossy(&output.stdout)
);
}
// Optionally print the stdout output if you want to see the build logs
println!("{}", String::from_utf8_lossy(&output.stdout));
}
}
}