Skip to content
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.

Feature request: better build info tools (which features, codegen a binary was compiled with) #106

Open
epage opened this issue Dec 6, 2021 · 0 comments

Comments

@epage
Copy link
Owner

epage commented Dec 6, 2021

Issue by jonathanstrong
Thursday Oct 18, 2018 at 01:12 GMT
Originally opened as clap-rs/clap#1363


Rust Version

rustc 1.31.0-nightly (bef62ccdd 2018-10-16)

Affected Version of clap

2.32.0

Bug or Feature Request Summary

I often find myself checking which version of a binary I compiled, between versions, crate features and codegen options. I wrote some code below which I am using via the App::about method to provide build info for my clap-generated -h printout. (Like vim --version, but much less info).

pub fn build_info() -> String {
    let indent = "    ";
    format!("\r\n\
        BUILD:\r\n\
        {}{}\r\n\r\n\
        CODEGEN:\r\n\
        {}{}",
        indent, features().join(" "),
        indent, codegen().join(" "))
}

fn codegen() -> Vec<&'static str> {
    let mut flags = Vec::new();
    macro_rules! check_cpu {
        ($($target:expr),*) => {{
            $(
                #[cfg(target_feature = $target)]
                flags.push($target);
            )*
        }}
    }

    check_cpu!("aes", "avx", "avx2", "avx512bw", "avx512cd", "avx512dq", "avx512f", "avx512vl", "bmi1",
               "bmi2", "fma", "fxsr", "lzcnt", "mmx", "pclmulqdq", "popcnt", "rdrand", "rdseed", "sse",
               "sse2", "sse3", "sse4.1", "sse4.2", "ssse3", "xsave", "xsavec", "xsaveopt", "xsaves");

    flags.sort_unstable();
    flags.dedup();
    flags
}

fn features() -> Vec<&'static str> {
    macro_rules! feat_list {
        ($($feat:expr),*) => {
            vec![
                $(
                    #[cfg(feature = $feat)]
                    $feat,
                )*
            ]
        }
    }

    let mut flags = feat_list!("feat-one", "feat-two");

    #[cfg(debug_assertions)]
    flags.push("debug_assertions");

    flags.sort_unstable();
    flags.dedup();
    flags
}

// ...

fn main()
    let build_info = mylib::build_info();
    let args: ArgMatches = App::new("my-binary")
        .version(crate_version!())
        .about(build_info.as_str())
        // ...

This is ok, but unfortunately it needs to be manually maintained as new features are added, etc. It occurred to me that perhaps clap would be a good fit for this kind of functionality, and I didn't see anything in the docs about providing build info. Have you considered adding tools for tracking features, codegen options, etc.?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant