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

The --bin flag on the install subcommand doesn't work #4830

Open
RazrFalcon opened this issue Dec 18, 2017 · 9 comments
Open

The --bin flag on the install subcommand doesn't work #4830

RazrFalcon opened this issue Dec 18, 2017 · 9 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-install S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@RazrFalcon
Copy link

RazrFalcon commented Dec 18, 2017

% cargo install --force --bin svgcleaner --git https://github.com/RazrFalcon/svgcleaner               
    Updating git repository `https://github.com/RazrFalcon/svgcleaner`
error: multiple packages with binaries found: docgen, files-testing, stats, svgcleaner, use_as_lib
% cargo -V
cargo 0.23.0 (61fa02415 2017-11-22)
@alexcrichton alexcrichton added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Dec 18, 2017
@ishanjain28
Copy link

ishanjain28 commented Dec 23, 2017

All the packages are installed using install function in src/cargo/ops/cargo_install.rs. This function takes a krate: Vec<&str> which is created from options.arg_crate in execute function in src/bin/install.rs.

In the command,

cargo install --force --bin svgcleaner --git https://github.com/RazrFalcon/svgcleaner               

options.arg_crate is an empty vector. The value of --bin flag(svgcleaner) is used to generate CompileFilter but never used. So, You are getting this error.

@RazrFalcon,
For your case, You can use cargo install --force svgcleaner --git https://github.com/RazrFalcon/svgcleaner and it'll work just fine. I'll try to send a PR to fix this before Monday.

@RazrFalcon
Copy link
Author

@ishanjain28 thanks, that worked.

@kornelski
Copy link
Contributor

kornelski commented Dec 26, 2018

I've ran into the same problem:

cargo install --bin cargo-deb --git https://github.com/mmstick/cargo-deb --force
    Updating git repository `https://github.com/mmstick/cargo-deb`
error: multiple packages with binaries found: cargo-deb, example

I see from this issue that skipping --bin solves the problem. However, I wouldn't have figured it out myself, because:

  • I assumed cargo install foo refers to foo on crates.io only, and --git foo is a replacement for the package name, not an independent argument.
  • Other cargo commands use -p to select the package, but not this one.
  • cargo install --help shows cargo install [OPTIONS] [--] [crate]... says crate, but the error is about packages.
  • cargo install --help has "--bin ... Install only the specified binary" which sounded exactly like what I wanted.

Things that could help:

  • Add help text to the error message suggesting adding crate name as the first arg
  • When --bin is specified, but not the crate/package, either search all of them, or show an error explaining specifically why --bin was ignored.
  • Support -p, --package to specify the package for consistency with other commands.

@ehuss

This comment was marked as resolved.

@teor2345
Copy link

teor2345 commented Jan 7, 2021

Just copying those suggestions here:

  1. --bin zebrad should install the binary with that name, if there are multiple packages with binaries
  2. --bins should install all binaries, if there are multiple packages with binaries
  3. if there is only one binary in the workspace default-members, that binary should be installed
  4. a multiple packages with binaries found error should give users a hint about how to specify a single crate

@teor2345
Copy link

teor2345 commented Jan 8, 2021

Here's another possible solution:
5. add a default-install key to the package section of the manifest, which acts like default-run

default-run configures the default binary for cargo run, where:

  • there are multiple binaries in a crate, default-run is set in the crate Cargo.toml, and cargo run is run in the crate directory, or
  • there are multiple binaries in a workspace, default-run is set in exactly one crate's Cargo.toml, and cargo run is run in the workspace directory

This second behaviour was a bit surprising, but I think it's actually a good thing.

@dpurfield
Copy link

dpurfield commented Apr 27, 2021

I’m new to rust but my understanding is a package (cargo.toml) can have multiple crates in the form of 1 library and/or multiple binaries. (ref: The Book section 7.1 2nd paragraph). But crate is also used to refer to a published package on crates.io. And since a package can contain multiple binaries i would assume a published crate on crates.io can as well. So there is a conflict of what this term crate means.

The cargo install command help is incorrect in that it states the default arg is a crate. If you are installing a crate from crates.io this is true. But if you calling install with either —path or —git option the default arg is actually a package. I’m referring to this being a package since it is referring to the name property inside a cargo.toml file, not a published crate. Additionally the error messages such as the “multiple package error” in the original post refer to it as a package not a crate.

cargo install —help:
--git Git URL to install the specified crate from
--path Filesystem path to local crate to install

ARGS:
< crate>...

When using the path option, the path must point to the folder with the package. So a package is not required, as there can only be one cargo.toml per folder. But if provided, the package most match the name of the one in the path provided.

When using the git option, the package is required only when there are multiple packages in the repo. It will not default to the root package. And a path can not be provided with a git option to point to a subfolder containing a package.

I would like to do the following if its agreed as valid solution:
1.) change the help to name the default ARGS from < crate> to <crate(s)/package(s)>.
2.) change the functionality of the git option to the following:
default to the only package with a binary or the root package
if there are multiple packages with binaries and none in the root folder then raise an error:
error: package is required when unable to find default package

