Closed themadcreator closed 10 months ago
When doing this, it would also be nice to introduce yet another function which still doesn't put the file into target/{target}/{profile}
but rather still puts the file into target/{profile}
as before (intended for host tools) even when cross compiling. ({profile}
being the build type, really)
FWIW, I needed this supported for work and just forked the implementation to be:
pub fn copy_to_output_for_build_type(path: &str, build_type: &str) -> Result<()> {
let mut options = CopyOptions::new();
let mut out_path = get_project_root()?;
out_path.push("target");
// TODO: This is a hack, ideally, we would plug into https://docs.rs/cargo/latest/cargo/core/compiler/enum.CompileKind.html
let triple = build_target::target_triple().unwrap();
if env::var_os("OUT_DIR").unwrap().to_str().unwrap().contains(&triple) {
out_path.push(triple)
}
out_path.push(build_type);
// Overwrite existing files with same name
options.overwrite = true;
options.copy_inside = true;
copy_items(&[path], &out_path, &options)?;
Ok(())
}
This works by inspecting to see if the target appears in the path, which is the hacky way of seeing which compilekind cargo is running with. Ideally it would hook into the cargo library, but looking into it I didn't see an immediately obvious path. Might upgrade the hack later, but it met my needs as is for now.
Note it also uses project_root::get_project_root()
which is an option to address #6 , similar to what another commenter mentioned there.
I need to use the forked version for work for other reasons as well, but happy to contribute it back upstream if this is still maintained / isn't too hacky for others.
Looks like a good solution that will close both issues, and I'm happy to merge it to the main branch if you submit a pull request. Thanks very much for the help.
Will do :) I'll clean it up a bit first
Closed in pr #8 by @LittleBoxOfSunshine. Will look into using get_project_root
and rewriting the tests appropriately
When cross compiling, the target output directory looks something like
target/x86_64-pc-windows-msvc/release
ortarget/{target}/{profile}
Currently this library only considers the
PROFILE
env var.