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

cargo install --name #11413

Closed
simon-an opened this issue Nov 23, 2022 · 9 comments
Closed

cargo install --name #11413

simon-an opened this issue Nov 23, 2022 · 9 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@simon-an
Copy link

simon-an commented Nov 23, 2022

Problem

I have a binary crate which has multiple features. I want to install multiple variants of it.

So in addition to

cargo install app

I want to do:

cargo install --features feature-1 --name app-only-feat1 app
cargo install --all-features --name app-all app

Proposed Solution

Add --name argument

Notes

No response

@simon-an simon-an added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Nov 23, 2022
@simon-an
Copy link
Author

simon-an commented Nov 23, 2022

Figured it out myself. In the cargo.toml we can do:

default-run = "app"

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

[[bin]]
name = "app-only-feat1"
required-features = ["feat1"]
path = "src/main.rs"

Result:

cargo install --features feature-1 --bin app-only-feat1 app
cargo install  app

@simon-an
Copy link
Author

simon-an commented Nov 23, 2022

Maybe it is worth adding this to the docs of the cargo install command

@weihanglo
Copy link
Member

@simon-an, glad you figured it out!

I have the impression that cargo help install already mentioned that here https://doc.rust-lang.org/nightly/cargo/commands/cargo-install.html

If a crate has multiple binaries, the --bin argument can selectively install only one of them, and if you'd rather install examples the --example argument can be used as well.

Is this sufficient or do you have different thoughts on doc discovery, wording, or something else?

@weihanglo weihanglo changed the title cargo install --name cargo install --name https://github.com/rust-lang/cargo/issues/11413#issuecomment-1325070827 Nov 23, 2022
@weihanglo weihanglo changed the title cargo install --name https://github.com/rust-lang/cargo/issues/11413#issuecomment-1325070827 cargo install --name Nov 23, 2022
@weihanglo
Copy link
Member

Sorry for accidentally changing the title 😅.

@simon-an
Copy link
Author

simon-an commented Nov 23, 2022

For me it was not obvious in the first place that:

  • I can use [[bin]] multiple times in the cargo.toml pointing to the same main.ts file which in combination with required-features and default-run. Somehow i assumed this have to be different crates in the same workspace.
  • I can then use this together with cargo install --bin to get the behavior i wanted.

@simon-an
Copy link
Author

But you are right it is mentioned in the docs already and the issue was in front of the computer. 🤣

@weihanglo
Copy link
Member

weihanglo commented Nov 23, 2022

It's hard to decide what should be included in the first page of the manual. I feel like multiple binaries setup is a somewhat advanced feature, so IMO the current place of it in Cargo Guide seems reasonable.

Imagine there is a Cargo cookbook and helps people do arbitrary tasks. I am not sure if it is useful for cases like yours.

BTW, I am going to close this soon. If you have a new idea about improving the doc of cargo install in general, let us know. We can re-open it :)

@philpax
Copy link
Contributor

philpax commented Jul 15, 2023

Hi there! I'd like to request the --name parameter as originally specified, so that the binary can be named at install-time, not configuration-time.

My use case is to install multiple versions of the same binary with different names, so that I can use them simultaneously:

cargo install --path cli --name ambient
cargo install --git https://github.com/AmbientRun/Ambient.git --tag v0.2.1 --name ambient-0.2.1
cargo install --git https://github.com/AmbientRun/Ambient.git --rev 123abcdef --name ambient-123abcdef
# ...

As far as I can tell, there's no way to do this without installing to a temporary directory and then moving the resulting binary to ~/.cargo/bin with a new name, which works but isn't ideal.

(Happy to open a new issue if that's preferred!)

@weihanglo
Copy link
Member

@philpax Surely! Please file a new one, and we can start a discussion there. I have some thoughts to share on such a flag :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

3 participants