Skip to main content

Questions tagged [rust-cargo]

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

rust-cargo
Filter by
Sorted by
Tagged with
410 votes
4 answers
156k views

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 ...
Andrew Wagner's user avatar
368 votes
7 answers
106k views

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, ...
BitTickler's user avatar
  • 11.6k
287 votes
24 answers
160k views

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 ...
Naruto Sempai's user avatar
284 votes
5 answers
59k views

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 ...
Jimmy's user avatar
  • 36.6k
260 votes
3 answers
114k views

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 ...
RallionRl's user avatar
  • 2,793
250 votes
5 answers
186k views

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 ...
Filip Allberg's user avatar
168 votes
5 answers
60k views

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. ...
w.brian's user avatar
  • 17k
163 votes
1 answer
77k views

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 ...
ideasman42's user avatar
  • 46.2k
128 votes
1 answer
51k views

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 ...
Soham Chowdhury's user avatar
118 votes
1 answer
21k views

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's user avatar
  • 14.4k
109 votes
6 answers
73k views

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 ...
user51's user avatar
  • 9,823
100 votes
2 answers
49k views

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. ...
s3rvac's user avatar
  • 10.1k
95 votes
3 answers
30k views

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. ...
Linear's user avatar
  • 21.8k
95 votes
8 answers
36k views

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 ...
aij's user avatar
  • 6,341
83 votes
5 answers
72k views

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, ...
Stepan Yakovenko's user avatar
82 votes
4 answers
41k views

How to get assembly output from building with Cargo?

While I've seen docs on using rustc directly to output assembly, having to manually extract commands used by Cargo and edit them to write assembly is tedious. Is there a way to run Cargo that writes ...
ideasman42's user avatar
  • 46.2k
81 votes
1 answer
53k views

How to run a specific unit test in Rust?

I have unit tests in a package named school-info and there is a test function called repeat_students_should_not_get_full_marks. I can run all tests in the module by cargo test --package school_info. ...
Kalanamith's user avatar
  • 20.2k
77 votes
4 answers
35k views

How do I list all of the packages I've installed globally with cargo install?

I've installed several CLI tools using cargo install (for instance, ripgrep). How do I see a list of all the crates I've downloaded using cargo install? Sort of like apt list --installed but for cargo?...
almel's user avatar
  • 7,688
73 votes
3 answers
18k views

How to opt out of running a doc test?

I'm writing a Rust library and I want to provide examples in my documentation that compile as part of running cargo test do not run. Is this possible? I'm writing a database client library, and ...
Craig M. Brandenburg's user avatar
66 votes
2 answers
80k views

How to clear the Cargo cache?

When I run cargo build, various libs get stored within the folder /usr/local/lib/rustlib/. What is the correct way to clear these libs? I could rm these files manually, but would that be the right ...
bojangle's user avatar
  • 1,088
65 votes
3 answers
39k views

How to include files from same directory in a module using Cargo/Rust?

I have a Cargo project consisting of three files in the same directory: main.rs, mod1.rs and mod2.rs. I want to import functions from mod2.rs to mod1.rs the same way I would import functions from ...
Neo's user avatar
  • 3,686
64 votes
2 answers
60k views

How to execute cargo test using the nightly channel?

I'm trying to run my tests with nightly Rust using Windows Powershell. I run cargo test in the directory, and I get Compiling rustcraft v0.1.0 (file:///C:/Users/Phoenix/Desktop/Rust/rustcraft) error[...
Phoenix's user avatar
  • 1,703
61 votes
4 answers
49k views

How do I use conditional compilation with `cfg` and Cargo?

I want to conditionally compile my source code using cfg with Cargo, after Googling for a while, it seems that the solution is to use cargo --features. http://doc.crates.io/manifest.html I tried ...
盛安安's user avatar
  • 1,191
60 votes
6 answers
26k views

Can Cargo download and build dependencies without also building the application?

Is there a way to tell Cargo to install and build all my dependencies, but not attempt to build my application? I thought cargo install would do that, but it actually goes all the way to building my ...
Tomas Aschan's user avatar
  • 59.8k
58 votes
5 answers
40k views

How to move tests into a separate file for binaries in Rust's Cargo?

I created a new binary using Cargo: cargo new my_binary --bin A function in my_binary/src/main.rs can be used for a test: fn function_from_main() { println!("Test OK"); } #[test] fn my_test() {...
ideasman42's user avatar
  • 46.2k
