1use config;
4use failure::{err_msg, Error};
5use std::env;
6use std::process::{self, Command};
7
8pub fn build(config: &config::Root, release: bool) -> Result<(), Error> {
10 let mut command = Command::new("xargo");
11 command.arg("build");
12 if release {
13 command.arg("--release");
14 }
15 command.arg("--target").arg(&config.target);
16 let status = command.spawn()?.wait()?;
17 if !status.success() {
18 process::exit(status.code().unwrap_or(1));
19 }
20 Ok(())
21}
22
23pub fn binary_path(
25 config: &config::Root,
26 release: bool,
27) -> Result<String, Error> {
28 Ok(format!(
29 "target/{}/{}/{}",
30 config.target,
31 if release { "release" } else { "debug" },
32 crate_name()?,
33 ))
34}
35
36pub fn crate_name() -> Result<String, Error> {
38 Ok(
39 env::current_dir()?
40 .file_name()
41 .ok_or_else(|| err_msg("Current directory is invalid"))?
42 .to_str()
43 .ok_or_else(|| err_msg("Current directory path is not valid UTF-8"))?
44 .to_string(),
45 )
46}