1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
use anyhow::{ensure, Result}; use std::{ffi::OsStr, path::Path, process::Command}; pub fn build<I, K, V>(envs: I, path: Option<&Path>) -> Result<()> where I: Iterator<Item = (K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr>, { let mut command = Command::new("cargo"); if let Some(path) = path { command.current_dir(path); } let envs: Vec<(String, String)> = envs .map(|(k, v)| { ( k.as_ref().to_string_lossy().to_string(), v.as_ref().to_string_lossy().to_string(), ) }) .collect(); log::debug!("{:?}", envs); command.envs(envs).args(&["build"]); log::debug!("{:?}", command); let status = command.status()?; ensure!(status.success(), "command failed: {:?}", command); Ok(()) }