built
built copied to clipboard
File NotFound error when building package in cargo workspace
I'm encountering a problem which I believe is from get_build_deps()
trying to retrieve the Cargo.lock file from the manifest folder, inside a package using the new Rust 1.64.0 workspace inheritance feature.
I'm not certain of my analysis... still a bit of a Rust noob, but I've been able to narrow the problem down to that line. My build.rs code is identical to the example in the pyo3-built README .
I can build the example_project code as a crate within my workspace (listing it in workspace.members) as long as I leave its Cargo.lock file in its folder. As soon as I remove that file, I get the same NotFound error from get_build_deps(), which I believe should be looking in the parent folder when its in a workspace package.
You are correct. I've described the problem a bit at https://stackoverflow.com/questions/75052086/how-to-locate-the-cargo-lock-from-build-rs , along with a solution to use https://crates.io/crates/project-root , which needs to be used with https://docs.rs/built/latest/built/fn.write_built_file_with_opts.html in order to specify the appropriate directory explicitly.
i.e. something like
fn main() {
let dest = std::path::Path::new(&env::var("OUT_DIR").expect("OUT_DIR not set")).join("built.rs");
let workspace_root = ...get_workspace_root()...;
built::write_built_file_with_opts(
Some(&workspace_root),
&dest,
).expect("Failed to acquire build-time information");
}
where get_workspace_root
is your own function that returns the directory containing Cargo.lock
Recent commit bd869d1a38b375655243a47bcc6583fa7244c5d3 should work for most scenarios, although it doesn't actually implement cargo's workspace-behavior. Mind giving current HEAD
a try if it works for you?
Thanks @lukaslueg , I've tested master
- it works well.
Could we get a release with this fix? Or do you want other issues fixed before the next release?
@jayvdb Pushed as 0.7.3