-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Add cargo install
#1200
RFC: Add cargo install
#1200
Conversation
Add a new subcommand to Cargo, `install`, which will install `[[bin]]`-based packages onto the local system in a Cargo-specific directory.
various locations and specifying what should be installed. All binaries will be | ||
stored in the **cargo-local** directory `CARGO_HOME/bin`. This is typically | ||
`$HOME/.cargo/bin` but the home directory can be modified via the `$CARGO_HOME` | ||
environment variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally needs a $CARGO_INSTALL_HOME
which overrides everything, because nobody wants to get binaries stored in their $XDG_CONFIG_HOME
to which their $CARGO_HOME
is very likely to be set to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes I had forgotten about my intention to do this. I'm thinking something along the lines of:
--root
is an argument to theinstall
anduninstall
subcommands to specify the root manually.- The environment variable
CARGO_INSTALL_ROOT
can specify the root - The configuration key
install.root
can specify the root - Finally,
$CARGO_HOME/bin
is used.
How does that sound?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would binaries go into $root
or $root/bin
? With the latter, cargo install
could later write things in $root/share
or $root/lib
, and there is precedent in ./configure
scripts to name it prefix rather than root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm yes I do think that going into $root/bin
is probably the best option for now to give ourselves some room to expand in the future like this. So long as it's predictable I don't think it's the end of the world.
I’m somewhat against this. Just because we already have a few awesome system package managers that make installing “foreign” packages relatively painless and if you/your system doesn’t use one of these, it should totally start doing so. That is, I believe cargo (and similar tools such as pip, cabal, etc) are not a place for such functionality. |
So, the alternative is making sure those sort of package managers have (cross-platform...) support for Rust code as effortless as the |
Really big 👍 here, this is something I've wanted since day 1. |
I subscribe to the idea of package manager providing the necessary glue. That strategy has worked out spectacularly for nix with cabal2nix, for example. We also already provide a good tool ( History has also proven that any notable packages (e.g. I certainly agree that building packages for all the package managers or trying to interface with all of them is outrageous. On the other hand, I don’t see why we should bother introducing tools, which are essentially an alias for |
|
||
Cargo attempts to be as flexible as possible in terms of installing crates from | ||
various locations and specifying what should be installed. All binaries will be | ||
stored in the **cargo-local** directory `CARGO_HOME/bin`. This is typically |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$CARGO_HOME
It'd be cool if
|
Personally speaking, I'm not sure I see what the advantage of locally installing libraries like this is. By day I work in Clojure, and I've rather become fond instead of the behavior of leiningen and cargo of instead grabbing and caching libraries as needed at build time, adding a library being as simple as adding a line to the dependencies (with the added bonus that the config and lock files will ensure we stick to a consistent version of that library for future builds). Perhaps I'm missing something, but it just doesn't seem like something I'm likely to use much. I do like the sound of being able to add cargo sub-commands more easily, and perhaps this might be a solution for things like SDL which depend on external non-rust libs being more easily packaged (as opposed to now, where to build mooneye-gb I had to download SDL myself and manually extract the right files to the right Rust dirs). |
👍 This is a great way to make it easy to distribute Rust binaries. Large Rust projects will work their way into the package repositories of many Linux distros, but that isn't the only use case for Also, while linux distros have package managers, Windows really does not. |
|
||
Installing new crates: | ||
cargo install [options] | ||
cargo install [options] [-p CRATE | --package CRATE] [--vers VERS] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gratuitous bikeshedding: "vers" sounds weird (and spells like "worm" in French). I’d prefer "ver" or "version".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently have precedent for this with cargo yank --vers
, and unfortunately the best word, version
, is already taken with the cargo --version
flag :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about --precise
, like in cargo update
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm perhaps, but precise
was actually added first to cargo update
for the SHA of a git repository, but it may apply here as well!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can still have --version
without a conflict right?
$ cargo --version
0.4.0
$ cargo install --package foo --version 0.2.1
....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does cargo install
require a -p
or --package
instead of pulling from the registry by default (which I would expect to be the most common use)? Is there an argument parsing issue with this being cargo install [options] <crate> [--vers VERS]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's an ambiguity, but it seems relatively more consistent with --git
and --path
to have a flag to specify where you're pulling the crate from.
It doesn’t even install libraries, nor does it install native dependencies either. Only binaries (i.e. things defined in
Sorry to disappoint you! OneGet is shipping with Windows 10, and is probably better than apt or rpm in featuring a functionality to discover and install packages from language specific package managers (and there’s Cargo/Rust on the TODO list). |
👍 for me, because windows folks dose not have package manager until Windows 10. |
I'm in favor of this. Writing a small, useful CLI tool in Rust is pretty easy, but getting it into the big package managers is a lot of work. |
This is a use I hadn't considered. I was thinking about that problem the other day with wf; if it wanted to actually package it for distribution anywhere, or even just installing it to the right places locally, I'd have to muck with make or apt, or fiddle with a lot of stuff manually. If Cargo offered some installation configuration as part of the Cargo.toml or as |
@nagisa while package managers enable easy (un)installation of major stable software, they fail to adequately address minor or very unstable software, in my opinion. Cargo enables us all to share our random unstable one-off libraries. It seems reasonable to extend that to programs. |
This also encourages everyone to upload all their Rust programs to crates.io, which gives us more robust coverage for Crater. |
I tried to discuss this in the alternatives section (although I could likely expand more), but I feel like the key part of this sentence is "it should totally start doing so". Despite whatever we feel, there's no way these sorts of agnostic package managers will make their way onto all platforms overnight, and it's becoming clear over time that we need a solution to this problem sooner rather than later.
I 100% agree with this, but I'm not sure it precludes the existence of
I also totally agree with this, and I expect many popular Rust packages will follow suit.
The key part here is ease of installation. As a user of Cargo who wants to quickly get some new subcommands or some ubiquitous rust-specific tools,
I would be a little uneasy about adding a whole bunch of magic because it often leads to ambiguities. For example if we are given a URL, is it a git repo? mercurial? SVN? tarball? Having to say Similarly having to say
Ah just to clarify, |
installed crates: | ||
|
||
* Dynamic native libraries built as part of `cargo build`. | ||
* Native assets such as images not included in the binary itself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d like to have this eventually (a convention of where files go, cargo install
copying them, and maybe some helper functions for programs to find them), but it doesn’t have to be in the first iteration of cargo install
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happier to see install scripts supported in the same manner as build scripts, but agree that it can wait for later iteration,
Where would the |
This doesn't disappoint me at all. Your tone here is a bit antagonistic. I do not think it is wise to "magic"ally inferring the type of source from user input; what kind of source each type of input refers to is not static across different projects and different times, and its better to be explicit here. |
I expect the implementation would cache all source files as Cargo does today already (e.g. have a local database of git repos, crates.io, etc), but the artifacts would be built as part of a temporary directory. |
I too feel that this should not try to replace system package managers. Even though
it will likely get abused. Too often I encounter a program with an installation section reading
So now I first have to install yet another package manager, add its binary directory to my path, etc. And after a system-wide update, I have to run the update command for each of those package managers … Preparing system packages might have high overhead for developers, but non-system packages have high overhead for users. On the other hand, one cannot expect the developer to maintain a package for every system package manager out there either and it is hard to get into official repositories, so I don’t know whether this problem can be solved at all. |
|
I don't see what we gain by having an In the absence of a strong argument not to provide a convenience for this common sequence, I would like to include it. |
The tools team has decided to place this RFC into its week-long final comment period. |
It would be great if this had a |
@withoutboats I'd like that feature as well, but I think it should apply to any type of crate (binary or library), and should be proposed separately. |
I agree with @gsingh93 |
Personally, I feel that'd be better as a separate "cargo sources" subcommand or similar. |
I'll look into writing something up. |
I made a separate issue for the "cargo sources" command: rust-lang/cargo#1861 |
Properly designed, I rather think this is actually a prerequisite for good system PM integration - specifically, we'll want the system PM to be able to install rust libraries in such a way that Anyway, I'm glad that not only are other people thinking about distro-integration topics, they're being more active about it than I am 😄 |
Sure - mainly, my concerns revolve around the pitfalls it not being properly designed. Using a single central database that gets modified in-place, putting it somewhere contrary to FS guidelines, choosing a naming system that results in collisions, etc. If it winds up being more like pkg-config, I entirely agree - though for Rust, I think it'd need an additional level of hierarchy, such as In addition, if more than one installed crate would satisfy a dependency, it's crucial that the PM is able to control which is used - on a source distro like Exherbo, for example, failing to ensure that could result in a library being spuriously treated as unused, breaking stuff up the dependency tree (in the case of dynamic linking). |
The conclusion of the libs team was to accept this RFC, so I shall merge. |
Er, tools team* |
I guess I'm late to the party, but the problem I see with Since it's already been decided that |
@mikeyhew because cargo performs static linking and Rust requires explicit declaration of linked libraries in the code (the The most analogous command to |
To make the goal of this command a bit more clear I'd update the description,
to something illustrating that it's just compiling a binary and putting it in a bindir. Maybe something like
I know it explains more below, but this would make it clear from the get go. If this command ever does system wide library installation we could change the wording then. |
I also feel like this is cumbersome. People coming from other tools like |
I agree that we should allow leaving off the |
It might be too late for this, but I had an idea as I was reading through this. Since this command is really not installing a crate, it's just dealing with binaries, at least for now. And the details of dealing with binaries are different from the details of libraries, why not make the command This also might help with the currently odd cargo binaries list
cargo binaries install
cargo binaries uninstall Just a thought. Another option for making the list command a bit better might be to have another subcommand |
@ruud-v-a, I agree. Whether you like it or not, people will use this as a replacement for another package manager. I would rather have a way to generate the package for the specific package manager (such as homebrew, aptitude, pacman, rpm, and so on), as @alexcrichton mentions. Maybe using a subcommand like |
This would be interesting to see. It would eliminate the need for users to install cargo/manually install binaries. |
@hunterboerner similarly, could also adopt nix/guix. |
I am of the belief that generating distributable packages with all the metadata and icons and whatnot is better handled by a tool on top of Cargo, and not Cargo itself. |
For those interested, I've now posted an implementation of |
Add a new subcommand to Cargo,
install
, which will install[[bin]]
-basedpackages onto the local system in a Cargo-specific directory.
Rendered