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

How do I run a project's example using Cargo?

I'm trying to run the example code from this project. Following the instructions on the Cargo docs, I did the following: git clone https://github.com/basiliscos/rust-procol-ftp-client cd rust-procol-ftp-client cargo run cargo test cargo test…
fraiser
  • 929
  • 12
  • 28
18
votes
1 answer

Is it possible to speed up Rust compilation when linking a large library?

I'm experiencing long consecutive build times when embedding Servo as part of my binary. For example, using this tutorial for embedding Servo, after the initial build is done, any modification to my code will require 40s+ to rebuild the binary on…
tnajdek
  • 542
  • 5
  • 14
18
votes
1 answer

Is there any way to tell Cargo to run its tests on the main thread?

I have been trying to build an OpenGL-based image processing library with GLFW, and need it to be testable. Unfortunately, I ran into this bug - GLFW needs its initialization functions to be called from the main thread, but Cargo tests are run on a…
jasongrlicky
  • 267
  • 2
  • 12
18
votes
1 answer

cargo test --release causes a stack overflow. Why doesn't cargo bench?

In trying to write an optimized DSP algorithm, I was wondering about relative speed between stack allocation and heap allocation, and size limits of stack-allocated arrays. I realize there is a stack frame size limit, but I don't understand why the…
Josh
  • 2,077
  • 1
  • 17
  • 21
18
votes
1 answer

How to link against Rust crate from integration tests in 'tests' folder when building static library?

I'm building a library in Rust that will be called from C/C++ code. Cargo.toml is configured to output the crate as a static library: [lib] crate-type = ["staticlib"] I have a test in tests/integration_test.rs: extern crate mylibrary; #[test] fn…
David Haynes
  • 933
  • 5
  • 14
18
votes
2 answers

"unresolved import -- maybe a missing extern" When extern declaration exists

I have a small project which built with no issues when it was all in one big .rs file. I wanted to make it easier to work with, so I broke it up into modules, and the project is now structured like this: ├── GameState │   ├── ballstate.rs │   ├──…
Ben Pious
  • 4,765
  • 2
  • 22
  • 34
18
votes
3 answers

How to link against a local Rust library? (similar to npm link)

When developing a library in node, if you wish to develop against a library that only exists locally, before you npm publish, you can use npm link /path/to/other/node_library. What is the equivalent of this for Rust? How do you create another a foo…
bguiz
  • 27,371
  • 47
  • 154
  • 243
17
votes
1 answer

How to tell cargo to use nightly?

I know I can set rust nightly on a project by running rustup override set nightly. But I was wondering if I could state it on the Cargo.toml, so if I build in another machine it'll just run with nightly from the start. So far I haven't been able to…
Tomás Vallotton
  • 538
  • 6
  • 13
17
votes
1 answer

How to pull a dependency with different features under Cargo.toml "dependencies" and "dev-dependencies"?

Suppose you have a dependency called "dep" which has two features called f1 and f2. I want to use "dep" with the f1 feature when I'm building my crate normally, but use it with f2 when building it for tests. I know dev-dependencies are those we need…
Alex Sed
  • 700
  • 5
  • 12
17
votes
1 answer

What exactly is a 'crate' in the Cargo ecosystem and what is the mapping to what is on crates.io?

I am a little confused as to the exact things hosted on crates.io (is a 'crate' the proper way to refer to those)? My understanding is that a crate is a unit of compilation in Rust, but then what is the mapping between crates and what is on…
nromaniv
  • 665
  • 6
  • 18
17
votes
4 answers

How can I avoid running some tests in parallel?

I have a collection of tests. There are a few tests that need to access a shared resource (external library/API/hardware device). If any of these tests run in parallel, they fail. I know I could run everything using --test-threads=1 but I find that…
Juan Leni
  • 6,982
  • 5
  • 55
  • 87
17
votes
6 answers

How can I force `build.rs` to run again without cleaning my whole project?

How can I force build.rs to run again without cleaning my whole project? I checked cargo build --help but I couldn't find anything related to build.rs.
tversteeg
  • 4,717
  • 10
  • 42
  • 77
17
votes
1 answer

Specific profiles for workspace members

Is it possible to specify specific profiles for members of a workspace? If I write a profile into the member Cargo.toml I get: warning: profiles for the non root package will be ignored, specify profiles at the workspace root: I also tried to put…
Matthias
  • 8,018
  • 2
  • 27
  • 53
17
votes
5 answers

Is it possible to have Cargo always show warnings?

I'm using watch with cargo, in order to quickly see compile time errors. However, cargo build will only show errors when building the first time. $ cargo build Compiling clayman v0.0.1 src/core_math/vector.rs:8:5: 13:6 warning: method is never…
MartinHaTh
  • 1,417
  • 1
  • 13
  • 25
16
votes
4 answers

error: failed to run custom build command for `ring v0.16.20`

I want to build rust 1.59 project with musl in macOS Monterey 12.3.1 with M1 chip, then I run this command: rustup target add x86_64-unknown-linux-musl cargo build --release --target=x86_64-unknown-linux-musl but the project build output like…
Dolphin
  • 29,069
  • 61
  • 260
  • 539