vdev/commands/check/
component_features.rs

1use std::env;
2
3use anyhow::Result;
4
5use crate::{app, util::CargoToml};
6
7const CARGO: &str = "cargo";
8const BASE_ARGS: [&str; 5] = [
9    "check",
10    "--tests",
11    "--bin",
12    "vector",
13    "--no-default-features",
14];
15const PARALLEL_ARGS: [&str; 7] = [
16    "--group",
17    "--verbose",
18    "--retries",
19    "2",
20    "scripts/check-one-feature",
21    "{}",
22    ":::",
23];
24
25/// Check that all component features are set up properly
26#[derive(clap::Args, Debug)]
27#[command()]
28pub struct Cli {}
29
30impl Cli {
31    #[allow(clippy::dbg_macro)]
32    pub fn exec(self) -> Result<()> {
33        app::set_repo_dir()?;
34
35        let features = extract_features()?;
36
37        // Prime the pump to build most of the artifacts
38        app::exec(CARGO, BASE_ARGS, true)?;
39        app::exec(
40            CARGO,
41            BASE_ARGS.into_iter().chain(["--features", "default"]),
42            true,
43        )?;
44        app::exec(
45            CARGO,
46            BASE_ARGS
47                .into_iter()
48                .chain(["--features", "all-integration-tests"]),
49            true,
50        )?;
51
52        // The feature builds already run in parallel below, so don't overload the parallelism
53        unsafe {
54            env::set_var("CARGO_BUILD_JOBS", "1");
55        }
56
57        app::exec(
58            "parallel",
59            PARALLEL_ARGS
60                .into_iter()
61                .chain(features.iter().map(String::as_str)),
62            true,
63        )
64    }
65}
66
67fn extract_features() -> Result<Vec<String>> {
68    Ok(CargoToml::load()?
69        .features
70        .into_keys()
71        .filter(|feature| {
72            !feature.contains("-utils")
73                && feature != "default"
74                && feature != "all-integration-tests"
75        })
76        .collect())
77}