Should Cargo.lock be committed when the crate is both a rust library and an executable?

Yes, crates that depend on your library will ignore your Cargo.lock. The Cargo FAQ provides more details: Why do binaries have Cargo.lock in version control, but not libraries? The purpose of a Cargo.lock is to describe the state of the world at the time of a successful build. It is then used to provide deterministic … Read more

Linking Rust application with a dynamic library not in the runtime linker search path

Here’s a Minimal, Reproducible Example that exhibits the same problem that you experienced. I created a C library exporting a simple addition function. I also created a Cargo project to use this function. dynlink/ ├── executable │   ├── build.rs │   ├── Cargo.lock │   ├── Cargo.toml │   └── src │      └── main.rs └── library ├── … Read more

Include git commit hash as string into Rust program

Since Rust 1.19 (cargo 0.20.0), thanks to https://github.com/rust-lang/cargo/pull/3929, you can now define a compile-time environment variable (env!(…)) for rustc and rustdoc via: println!(“cargo:rustc-env=KEY=value”); So OP’s program can be written as: // build.rs use std::process::Command; fn main() { // note: add error checking yourself. let output = Command::new(“git”).args(&[“rev-parse”, “HEAD”]).output().unwrap(); let git_hash = String::from_utf8(output.stdout).unwrap(); println!(“cargo:rustc-env=GIT_HASH={}”, git_hash); } … Read more

rustup gives command not found error with zsh even after installing with brew

I used the following steps to install Rust on MacOS: Install Rust using: curl –proto ‘=https’ –tlsv1.2 -sSf https://sh.rustup.rs | sh Make sure that you customize the installation and answer No when it asks to modify the Path. Once successfully done, then add the Path variable to .zshrc using: To open .zshrc use nano ~/.zshrc … Read more

How to pass RUST_BACKTRACE=1 when running a Rust binary installed in Debian?

Just in case someone is looking for setting environment variable from source code, here is how you do it: use std::env; fn main() { // this method needs to be inside main() method env::set_var(“RUST_BACKTRACE”, “1”); } The benefit of this approach — in contrast to manually setting the env variable from PowerShell– is that you … Read more

What does “manifest path is a virtual manifest, but this command requires running against an actual package” mean?

Your Cargo.toml is a virtual manifest. In workspace manifests, if the package table is present, the workspace root crate will be treated as a normal package, as well as a workspace. If the package table is not present in a workspace manifest, it is called a virtual manifest. When working with virtual manifests, package-related cargo … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)