@dpurfield
Copy link

I'm also good with any of the suggestions made in #8958.

@teor2345
Copy link

When using the path option, the path must point to the folder with the package. So a package is not required, as there can only be one cargo.toml per folder. But if provided, the package most match the name of the one in the path provided.

I think we've used --path with a workspace containing multiple library and binary packages. But I'd have to double-check how we made it work.

bors added a commit that referenced this issue Mar 13, 2023
`cargo install --git` multiple packages with binaries found hint

### What does this PR try to resolve?
The issues discussed in: #4830

namely this one:
> 4. a multiple packages with binaries found error should give users a hint about how to specify a single crate

I think improving the error message to provide a suggestion is a simple change that would help a lot of people when this happens, sorry if I'm out of line for just opening a PR here :)

### Before
cargo 1.68.0 (115f345 2023-02-26)
![image](https://user-images.githubusercontent.com/14891742/224546157-d9b48bfd-f896-4fd1-9f0a-e04a3ad60ae2.png)

### After
![image](https://user-images.githubusercontent.com/14891742/224546182-d4b451ae-1b28-41b6-9d74-db860532512b.png)

### Additional information

I added in a related test documenting existing behaviours
* multiple_examples_error: "multiple packages with examples found" (i.e. not "binaries")

I added these tests which aren't necessarily related to this PR, but could be considered if the behaviour were to change
* `multiple_binaries_deep_select_uses_package_name`: it uses the name, not the path. Is this a problem for crates with the same name?
* `multiple_binaries_in_selected_package_installs_all`: so `--bins` is implied when a package is specified?
* `multiple_binaries_in_selected_package_with_bin_option_installs_only_one`: demonstrates a use case where `--bin` and `[crate]` are both used
bors added a commit that referenced this issue Mar 13, 2023
`cargo install --git` multiple packages with binaries found hint

### What does this PR try to resolve?
The issues discussed in: #4830

namely this one:
> 4. a multiple packages with binaries found error should give users a hint about how to specify a single crate

I think improving the error message to provide a suggestion is a simple change that would help a lot of people when this happens, sorry if I'm out of line for just opening a PR here :)

### Before
cargo 1.68.0 (115f345 2023-02-26)
![image](https://user-images.githubusercontent.com/14891742/224546157-d9b48bfd-f896-4fd1-9f0a-e04a3ad60ae2.png)

### After
![image](https://user-images.githubusercontent.com/14891742/224546182-d4b451ae-1b28-41b6-9d74-db860532512b.png)

### Additional information

I added in a related test documenting existing behaviours
* multiple_examples_error: "multiple packages with examples found" (i.e. not "binaries")

I added these tests which aren't necessarily related to this PR, but could be considered if the behaviour were to change
* `multiple_binaries_deep_select_uses_package_name`: it uses the name, not the path. Is this a problem for crates with the same name?
* `multiple_binaries_in_selected_package_installs_all`: so `--bins` is implied when a package is specified?
* `multiple_binaries_in_selected_package_with_bin_option_installs_only_one`: demonstrates a use case where `--bin` and `[crate]` are both used
@weihanglo weihanglo added S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. and removed E-help-wanted labels Apr 18, 2023
epage added a commit to epage/cargo that referenced this issue Oct 17, 2023
- That a version is accepted
- That you are selecting from the source a package which led to part of
  the confusion in rust-lang#4830

I wonder if we should rename our `CRATE` value names to `PKG`/`PACKAGE`
epage added a commit to epage/cargo that referenced this issue Oct 17, 2023
- That a version is accepted
- That you are selecting from the source a package which led to part of
  the confusion in rust-lang#4830

I wonder if we should rename our `CRATE` value names to `PKG`/`PACKAGE`
epage added a commit to epage/cargo that referenced this issue Oct 17, 2023
- That a version is accepted
- That you are selecting from the source a package which led to part of
  the confusion in rust-lang#4830

I wonder if we should rename our `CRATE` value names to `PKG`/`PACKAGE`
epage added a commit to epage/cargo that referenced this issue Oct 18, 2023
- That a version is accepted
- That you are selecting from the source a package which led to part of
  the confusion in rust-lang#4830

I wonder if we should rename our `CRATE` value names to `PKG`/`PACKAGE`
epage added a commit to epage/cargo that referenced this issue Oct 18, 2023
- That a version is accepted
- That you are selecting from the source a package which led to part of
  the confusion in rust-lang#4830

I wonder if we should rename our `CRATE` value names to `PKG`/`PACKAGE`
bors added a commit that referenced this issue Oct 18, 2023
fix(help):Clarify install's positional

### What does this PR try to resolve?

- That a version is accepted
- That you are selecting from the source a package which led to part of
  the confusion in #4830

I wonder if we should rename our `CRATE` value names to `PKG`/`PACKAGE`

While doing this, I decided to fix the inconsistency in how we handle value names in help.

### How should we test and review this PR?

### Additional information
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` Command-install S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants