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

What does "manifest path is a virtual manifest, but this command requires running against an actual package" mean?

I'm trying to build a Rust project (xray). When running cargo run I get the following error message error: manifest path D:\xray\building\xray\Cargo.toml is a virtual manifest, but this command requires running against an actual package in this…
Amani
  • 16,245
  • 29
  • 103
  • 153
29
votes
2 answers

Rust constants in different modules?

I have this "main.rs" file which I declare a version constant. pub const VERSION: &'static str = "v2"; mod game; fn main() { do_stuff(); } Then I want to access this global constant in a different module "game.rs": pub fn do_stuff() { …
user3384741
  • 1,261
  • 3
  • 16
  • 21
28
votes
6 answers

How to run cargo fmt on save in vscode?

Is it possible to make Visual Studio Code run cargo fmt on file save?
s4eed
  • 7,173
  • 9
  • 67
  • 104
28
votes
7 answers

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 to work on my Rust project. The dependency in…
Samson G.
  • 369
  • 1
  • 3
  • 7
28
votes
3 answers

How can I specify a custom Cargo output directory?

I put this in my Cargo.toml [build] target-dir = "../my-target" However, Cargo doesn't recognize this key. cargo run --release --bin my_project warning: unused manifest key: build error: failed to open:…
mq7
  • 1,125
  • 2
  • 11
  • 21
28
votes
5 answers

Include git commit hash as string into Rust program

I host a Rust project in git repository and I want to make it print the version on some command. How can I include the version into the program? I thought that the build script could set environment variables which can be used while compiling the…
VP.
  • 15,509
  • 17
  • 91
  • 161
28
votes
2 answers

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.2.2 Compiling libc v0.2.2 Compiling memchr…
erip
  • 16,374
  • 11
  • 66
  • 121
27
votes
2 answers

Should Cargo.lock be committed when the crate is both a rust library and an executable?

I 've read https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html If I understand correctly, when I commit Cargo.lock into my crate (which is both a library and an executable)'s repository, and also, publish it to crates.io, downstream…
Danielhu
  • 499
  • 4
  • 13
26
votes
2 answers

How to idiomatically alias a crate in Rust 2018?

I have a crate foo_sys. In Rust 2015 I used extern crate foo_sys as foo for convenience, but in Rust 2018 extern crate isn't needed anymore and I don't want to use it only for aliasing. When dropping extern crate, I get error[E0463]: can't find…
Tim Diekmann
  • 7,755
  • 11
  • 41
  • 69
26
votes
1 answer

Which files from the target directory are actually required by the executable?

After compiling my program 'zagir', the release folder has the size of more than 200MiB, which is ridiculous for the program I have written. So, I tried to check whether only the 'zagir' executable runs in isolation and it did. But the confusion is…
pepsighan
  • 798
  • 9
  • 17
26
votes
2 answers

What is the intended/planned way of configuring/installing software that uses Rust Cargo as build system?

Existing build systems usually have some kind of install targets, that is used either manually (for installing in /usr/local or other location that user can access) or automatically (by package build systems of binary based distros or by package…
Jaŭhien Piatlicki
  • 843
  • 10
  • 18
25
votes
2 answers

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 create a Debian package for the same binary, how…
Rajeev Ranjan
  • 3,588
  • 6
  • 28
  • 52
25
votes
2 answers

Can Rust's clippy do autocorrection / autofix?

Is it possible to run cargo clippy with an option so it will fix warnings automatically? From the help message, it does not look like this option is supported at the moment.
Sergey Potapov
  • 3,819
  • 3
  • 27
  • 46
25
votes
1 answer

How to limit the number of test threads in Cargo.toml?

I have tests which share a common resource and can't be executed concurrently. These tests fail with cargo test, but work with RUST_TEST_THREADS=1 cargo test. I can modify the tests to wait on a global mutex, but I don't want to clutter them if…
kriomant
  • 2,216
  • 1
  • 16
  • 21
25
votes
3 answers

Linking Rust application with a dynamic library not in the runtime linker search path

I have a shared library that I'd like to dynamically link into several separate binary Cargo applications. I include its location in the linker using the -- -L /path/to/dir format and the application compiles correctly with the significant decrease…
Ameo
  • 2,307
  • 5
  • 21
  • 33