-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
85 lines (74 loc) · 1.85 KB
/
Copy pathbuild.rs
File metadata and controls
85 lines (74 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* SPDX-FileCopyrightText: (C) 2025 a dinosaur
* SPDX-License-Identifier: Zlib
*/
use std::path::{Path, PathBuf};
pub fn get_source_dir() -> PathBuf
{
std::env::current_dir().unwrap().join("src")
}
pub fn get_target_dir() -> PathBuf
{
//let out_dir = std::env::var("OUT_DIR").unwrap();
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let build_type = std::env::var("PROFILE").unwrap();
Path::new(&manifest_dir).join("target").join(build_type)
}
pub fn copy_resources<S: AsRef<str>>(src_dir: &PathBuf, dst_dir: &PathBuf, resources: Vec<S>)
{
if !dst_dir.is_dir()
{
std::fs::create_dir(&dst_dir).unwrap();
}
for resource in resources
{
std::fs::copy(&src_dir.join(resource.as_ref()), &dst_dir.join(resource.as_ref())).unwrap();
}
}
pub fn copy_shaders<const N: usize>(src_dir: &PathBuf, dst_dir: &PathBuf, shaders: &[&str; N])
{
let mut resources: Vec<String> = vec![];
for name in shaders
{
if cfg!(target_os="macos")
{
resources.push(format!("{name}.metallib"));
continue;
}
resources.push(format!("{name}.vtx.spv"));
resources.push(format!("{name}.frg.spv"));
if cfg!(target_os="windows")
{
resources.push(format!("{name}.vtx.dxb"));
resources.push(format!("{name}.pxl.dxb"));
}
}
copy_resources(src_dir, dst_dir, resources);
}
pub fn main()
{
#[cfg(target_os="macos")]
println!("cargo:rustc-link-arg=-Wl,-rpath,/Library/Frameworks");
#[cfg(target_os="linux")]
println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN");
let src_dir = std::env::current_dir().unwrap().join("data");
let dst_dir = get_target_dir().join("Data");
copy_resources(&src_dir, &dst_dir,
vec![
"NeHe.bmp",
"Crate.bmp",
"Glass.bmp",
"Star.bmp",
"Mud.bmp",
"World.txt",
]);
copy_shaders(&src_dir.join("shaders"), &dst_dir.join("Shaders"),
&[
"lesson2",
"lesson3",
"lesson6",
"lesson7",
"lesson8",
"lesson9",
]);
}