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

rust solana build error: no such subcommand: +bpf

I am new to solana and rust, recently i have installed thier example-helloworld from this repo- https://github.com/solana-labs/example-helloworld . Whenever i have tried to build the rust program using npm scripts or going to the rust program…
abhishek
  • 189
  • 1
  • 3
16
votes
3 answers

How can I fix unused imports in Rust automatically?

Is there any way to fix ONLY unused imports in Rust automatically? I have seen cargo fix, which does work, but it makes a whole bunch of other fixes too. Is there any way to tell cargo fix to only fix unused imports (preferably in a specified file)…
Akshay
  • 1,606
  • 3
  • 17
  • 32
16
votes
1 answer

Is it possible to check if `panic` is set to `abort` while a library is compiling?

It may be not a good idea or not idiomatic, but let's assume that for some reason a library relies on catch_unwind for its business logic. Can I somehow warn (by failing the compilation with an error message?) a user of this library if they set…
ozkriff
  • 1,269
  • 15
  • 23
16
votes
0 answers

Get Cargo.toml version at runtime

In my Cargo.toml I have this block [package] name = "packagename" version = "0.1.0" authors = ["me "] How can I fetch what [package].version is at runtime?
jens1o
  • 625
  • 7
  • 14
16
votes
1 answer

What is the idiomatic way of writing man pages for Rust CLI tools?

CLI apps on Unix-like OSes generally provide man pages for reference. I have not yet seen any good guide on how to do this in the Rust ecosystem - what is the idiomatic way of doing this? I am aware of the Cargo build scripts feature, is this the…
Espen H
  • 261
  • 2
  • 9
16
votes
1 answer

How to tell Cargo to use a git repository as source for an indirect dependency instead of crates.io?

A few days ago, cross-compiling to JavaScript via Emscripten has finally hit nightly. I wanted to compile a project using glium in that manner. However, there are still many Emscripten-related bugs in many crates. While maintainers usually fix those…
Lukas Kalbertodt
  • 79,749
  • 26
  • 255
  • 305
16
votes
3 answers

Can I prevent cargo from rebuilding libraries with every new project?

Suppose I execute cargo new one --bin and cargo new two --bin then add the same dependency to each project's Cargo.toml and build them. Now there are two absolutely identical sets of libraries: /one/target/debug/deps/ *.rlib /two/target/debug/deps/…
vlad4378
  • 803
  • 1
  • 9
  • 21
16
votes
1 answer

Only show first screenful of compile errors in Rust when building with Cargo?

Is there a way to get rustc to only output the first few errors when compiling with Cargo, or even better, to print the oldest errors last? It seems the default threshold for aborting the compile is set quite high: error: aborting due to 25…
Andrew Wagner
  • 22,677
  • 21
  • 86
  • 100
16
votes
1 answer

How to set logging level while running cargo test?

I need to change the logging level while running the unit tests for a library. I am using the cargo test command to run the tests. Is there any way to specify the logging level on the command line? From the documentation of the log crate, it seems…
Shailesh Kumar
  • 6,457
  • 8
  • 35
  • 60
15
votes
1 answer

error "/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found"

Here is My Docker File: FROM ubuntu:20.04 RUN apt-get update && apt-get upgrade -y RUN apt-get install libssl-dev RUN apt-get install -y -q build-essential curl RUN curl https://sh.rustup.rs -sSf | sh -s -- -y ENV…
Jahadul Rakib
  • 476
  • 1
  • 5
  • 19
15
votes
1 answer

Difference between `cargo doc` and `cargo rustdoc`

According to doc.rust-lang.org cargo rustdoc build[s] a package's documentation, using specified custom flags cargo doc build[s] a package's documentation What is the difference between the two? From what I understand cargo rustdoc is just…
andrewgazelka
  • 1,746
  • 1
  • 16
  • 26
15
votes
1 answer

Can I activate a dependency's feature only for debug profile?

I have just started looking into the Bevy game engine for Rust. It has a feature called dynamic, which enables dynamic linking, to speed up compilation time during development. We are, however, advised to disable this when building for release. Is…
Arthur
  • 653
  • 2
  • 6
  • 21
15
votes
2 answers

How do I fix "ld: error: unable to find library -lgcc" when cross-compiling rust to android?

I'm trying to get rust working on android. However, when I try to cross-compile to android I get the following linking error: $ cargo build --target=arm-linux-androideabi Compiling v0.1.0 () error: linking with…
StackOverflower
  • 526
  • 3
  • 14
15
votes
2 answers

can't install cargo wasm-pack

When i run cargo install wasm-pack on windows 10 64-bit i get this error: error: failed to run custom build command for `openssl-sys v0.9.65` Caused by: process didn't exit successfully:…
VilgotanL
  • 328
  • 2
  • 9
15
votes
3 answers

How to use the mold linker with cargo?

I'm using lld as my linker currently for Rust, but recently encountered the mold project, which is faster than lld. I'd like to try it for Rust compilation, but I'm not sure how to pass it in as my linker. In my .cargo/config file I've…
Marcus Buffett
  • 1,289
  • 1
  • 14
  • 32