How do I pin indirect dependencies of a crate?

Manual editing You can check out Iron, modify Cargo.toml to specify versions (as you have already done). Then you repeat the process, checking out url, modifying its Cargo.toml, then make sure you are using your version of url in Iron’s Cargo.toml. Rinse and repeat. Patch overrides From the Cargo docs: The [patch] section of Cargo.toml … Read more

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 in the Cargo Book [[bin]] name = “daemon” path = “src/daemon/bin/main.rs” [[bin]] name = “client” path = “src/client/bin/main.rs” You can run individual binaries with the cargo run command with the –bin <bin-name> option. Tip: If you instead put these files in src/bin/daemon.rs and src/bin/client.rs, you’ll get … Read more

Is there a list of all cfg features?

The “Conditional compilation” section of the Reference has a list of configurations that must be defined (as of Rust 1.14): target_arch with values like: x86 x86_64 mips powerpc powerpc64 arm aarch64 target_os with values like: windows macos ios linux android freebsd dragonfly bitrig openbsd netbsd target_family with values like: unix windows unix (shortcut for target_family) … Read more

How to include files from same directory in a module using Cargo/Rust?

All of your top level module declarations should go in main.rs, like so: mod mod1; mod mod2; fn main() { println!(“Hello, world!”); mod1::mod1fn(); } You can then use crate::mod2 inside mod1: use crate::mod2; pub fn mod1fn() { println!(“1”); mod2::mod2fn(); } I’d recommend reading the chapter on modules in the new version of the Rust book … Read more

How to check release / debug builds using cfg in Rust?

You can use debug_assertions as the appropriate configuration flag. It works with both #[cfg(…)] attributes and the cfg! macro: #[cfg(debug_assertions)] fn example() { println!(“Debugging enabled”); } #[cfg(not(debug_assertions))] fn example() { println!(“Debugging disabled”); } fn main() { if cfg!(debug_assertions) { println!(“Debugging enabled”); } else { println!(“Debugging disabled”); } #[cfg(debug_assertions)] println!(“Debugging enabled”); #[cfg(not(debug_assertions))] println!(“Debugging disabled”); example(); } … Read more