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
22
votes
2 answers

Is there a command to automatically add a crate to my Cargo.toml?

I expected there to be something like: cargo install stopwatch but could not find it in the docs. Finding the package version and manually adding the package to .toml: [dependencies] stopwatch="0.0.6" Does not feel automated enough. :)
Johan Larsson
  • 17,112
  • 9
  • 74
  • 88
22
votes
2 answers

Copy files to the target directory after build

Let's assume I have a game with the following directory structure: /src /resources Cargo.toml I would like cargo build to copy the files in the resources directory and paste them in the same directory as the executable file. I know it is possible…
aochagavia
  • 5,887
  • 5
  • 34
  • 53
22
votes
4 answers

How can I include private modules when generating documentation via Cargo?

I'm currently working on a project with Rust and Cargo. It works well, but I encounter a little issue: for code reuse, most of my project is inside a lib crate. In this crate, a lot of things is private. So when I do cargo doc, I just have…
lthms
  • 509
  • 3
  • 10
21
votes
2 answers

found a virtual manifest at instead of a package manifest

I searched for [rust] "instead of a package manifest" on this site before asking and found no hits. I also read about virtual manifests here but did not resolve my question. My goal is to make changes to azul. To achieve this I read about patching…
Charles
  • 953
  • 1
  • 8
  • 19
21
votes
1 answer

Using a crate in a Cargo project errors with "maybe a missing extern crate"

I started learning Rust today, but I am stuck at this step. I want use the rand crate in my project, so I updated my Cargo.toml as suggested in the tutorial: [package] name = "guessing_game" version = "0.1.0" authors = ["Novice…
Bopsi
  • 2,090
  • 5
  • 36
  • 58
21
votes
1 answer

Run additional tests by using a feature flag to "cargo test"

I have some tests that I would like to ignore when using cargo test and only run when explicitly passed a feature flag. I know this can be done by using #[ignore] and cargo test -- --ignored, but I'd like to have multiple sets of ignored tests for…
Andrew Mackenzie
  • 5,477
  • 5
  • 48
  • 70
21
votes
1 answer

What exactly is considered a breaking change to a library crate?

Rust crates use Semantic Versioning. As a consequence, each release with a breaking change should result in a major version bump. A breaking change is commonly considered something that may break downstream crates (code the depends on the library in…
Lukas Kalbertodt
  • 79,749
  • 26
  • 255
  • 305
21
votes
1 answer

Cross-compilation to x86_64-unknown-linux-gnu fails on Mac OSX

I tried to compile one of my Rust projects to the x86_64-unknown-linux-gnu target: $ cargo build --target=x86_64-unknown-linux-gnu Compiling deployer v0.1.0 (file:///Users/raphael/web/deployer) error: linking with `cc` failed: exit code: 1 | …
rap-2-h
  • 30,204
  • 37
  • 167
  • 263
21
votes
2 answers

Is it possible to disable a single default feature in Cargo?

From reading this page, it states that you need to turn off all defaults to override them. With the exception of the default feature, all features are opt-in. To opt out of the default feature, use default-features = false and cherry-pick…
ideasman42
  • 42,413
  • 44
  • 197
  • 320
21
votes
1 answer

Can I install a library using Cargo without a Cargo.toml?

I am going through Rust's getting started and I need to get the rand crate on my system. I'm not doing the Cargo packaging stuff (e.g. creating Cargo.toml) because I was interested in the language, not packaging. Can I install the rand library on my…
Tomas Tomecek
  • 6,226
  • 3
  • 30
  • 26
21
votes
2 answers

Stack trace with line numbers when running cargo run

Doing RUST_BACKTRACE=1 cargo run gives a stack trace when an error occurs as shown below. Is there any way to get the file & line number instead of the hex address? thread '
' panicked at 'called `Result::unwrap()` on an `Err` value: Parsing:…
Bilal Syed Hussain
  • 8,664
  • 11
  • 38
  • 44
21
votes
3 answers

How to have different dependencies depending on OS family

I'm writing a cross-platform library that has platform specific dependencies, one for unix-like platforms, and one for windows. These crates only compile on specific platforms, wherefore I can't just add them all under dependencies normally. In the…
Bryal
  • 213
  • 2
  • 5
21
votes
2 answers

How do I pin indirect dependencies of a crate?

My project A depends on library B that depends on library C. Library B sets the dependency version to "*" (any) so Cargo will download the latest version of C. How can I instruct Cargo to build library B using a specific version of library C? I'm…
diogovk
  • 2,108
  • 2
  • 19
  • 24
21
votes
3 answers

Multiple Rust source files for cargo

If I have multiple .rs files in the src directory of a Cargo package, what are the rules for visibility, importing, etc.? Currently, any extra (i.e. not the file that is explicitly identified as the source for the executable in Cargo.toml) files are…
fadedbee
  • 42,671
  • 44
  • 178
  • 308
20
votes
2 answers

How do I debug `cargo build` hanging at "Updating crates.io index"?

My Rust project no longer builds after some conflicts between my RLS plugin and terminal build. I searched around the web and found suggestion of removing my ~/.cargo/registry/index/*, but after that I can't even build any project. Now the build…
Fei
  • 1,450
  • 1
  • 17
  • 30