57 votes
2 answers
28k views

How do you enable a Rust "crate feature"?

I'm trying to use rand::SmallRng. The documentation says This PRNG is feature-gated: to use, you must enable the crate feature small_rng. I've been searching and can't figure out how to enable "...
brundolf's user avatar
  • 1,410
56 votes
2 answers
19k views

How can I locate resources for testing with Cargo?

I'm on a project interacting with files, and I would like to use text files to test my work. However tests aren't run from the tests/ directory, and thus I cannot reliably find them when running cargo ...
Léo Ercolanelli's user avatar
56 votes
6 answers
20k views

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 ...
stuart's user avatar
  • 2,165
55 votes
2 answers
25k views

How to specify a certain commit in dependencies in Cargo.toml?

I am trying to configure my Rust project with an external dependency in GitHub. Unfortunately, some last commits made some changes in interfaces so I am unable to use the latest version. The ...
Fomalhaut's user avatar
  • 9,241
50 votes
1 answer
12k views

Can't use `-Z macro-backtrace` unstable option with `cargo`

I am writing rust macros and came across an error about my macro I can't understand. In hope of understanding it better, I tried to follow the compiler's advice by setting the -Z macro-backtrace ...
Dincio's user avatar
  • 1,042
49 votes
2 answers
35k views

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 ...
user avatar
49 votes
2 answers
54k views

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 ...
Maik Klein's user avatar
49 votes
2 answers
16k views

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: ---- ...
dhardy's user avatar
  • 11.8k
48 votes
7 answers
34k views

How to run cargo fmt on save in vscode?

Is it possible to make Visual Studio Code run cargo fmt on file save?
s4eed's user avatar
  • 7,673
48 votes
7 answers
42k views

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 <omitted>" ] (but the ...
wogsland's user avatar
  • 9,372
48 votes
1 answer
22k views

Error installing a crate via cargo: specified package has no binaries

I'm trying to install a Rust crate on my system (Arch Linux) using Cargo. I can search for crates and find what I need, for example: $ cargo search curl | head -n3 Updating registry `https://...
q9f's user avatar
  • 11.7k
46 votes
3 answers
59k views

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 ...
antono's user avatar
  • 1,028
46 votes
1 answer
55k views

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 ...
mandeep's user avatar
  • 569
46 votes
2 answers
18k views

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 ...
Fraser's user avatar
  • 77.3k
44 votes
5 answers
46k views

How do I use external crates in Rust?

I'm trying to work with the rust-http library, and I'd like to use it as the basis for a small project. I have no idea how to use something that I can't install via rustpkg install <remote_url>....
lucperkins's user avatar
43 votes
4 answers
29k views

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 │  ...
Muhammad Lukman Low's user avatar
41 votes
3 answers
32k views

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's user avatar
  • 2,783
40 votes
1 answer
8k views

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 ...
Zizheng Tai's user avatar
  • 6,460
39 votes
3 answers
25k views

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 ...
ideasman42's user avatar
  • 46.2k
38 votes
2 answers
71k views

How to pass RUST_BACKTRACE=1 when running a Rust binary installed in Debian?

When I run a binary using cargo, I have the option to run it as follows - bash -c "RUST_BACKTRACE=1 cargo run --bin my_binary" This gives me a stack trace when the binary hits an error. But when I ...
Rajeev Ranjan's user avatar
37 votes
7 answers
46k views

rustup gives command not found error with zsh even after installing with brew

I installed rustup with brew command but still says that rustup command is not found. I am not sure if I am missing any installation step. Any help would be appreciated.
Rohith Joseph's user avatar
37 votes
3 answers
9k views

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 ...
Constantine's user avatar
  • 1,982
37 votes
2 answers
7k views

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 ...
eonil's user avatar
  • 85.2k
36 votes
10 answers
30k views

How to work with OpenSSL for Rust within a Windows development environment

I can't build my Rust project when I add an SSL dependency in my cargo file. This isn't new to Windows, but I'd like to resolve the issue such that I can use Powershell and native Windows development ...
Samson G.'s user avatar
  • 449
36 votes
3 answers
7k views

How do I prevent `rust doc` from adding dependencies to documentation?

I've just started playing with Rust and was trying to generate docs for the code I've written. When I issued cargo doc, I saw something a little weird. 21:53 $ cargo doc Compiling regex-syntax v0....
erip's user avatar
  • 16.8k

1
2 3 4 5
48