Let's assume I have a game with the following directory structure:
/src
/resources
Cargo.toml
I would like cargo build
to copy the files in the resources
directory and paste them in the same directory as the executable file.
I know it is possible to do this using a custom build script, but this seems to be a common case that deserves special treatment. So the question is: does cargo provide a standard way of copying files to the target directory (using just Cargo.toml
)?
"Copy to Output Directory" is the property of the files within a Visual Studio project, which defines if the file will be copied to the project's built path as it is. Coping the file as it is allows us to use relative path to files within the project.
Type "xcopy", "source", "destination" /t /e in the Command Prompt window. Instead of “ source ,” type the path of the folder hierarchy you want to copy. Instead of “ destination ,” enter the path where you want to store the copied folder structure. Press “Enter” on your keyboard.
No, it doesn't.
You can move files around with build scripts, but these are run before your crate is built because their sole purpose is to prepare the environment (e.g. compile C libraries and shims).
If you think this is an important feature, you can open a feature request in Cargo issue tracker.
Alternatively, you can write a makefile or a shell script which would forward all arguments to cargo and then copy the directory manually:
#!/bin/bash
DIR="$(dirname "$0")"
if cargo "$@"; then
[ -d "$DIR/target/debug" ] && cp -r "$DIR/resources" "$DIR/target/debug/resources"
[ -d "$DIR/target/release" ] && cp -r "$DIR/resources" "$DIR/target/release/resources"
fi
Now you can run cargo like
% ./make.sh build
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With