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

Is there any way to include binary or text files in a Rust library?

I am trying to create a library and I want to include some binary (or text) files in it that will have data which will be parsed at runtime. My intention is to have control over these files, update them constantly and change the version of the…
Otobo
  • 714
  • 1
  • 7
  • 13
24
votes
7 answers

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
  • 603
  • 1
  • 5
  • 17
24
votes
1 answer

Cargo not running tests in top-level file

I'm quite confused by how Cargo finds tests to run. I've created a Cargo project and it added a main.rs for me. If I add #[test] functions in there, they're found and run with cargo test. If I add a foo.rs file as a sibling to main.rs and add tests…
tenpn
  • 4,556
  • 5
  • 43
  • 63
24
votes
1 answer

How do I 'pass down' feature flags to subdependencies in Cargo?

I'm writing a library in Cargo. If this library depends on another library like libc, which exposes a feature (in this case, use_std), how do I make a feature I expose enable or disable that feature in my dependency? Looking at the cargo…
burtonageo
  • 397
  • 2
  • 7
24
votes
2 answers

Is it possible to have Cargo fetch dependencies from a private remote git?

I have an account on an ssh-friendly lab machine where I store a lot of private projects so I can access them from multiple computers (and it allows me to only use my few private Github repos for things multiple people will work on). It seems like…
Linear
  • 21,074
  • 4
  • 59
  • 70
23
votes
1 answer

How can I specify which crate `cargo run` runs by default in the root of a Cargo workspace?

Right now I have a Cargo workspace with three members. [workspace] members = [ "foo", "bar", "baz", ] If I run cargo run in the root directory, I get this error: error: manifest path /home/lukas/dev/mahboi/Cargo.toml is a virtual…
Lukas Kalbertodt
  • 79,749
  • 26
  • 255
  • 305
23
votes
2 answers

How do I access assets included in a Rust/Cargo project installed via `cargo install`?

I have a project which includes some associated assets (Lua scripts), which I need to find at runtime. This can mean two things: During development (e.g. cargo run), I want to find it relative to the source When installed via cargo install, the…
Chris Emerson
  • 13,041
  • 3
  • 44
  • 66
23
votes
1 answer

How to specify the path to a Cargo.toml

I'm new to Rust and I want to build and run my project. I use something like: cd %project_path% cargo run I want to be able to write cargo run -path %project_path% in a single line because I want to create a build script that doesn't allow changing…
Alex Zhukovskiy
  • 9,565
  • 11
  • 75
  • 151
23
votes
6 answers

Specify the version of rustc required for a Cargo project

Is it possible to specify that a Cargo project requires a minimum rustc version of, for example, 1.1.0 to compile?
telotortium
  • 3,383
  • 2
  • 23
  • 25
23
votes
1 answer

What is the syntax for specifying dependency versions in Cargo?

So far I have seen three... [dependencies] crate = "1.0.0" # I think this is an exact version match crate = "^1.0.0" # I think this means "use that latest 1.x.x" crate = "*" # I think this means "use the latest" I'd love to know for certain…
jocull
  • 20,008
  • 22
  • 105
  • 149
22
votes
2 answers

Set a project to use nightly by default

How do I set a Cargo project to build & run using nightly by default (i.e. cargo build is actually cargo +nightly build) without setting nightly as the global default? This is not the same question as How to switch between Rust toolchains. If you…
Timmmm
  • 88,195
  • 71
  • 364
  • 509
22
votes
2 answers

Does a compiled Rust executable exclude unused code from dependencies?

If I build a Rust application using Cargo with some crate dependencies, will any code in those dependencies that is unused by my application be eliminated from the final executable?
Thomas Bratt
  • 48,038
  • 36
  • 121
  • 139
22
votes
2 answers

Why does `cargo new` create a binary instead of a library?

I am creating a library with Rust. On library creation I type cargo new name According to the docs this should create a lib, because --bin is omitted. However, the file is auto set to a binary. Is there a setting I have to adjust to disable auto…
seamus
  • 2,681
  • 7
  • 26
  • 49
22
votes
3 answers

Out of source builds (external build directory) with Cargo?

Having used CMake, I've become used to out-of-source builds, which are encouraged with CMake. How can out-of-source builds be done with Cargo? Using in-source-builds again feels like a step backwards: Development tools need to be configured to…
ideasman42
  • 42,413
  • 44
  • 197
  • 320
22
votes
2 answers

How to emit LLVM-IR from Cargo

How can I get cargo to emit LLVM-IR instead of a binary for my project? I know that you can use the --emit=llvm-ir flag in rustc, but I've read some Github issues that show it's impossible to pass arbitrary compiler flags to cargo. Is there any…
Ameo
  • 2,307
  • 5
  • 21
  • 33