I have two crates, A and B and a different crate C. C is a special crate that must be compiled at runtime by the final executable of any crate using B as a dependency.
A is a parent crate that depends on B. I am trying to find a good way, at compilation time, to copy B into a location known to A so that the final executable can use it.
Currently I have this build.rs
in B
let crate_b_path = std::env::var("CARGO_MANIFEST_DIR").unwrap();
println!(
"{}",
format!("cargo:rustc-env=PATH_TO_C={}/crate_data/", crate_b_path.clone())
);
This correctly finds the spot where C is stored. The problem now is trying to copy it into a location known to A and marking that location. The env var PATH_TO_C
only exists during compilation of C
so I can’t just read it from A.
Probably the best way to do this is if there is a way for the build.rs
script in B to know the path to the root of the current compilation group (in this case A). But I don’t see anything in the docs that suggests this is possible.