Skip to content

Environment variable to identify the binary name #8251

@joshtriplett

Description

@joshtriplett

Currently, cargo provides an environment variable CARGO_PKG_NAME containing the name of the crate. clap uses this in clap::crate_name to get the name of the crate to use as the program name.

However, this doesn't work for crates that build more than one binary. I'd like to have an environment variable specifying the name of the binary being built, such as CARGO_BIN_NAME, which clap could use for a more accurate idea of the name of the program.

For example, given the following Cargo.toml:

[package]
name = "cratename"
version = "0.1.0"
edition = "2018"

[[bin]]
name = "binname"
path = "src/main.rs"

[dependencies]
clap = "2.33.1"

When building src/main.rs, cargo should set CARGO_PKG_NAME=cratename and CARGO_BIN_NAME=binname.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`E-easyExperience: EasyS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions