How to pass rustc flags to cargo?

You can pass flags through Cargo by several different means: cargo rustc, which only affects your crate and not its dependencies. The RUSTFLAGS environment variable, which affects dependencies as well. Some flags have a proper Cargo option, e.g., -C lto and -C panic=abort can be specified in the Cargo.toml file. Add flags in .cargo/config using … Read more

How can I build multiple binaries with Cargo?

You can specify multiple binaries using [[bin]], as mentioned here: [[bin]] name = “daemon” path = “src/daemon/bin/main.rs” [[bin]] name = “client” path = “src/client/bin/main.rs” Tip: If you instead put these files in src/bin/daemon.rs and src/bin/client.rs, you’ll get two executables named daemon and client as Cargo compiles all files in src/bin into executables with the same … Read more

Error installing a crate via cargo: specified package has no binaries

cargo install is used to install binary packages that happen to be distributed through crates.io. If you want to use a crate as a dependency, add it to your Cargo.toml. Read the Rust getting started guide and the Cargo getting started guide for further information. In short: cargo new my_project cd my_project echo ‘curl = … Read more

Why are Rust executables so huge?

By default, the Rust compiler optimizes for execution speed, compilation speed, and ease of debugging (by including symbols, for example), rather than minimal binary size. For an overview of all of the ways to reduce the size of a Rust binary, see my min-sized-rust GitHub repository. The current high level steps to reduce binary size … Read more

What is a crate attribute and where do I add it?

A crate attribute is an attribute (#[…]) that applies to the enclosing context (#![…]). This attribute must be added to the top of your crate root, thus the context is the crate itself: #![attribute_name] #![attribute_name(arg1, …)] If you are creating a library — the crate root will be a file called lib.rs an application — … Read more

What is an idiomatic way to have shared utility functions for integration tests and benchmarks?

Create a shared crate (preferred) As stated in the comments, create a new crate. You don’t have to publish the crate to crates.io. Just keep it as a local unpublished crate inside your project and mark it as a development-only dependency. This is best used with version 2 of the Cargo resolver. For better performance, … Read more

tech