Questions tagged [rust-cargo]

Cargo is the official package manager for the Rust programming language.

Cargo is the official package manager for the Rust programming language. Using a manifest, the programmer can provide metadata about a project, including dependencies, which Cargo can automatically download and compile before compiling the project itself.

You can find more information in the cargo book and browse the crates (Rust packages) in crates.io.

2044 questions
375
votes
4 answers

Package with both a library and a binary?

I would like to make a Rust package that contains both a reusable library (where most of the program is implemented), and also an executable that uses it. Assuming I have not confused any semantics in the Rust module system, what should my…
Andrew Wagner
  • 22,677
  • 21
  • 86
  • 100
336
votes
7 answers

Why are Rust executables so huge?

I find the approach and the way they define the language in the first two chapters of the documentation particularly interesting. So I decided to get my fingers wet and started out with "Hello, world!". I did so on Windows 7 x64, btw. fn main() { …
BitTickler
  • 10,905
  • 5
  • 32
  • 53
265
votes
3 answers

How can a Rust program access metadata from its Cargo package?

How do you access a Cargo package's metadata (e.g. version) from the Rust code in the package? In my case, I am building a command line tool that I'd like to have a standard --version flag, and I'd like the implementation to read the version of the…
Jimmy
  • 35,686
  • 13
  • 80
  • 98
264
votes
30 answers

Cargo build hangs with " Blocking waiting for file lock on the registry index" after building parity from source

I followed the readme instructions for building Parity from source and then executed: cargo build --release ~/.cargo/bin/cargo build --release as instructed, both of which returned the following message while the prompt hung: Blocking waiting for…
Naruto Sempai
  • 6,233
  • 8
  • 35
  • 51
226
votes
3 answers

How can I build multiple binaries with Cargo?

I'd like to make a project with a daemon and a client, connecting through a unix socket. A client and a daemon requires two binaries, so how do I tell Cargo to build two targets from two different sources? To add a bit of fantasy, I'd like to have…
RallionRl
  • 2,453
  • 2
  • 10
  • 9
182
votes
5 answers

Is there a command to update Cargo to the latest official release?

I seem to have diverging versions of rustc and cargo (I think), $ rustc -V rustc 1.9.0 (e4e8b6668 2016-05-18) $ cargo -V cargo 0.10.0-nightly (10ddd7d 2016-04-08) Is there a command akin to pip install --upgrade pip for upgrading cargo? I.e.…
Filip Allberg
  • 3,941
  • 3
  • 20
  • 37
142
votes
5 answers

Does cargo install have an equivalent update command?

I used cargo install to globally install a package, such as rustfmt or racer. How can I update the installed package without first deleting it ( cargo uninstall) and then running cargo install again. Is there an update command?
w.brian
  • 16,296
  • 14
  • 69
  • 118
141
votes
1 answer

How to check release / debug builds using cfg in Rust?

With the C pre-processor it's common to do, #if defined(NDEBUG) // release build #endif #if defined(DEBUG) // debug build #endif Cargo's rough equivalents are: cargo build --release for release. cargo build for debug. How would Rust's…
ideasman42
  • 42,413
  • 44
  • 197
  • 320
120
votes
1 answer

What is a crate attribute and where do I add it?

In order to get a feel for how Rust works, I decided to look at a little terminal-based text editor called Iota. I cloned the repository and ran cargo build only to be told: error: *if let* syntax is experimental help: add #![feature(if_let)] to…
Soham Chowdhury
  • 2,125
  • 2
  • 18
  • 29
107
votes
1 answer

How to define test-only dependencies?

I have a Rust library that implements a lint plugin. I want to include compiletest, but not require it outside of testing. What is the correct way to specify that the dependency is for testing only?
llogiq
  • 13,815
  • 8
  • 40
  • 72
98
votes
6 answers

error[E0554]: #![feature] may not be used on the stable release channel Couldn't install racer using cargo

I'm trying to install racer using cargo, so I executed the command cargo install racer in the terminal and it resulted in the error: error[E0554]: #![feature] may not be used on the stable release channel -->…
user51
  • 8,843
  • 21
  • 79
  • 158
89
votes
2 answers

How to get a release build with debugging information when using cargo?

The following command $ cargo build produces a non-optimized build with debugging information. On the contrary, $ cargo build --release produces an optimized build without debugging information. Is there a way of producing an optimized build with…
s3rvac
  • 9,301
  • 9
  • 46
  • 74
83
votes
3 answers

How can I specify binary-only dependencies?

I have a crate with both a binary and a library. The library is extremely light on dependencies, while the binary requires quite a bit more to, e.g., load files or do scoped parallel things. Currently, I have my Cargo.toml set up like…
Linear
  • 21,074
  • 4
  • 59
  • 70
76
votes
7 answers

How can I get cargo to recompile changed files automatically?

I have heard cargo has the ability to automatically recompile changed source files, but I'm having a hard time figuring out how to tell it to do so. For now, I am manually running cargo build or cargo run every time I want to type check my code. I…
aij
  • 5,903
  • 3
  • 37
  • 41
72
votes
5 answers

How to launch a Rust application from Visual Studio Code?

I have installed the Visual Studio Code extensions for Rust: I want to run my project and I don't understand where to click. I tried clicking Run Task, Run build task, Configure Default build task, but nothing reasonable happens.
Stepan Yakovenko
  • 8,670
  • 28
  • 113
  • 206
1
2 3
99 100