Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRFC: Add `cargo install` #1200
Conversation
alexcrichton
added
the
T-dev-tools
label
Jul 10, 2015
nagisa
reviewed
Jul 10, 2015
| 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. |
This comment has been minimized.
This comment has been minimized.
nagisa
Jul 10, 2015
Contributor
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.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 11, 2015
Author
Member
Ah yes I had forgotten about my intention to do this. I'm thinking something along the lines of:
--rootis an argument to theinstallanduninstallsubcommands to specify the root manually.- The environment variable
CARGO_INSTALL_ROOTcan specify the root - The configuration key
install.rootcan specify the root - Finally,
$CARGO_HOME/binis used.
How does that sound?
This comment has been minimized.
This comment has been minimized.
SimonSapin
Jul 12, 2015
Contributor
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.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 12, 2015
Author
Member
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.
nagisa
reviewed
Jul 10, 2015
| of `cargo build`. For example the following items will not be available to | ||
| installed crates: | ||
|
|
||
| * Dynamic native libraries built as part of `cargo build`. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 11, 2015
Author
Member
@nagisa can you elaborate on your concern a bit? Do you think it's enough of a downside to require fixing now versus punting to a later date? I'm of the impression that most native dependencies built as part of the build process are statically linked, in which case this is not a problem. I'm unaware of any native dependency that builds a dynamic library as part of the build process.
Put another way, I expect this limitation to not actually affect many crates today, so I don't feel it's necessary to fix immediately.
This comment has been minimized.
This comment has been minimized.
nagisa
Jul 11, 2015
Contributor
Now that you mention it, yes, most binaries will be linked fully statically. Except there will surely exist those few odd binaries that link to something dynamically and fail to run at all, no matter what.
Sure, that’s probably not something worth putting a lot of attention to for the first viable release of the functionality.
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
So, the alternative is making sure those sort of package managers have (cross-platform...) support for Rust code as effortless as the |
This comment has been minimized.
This comment has been minimized.
|
Really big |
This comment has been minimized.
This comment has been minimized.
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 |
Gankro
reviewed
Jul 11, 2015
|
|
||
| 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 |
This comment has been minimized.
This comment has been minimized.
Gankro
reviewed
Jul 11, 2015
|
|
||
| ### System Package Managers | ||
|
|
||
| The primary alternative to putting effort behind `cargo install` it to instead |
This comment has been minimized.
This comment has been minimized.
Gankro
reviewed
Jul 11, 2015
| have access to these libraries (as Cargo retains control over dependencies). It | ||
| may mean that normal invocations of `rustc` have access to these libraries (e.g. | ||
| for small one-off scripts), but it's not clear that this is worthwhile enough to | ||
| support installing libraries yet. |
This comment has been minimized.
This comment has been minimized.
Gankro
Jul 11, 2015
Contributor
Also the lack of any kind of stable ABI means compatibility headaches.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 11, 2015
Author
Member
Yeah that's when Cargo would have to recompile libraries if the Rust compiler changes (e.g. via multirust or via a normal update). It already does this for local build directories but I think it definitely reduces the usefulness of cargo install for libraries as well.
This comment has been minimized.
This comment has been minimized.
nixpulvis
Aug 28, 2015
Unifying multirust and cargo would help dramatically with this. I very often find myself wanting a number of libraries for one of Rust files.
This comment has been minimized.
This comment has been minimized.
jdub
commented
Jul 11, 2015
|
It'd be cool if
|
This comment has been minimized.
This comment has been minimized.
jarcane
commented
Jul 11, 2015
|
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 comment has been minimized.
This comment has been minimized.
|
Also, while linux distros have package managers, Windows really does not. |
SimonSapin
reviewed
Jul 11, 2015
| Installing new crates: | ||
| cargo install [options] | ||
| cargo install [options] [-p CRATE | --package CRATE] [--vers VERS] |
This comment has been minimized.
This comment has been minimized.
SimonSapin
Jul 11, 2015
Contributor
Gratuitous bikeshedding: "vers" sounds weird (and spells like "worm" in French). I’d prefer "ver" or "version".
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 11, 2015
Author
Member
We currently have precedent for this with cargo yank --vers, and unfortunately the best word, version, is already taken with the cargo --version flag :(
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 12, 2015
Author
Member
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!
This comment has been minimized.
This comment has been minimized.
tshepang
Jul 17, 2015
Contributor
We can still have --version without a conflict right?
$ cargo --version
0.4.0
$ cargo install --package foo --version 0.2.1
....
This comment has been minimized.
This comment has been minimized.
withoutboats
Jul 30, 2015
Contributor
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]?
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 31, 2015
Author
Member
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.
This comment has been minimized.
This comment has been minimized.
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). |
This comment has been minimized.
This comment has been minimized.
cosmo0920
commented
Jul 11, 2015
|
|
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
jarcane
commented
Jul 11, 2015
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 |
This comment has been minimized.
This comment has been minimized.
|
@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 comment has been minimized.
This comment has been minimized.
|
This also encourages everyone to upload all their Rust programs to crates.io, which gives us more robust coverage for Crater. |
This comment has been minimized.
This comment has been minimized.
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, |
alexcrichton
added some commits
Jul 11, 2015
SimonSapin
reviewed
Jul 11, 2015
| installed crates: | ||
|
|
||
| * Dynamic native libraries built as part of `cargo build`. | ||
| * Native assets such as images not included in the binary itself. |
This comment has been minimized.
This comment has been minimized.
SimonSapin
Jul 11, 2015
Contributor
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.
This comment has been minimized.
This comment has been minimized.
nrc
Jul 13, 2015
Member
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,
SimonSapin
reviewed
Jul 11, 2015
| 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. |
This comment has been minimized.
This comment has been minimized.
SimonSapin
Jul 11, 2015
Contributor
Should there be a --target argument to override this, separately from where Cargo keeps its cache files?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 12, 2015
Author
Member
Ah yeah @nagisa already mentioned a concern about this, and I'm curious what you think about my suggestion?
This comment has been minimized.
This comment has been minimized.
|
Where would the |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
ruuda
commented
Jul 12, 2015
|
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. |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
The tools team has decided to place this RFC into its week-long final comment period. |
alexcrichton
added
the
final-comment-period
label
Jul 29, 2015
This comment has been minimized.
This comment has been minimized.
|
It would be great if this had a |
This comment has been minimized.
This comment has been minimized.
gsingh93
commented
Jul 29, 2015
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
I agree with @gsingh93 |
This comment has been minimized.
This comment has been minimized.
eternaleye
commented
Jul 30, 2015
|
Personally, I feel that'd be better as a separate "cargo sources" subcommand or similar. |
This comment has been minimized.
This comment has been minimized.
|
I'll look into writing something up. |
This comment has been minimized.
This comment has been minimized.
gsingh93
commented
Jul 30, 2015
|
I made a separate issue for the "cargo sources" command: rust-lang/cargo#1861 |
This comment has been minimized.
This comment has been minimized.
RAOF
commented
Aug 4, 2015
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 |
This comment has been minimized.
This comment has been minimized.
eternaleye
commented
Aug 4, 2015
|
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). |
This comment has been minimized.
This comment has been minimized.
|
The conclusion of the libs team was to accept this RFC, so I shall merge. |
alexcrichton
merged commit 7c18705
into
rust-lang:master
Aug 14, 2015
This comment has been minimized.
This comment has been minimized.
|
Er, tools team* |
This comment has been minimized.
This comment has been minimized.
mikeyhew
commented
Aug 15, 2015
|
I guess I'm late to the party, but the problem I see with Since it's already been decided that |
This comment has been minimized.
This comment has been minimized.
|
@mikeyhew because cargo performs static linking and Rust requires explicit declaration of linked libraries in the code (the The most analogous command to |
This comment has been minimized.
This comment has been minimized.
nixpulvis
commented
Aug 28, 2015
|
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. |
This comment has been minimized.
This comment has been minimized.
nixpulvis
commented
Aug 28, 2015
I also feel like this is cumbersome. People coming from other tools like |
This comment has been minimized.
This comment has been minimized.
|
I agree that we should allow leaving off the |
This comment has been minimized.
This comment has been minimized.
nixpulvis
commented
Aug 28, 2015
|
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 uninstallJust a thought. Another option for making the list command a bit better might be to have another subcommand |
This comment has been minimized.
This comment has been minimized.
|
@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 comment has been minimized.
This comment has been minimized.
hunterboerner
commented
Sep 9, 2015
This would be interesting to see. It would eliminate the need for users to install cargo/manually install binaries. |
This comment has been minimized.
This comment has been minimized.
vyp
commented
Sep 9, 2015
|
@hunterboerner similarly, could also adopt nix/guix. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
For those interested, I've now posted an implementation of |
alexcrichton commentedJul 10, 2015
Add a new subcommand to Cargo,
install, which will install[[bin]]-basedpackages onto the local system in a Cargo-specific directory.
Rendered