I want to be able to read the Cargo.lock file from build.rs without resorting to literal paths.
In build.rs, std::env::var("CARGO_MANIFEST_DIR").unwrap(); can be used to find the Cargo.toml, and traditionally the Cargo.lock was in this directory, however with the introduction of workspaces that is no longer always true.
https://crates.io/crates/project-root can be used to find the nearest
Cargo.lockup the directory structure from the current directory.In
Cargo.tomladdAnd in
build.rsuseproject_root::get_project_root().unwrap()to obtain the directory whereCargo.lockis.(It would be nice to find a solution which doesn't need additional dependencies)