Added build script to move files out of the Resources folder into the target

This commit is contained in:
Jordon Brooks 2023-06-03 01:40:42 +01:00
parent 54edd950eb
commit 81a4e86498
3 changed files with 34 additions and 0 deletions

2
.gitignore vendored
View file

@ -12,3 +12,5 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information # MSVC Windows builds of rustc generate these, which store debugging information
*.pdb *.pdb
!Resources/*

Binary file not shown.

32
build.rs Normal file
View file

@ -0,0 +1,32 @@
use std::env;
use std::fs;
use std::path::Path;
fn main() {
// The directory of the Cargo manifest of the package that is currently being built.
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is not defined");
// The directory where the final binaries will be placed.
let profile = env::var("PROFILE").expect("PROFILE is not defined");
let out_dir = Path::new(&manifest_dir).join("target").join(profile);
// The Resources directory.
let resources_dir = Path::new(&manifest_dir).join("Resources");
// Ensure the Resources directory exists.
if !resources_dir.exists() {
panic!("Resources directory does not exist");
}
// Iterate over each entry in the Resources directory.
for entry in fs::read_dir(resources_dir).expect("read_dir call failed") {
let entry = entry.expect("entry is invalid");
let path = entry.path();
if path.is_file() {
// The destination path is the output directory plus the file name.
let dest_path = out_dir.join(path.file_name().expect("file has no name"));
// Copy the file.
fs::copy(&path, &dest_path).expect("copy failed");
}
}
}