Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jonathanstrong opened this issue Oct 18, 2018 · 2 comments
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing

Comments

@jonathanstrong
Copy link

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.?

@CreepySkeleton CreepySkeleton added A-help Area: documentation, including docs.rs, readme, examples, etc... D: intermediate E-help-wanted Call for participation: Help is requested to fix this issue. C-enhancement Category: Raise on the bar on expectations labels Feb 1, 2020
@CreepySkeleton CreepySkeleton added this to the 3.1 milestone Feb 1, 2020
@pksunkara pksunkara removed the W: 3.x label Aug 13, 2021
@epage
Copy link
Member

epage commented Dec 9, 2021

@epage epage removed this from the 3.1 milestone Dec 9, 2021
@epage epage added S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing and removed D: medium E-help-wanted Call for participation: Help is requested to fix this issue. labels Dec 9, 2021
@epage
Copy link
Member

epage commented Feb 3, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing
Projects
None yet
Development

No branches or pull requests

4 participants