In another post I realized that one of my annoyances with pulling dependencies for cargo is that the easiest way to use the dependencies is to switch to using the Cargo build system itself (instead of just plain old rustc). I don’t even know how to do it otherwise, I never used any dependencies pre-Cargo.
What I’d like (and I’m sure this has already been mentioned and discussed), is have some global package installation using Cargo, and then being able to access those crates with just an extern crate declaration. The code could still be built with just rustc file.rs with no extra command line flags.
If this is on the roadmap for Cargo, is it something planned for the near future or much later on? Are there any challenges that make this tricky and block it from being done currently, or are there simply more immediate tasks that need to be done before this?
I can, but I don’t want to. Sometimes I just want to do simple stuff without cargo, maybe write a 100 line rust script to test something out. Creating a Cargo project just for that is kind of annoying.
I love that in python that if there’s some library I need to use, I can just do pip install foo and just start using foo in any python script in any project.
Note that having a global package installation like pip is definitely something Cargo avoids. Even the Python community frowns upon global installs, recommending the use of virtualenv for local dependencies..
I don't like "global package installation", but I do like the idea of "global package caching". It would be nice to not have to constantly re-build dependencies over and over again when building isolated libraries.
On a semi-unrelated note:
Do you mean embedding the dependency information in the .rs itself? Because I'd love some sort of Rust script runner. It's a bit of a pain to be helping someone on IRC/Reddit/SO and have to set up a new cargo package in a directory somewhere just to depend on something for a ten line program. Blah.
It's a bit of a pain to be helping someone on IRC/Reddit/SO and have to set up a new cargo package in a directory somewhere just to depend on something for a ten line program.
It's things like this why I want this feature. I agree 100% that when I'm developing some full blown python application I'll use virtualenv, but in my day to day work I'm not. I'm writing scripts for myself (and only for myself), running certain computations in a REPL, or other tasks (like testing someones code on SO), and it's nice I don't have to do a whole virtualenv setup for python, but currently I have to do that for Rust.
I'd like to see this RFC that was mentioned. When I hear "custom preludes", it doesn't immediately seem like what I'm asking for.
I guess an good compromise would be a global package cache and in-file dependency declaration.
I also have the requirement for small programs which I just don’t think they need an independent directory. But I do see the pain that a global package installation would have.
But in-file dependency declaration would solve both of them, the only problem is when and where should the dependencies be installed. That would need a global cache then.
I should note that cargo-script has made me want more aggressive caching even more.
I mean, the following program runs instantaneously, but takes sixteen seconds to fetch and build its dependencies, and it only directly depends on one crate. cargo-script can only do so much to help.
Why don’t you use your distro’s package manager for this sort of thing? After all, that’s its prupose.
In that regard, it would by nice if rustc / cargo worked with package managers more seamlessly. For example, sometimes cargo projects won’t build when there’s a dependency already present in the system and cargo gets confised because it doesn’t know against which one to link (either local or system one).