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
45
votes
6 answers

failed to parse manifest - no targets specified

I am new to Rust and attempting to build a test project with Cargo. My Cargo.toml looks like: [package] name = "rust-play" version = "0.0.1" authors = [ "Bradley Wogsland " ] (but the actual TOML file doesn't omit my email). When I cargo…
wogsland
  • 9,106
  • 19
  • 57
  • 93
45
votes
2 answers

How do I debug a failing cargo test in GDB?

I have a failing Cargo test: $ cargo test [snip] Running target/gunzip-c62d8688496249d8 running 2 tests test test_extract_failure ... FAILED test test_extract_success ... ok failures: ---- test_extract_failure stdout ---- task…
dhardy
  • 11,175
  • 7
  • 38
  • 46
43
votes
2 answers

How to pass rustc flags to cargo?

I am trying to disable dead code warnings. I tried the following cargo build -- -A dead_code ➜ rla git:(master) ✗ cargo build -- -A dead_code error: Invalid arguments. So I am wondering how would I pass rustc arguments to cargo?
Maik Klein
  • 15,548
  • 27
  • 101
  • 197
41
votes
1 answer

How do I set environment variables with Cargo?

I have a dependency listed in Cargo.toml that needs a specific environment variable set. I can run export FOO=bar in bash and all works well, but for the life of me I can't figure out how to export this environment variable at compile time with…
mandeep
  • 519
  • 1
  • 4
  • 6
41
votes
3 answers

How can I set default build target for Cargo?

I tried to make 'Hello World' in Rust using this tutorial, but the build command is a bit verbose: cargo +nightly build --target wasm32-unknown-unknown --release Is it possible to set the default target for cargo build?
antono
  • 978
  • 1
  • 7
  • 18
39
votes
4 answers

How do I tell Cargo to build files other than main.rs?

Here is my directory structure: lowks@lowkster ~/src/rustlang/gettingrusty $ tree . . ├── Cargo.lock ├── Cargo.toml ├── foo.txt ├── src │   ├── boolean_example.rs │   ├── function_goodbye_world.rs │   ├── listdir.rs │   ├── looping.rs │   ├──…
Muhammad Lukman Low
  • 8,177
  • 11
  • 44
  • 54
38
votes
1 answer

Can tests be built in release mode using Cargo?

I'm using cargo build --release to build my project in release configuration and cargo test to build and run my tests. However, I'd like to also build my tests in release mode; can this be done using cargo?
Fraser
  • 74,704
  • 20
  • 238
  • 215
37
votes
3 answers

How do I change the default rustc / Cargo linker?

I would like to make rustc use lld as a linker instead of ld in a particular crate. So I create .cargo/config in my project directory with the following: [target.x86_64-unknown-linux-gnu] …
kreo
  • 2,613
  • 2
  • 19
  • 31
36
votes
3 answers

Is there a list of all cfg features?

Rust has the ability to check configuration at build time with, e.g., #[cfg(target_os = "linux")] or if cfg!(target_os = "linux") {...}, where target_os is a feature. Is there a list of all (or, at least, commonly used) features that can be checked…
ideasman42
  • 42,413
  • 44
  • 197
  • 320
35
votes
4 answers

How to tell what "features" are available per crate?

Is there a standard way to determine what features are available for a given crate? I'm trying to read Postgres timezones, and this says to use the crate postgres = "0.17.0-alpha.1" crate's with-time or with-chrono features. When I try this in my…
stuart
  • 1,785
  • 2
  • 26
  • 38
35
votes
1 answer

Is `cargo clippy` a superset of `cargo check`?

I'm trying to build and test my Rust code with a CI, and I'm wondering whether cargo clippy (potentially with options) covers everything that cargo check does. Do I only need to run cargo clippy, or do I need to run both?
Zizheng Tai
  • 6,170
  • 28
  • 79
33
votes
2 answers

Cannot find tokio::main macro?

I am creating a sample Rust project in my Windows system to download a file by HTTP GET request in async mode. My code is as follows (same as the code mentioned in the Rust Cookbook): extern crate error_chain; extern crate tempfile; extern crate…
user14200418
32
votes
3 answers

What is an idiomatic way to have shared utility functions for integration tests and benchmarks?

I have Rust project with both integration tests (in the /tests dir) and benchmarks (in the /benches dir). There are a couple of utility functions that I need in tests and benches, but they aren't related to my crate itself, so I can't just put them…
Constantine
  • 1,802
  • 3
  • 23
  • 37
32
votes
2 answers

What files in a Cargo project should be in my .gitignore?

I created a "hello world" Rust app using cargo new. When I executed git status it showed a bunch of files: A rust/welcomec/Cargo.lock A rust/welcomec/Cargo.toml A rust/welcomec/src/main.rs A rust/welcomec/target/debug/.cargo-lock A …
labyrinth
  • 13,397
  • 7
  • 35
  • 44
30
votes
3 answers

Why can a Cargo package only have one library target?

According to its manual, Cargo packages can have multiple executable targets, but only one library target is allowed. A package can contain zero or one library crates and as many binary crates as you’d like. There must be at least one crate…
eonil
  • 83,476
  • 81
  • 317
  • 516