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
10
votes
1 answer

Why is the ~/.cargo directory so big?

On my Windows 10 machine it's 3.5GG. What is it storing? How can I trim it down?
Pablo Tato Ramos
  • 409
  • 4
  • 18
10
votes
1 answer

Why does Rust need both packages and workspaces?

I am a bit confused by the existence of the three upper levels in the Rust module hierarchy and why they are all needed. If I understand it correctly: Crates are simple projects that contain multiple modules and each crate is either a library or a…
Xcode23
  • 161
  • 2
  • 7
10
votes
1 answer

How to use external crates in a Cargo build script?

I have this file structure Test │ .gitignore │ build.rs │ Cargo.toml │ ├───.vscode │ tasks.json │ ├───src │ main.rs I have this Cargo.toml [package] name = "test" version = "0.1.0" authors = ["xtricman"] edition = "2018" # See…
10
votes
2 answers

Is it possible for the assert_eq macro to show a diff when two strings aren't equal?

I'm writing some tests for a language tokenizer and I'm comparing a JSON-serialized version of the tokenization produced by the tokenizer with a serialization of a known-good tokenization. So I have some tests like this: #[test] fn test_tokenize()…
David Sanders
  • 4,069
  • 1
  • 24
  • 38
10
votes
1 answer

Rust: link failed with exit code 1181

Error is shown at "cargo run" upon the first example of Getting started C:\Users\HiWin10\hello-rust>cargo run --verbose Compiling hello-rust v0.1.0 (C:\Users\HiWin10\hello-rust) Running `rustc --edition=2018 --crate-name hello_rust…
SOUser
  • 3,802
  • 5
  • 33
  • 63
10
votes
1 answer

dylib cannot load libstd when compiled in a workspace

I have a project with the following structure: Cargo.toml my_script.py my_lib: - Cargo.toml - src my_bin: - Cargo.toml - src Where: my_lib is a Rust library with crate-type = ["dylib"] my_bin is a Rust binary application using…
Maeln
  • 370
  • 1
  • 21
10
votes
3 answers

How to deal with multiple nested workspace roots?

How can you have multiple nested workspace with Cargo? I have the following project structure: myworkspace ├── project_a │  └── Cargo.toml ├── project_b │  └── Cargo.toml │ └── project_b_dependency | └── Cargo.toml └── Cargo.toml Where…
Olivier
  • 773
  • 9
  • 14
10
votes
3 answers

How to get executable's full target triple as a compile-time constant without using a build script?

I'm writing a Cargo helper command that needs to know the default target triple used by Rust/Cargo (which I presume is the same as host's target triple). Ideally it should be a compile-time constant. There's ARCH constant, but it's not a full…
Kornel
  • 97,764
  • 37
  • 219
  • 309
10
votes
1 answer

How do I conditionally compile for WebAssembly in Rust?

How can I make a config flag where I conditionally choose the wasm32-unknown-unkown target? I printed the current environment using the following build.rs: use std::env; fn main() { for (key, value) in env::vars() { if…
tversteeg
  • 4,717
  • 10
  • 42
  • 77
10
votes
1 answer

Can I tell the Rust compiler to ignore warnings only on files matching a specific name?

I'm using a library that generates a bunch of code for me, and it's often quite eager in generating methods that I'm not using yet. This results in a bunch of noisy warnings when building my project. The script generates plain old .rs files…
Cam Jackson
  • 11,860
  • 8
  • 45
  • 78
10
votes
1 answer

How to release a beta version of a crate for limited public testing?

I want to carefully release a new version of a crate to give users a chance to test it first. How can I release it to crates.io as a "beta"? (similar to how npm has @next tagged releases). It's not supposed to be a breaking change, so I'm not going…
Kornel
  • 97,764
  • 37
  • 219
  • 309
10
votes
1 answer

Why doesn't the rust crate openssl-sys compile?

I've just added an external crate to my Rust project: [dependencies] feed = "2.0" This crate has several dependencies, notably openssl-sys v0.9.10. This one failed when I'm trying to build my project: $ cargo build Compiling unicode-normalization…
LeyluIAA
  • 201
  • 2
  • 8
10
votes
1 answer

How to generate Cargo.lock based on last month's crates.io?

I want to create a Cargo.lock file in a Rust project from Cargo.toml based on what was available on 22 Feb 2017. I need to make version selection compatible to what would happen on that specific day. (No, don't have a version controlled Cargo.lock…
10
votes
1 answer

How do I generate cargo docs for all platforms?

The cargo command line tool allows me to generate documentation for my crate, but I have structures like: #[cfg(target-platform("windows")] mod winstuff { /// Explanation of Windows-specific tasks } #[cfg(target-platfrom("linux")] mod linstuff…
Valarauca
  • 1,041
  • 3
  • 10
  • 23
10
votes
2 answers

How can the location of Cargo's configuration directory be overridden?

It seems that the default behavior of Cargo when searching for its configuration directory is to look in the current user's home directory (~/.cargo on my system). How can this behavior be modified to make Cargo look in a user-supplied directory…
Doe
  • 585
  • 5
  • 19