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
37
38
39
40
41
42
43
44
45
46
47
48
use crate::types::*;
use itertools::Itertools;
use std::path::Path;
use std::process::Command as ProcessCommand;

pub fn cargo_rustc_command(
    target: &Target,
    project_path: &Path,
    profile: &Profile,
    features: &[String],
    all_features: bool,
    no_default_features: bool,
    build_target: &BuildTarget,
    crate_types: &[CrateType],
) -> ProcessCommand {
    let mut cargo = ProcessCommand::new("cargo");
    cargo.arg("rustc");
    match &target {
        Target::Bin(name) => cargo.args(&["--bin", name]),
        Target::Example(name) => cargo.args(&["--example", name]),
        Target::Lib => cargo.arg("--lib"),
    };
    cargo.current_dir(project_path);
    if profile == &Profile::Release {
        cargo.arg("--release");
    };
    for feature in features.iter() {
        cargo.args(&["--feature", feature]);
    }
    if all_features {
        cargo.arg("--all-features");
    };
    if no_default_features {
        cargo.arg("--no-default-features");
    };
    let triple = build_target.rust_triple();
    cargo.args(&["--target", &triple]);
    if !crate_types.is_empty() {
        // Creates a comma-separated string
        let crate_types: String = crate_types
            .iter()
            .map(|v| v.as_ref())
            .intersperse(",")
            .collect();
        cargo.args(&["--", "--crate-type", &crate_types]);
    };
    cargo
}