MCPcopy Create free account
hub / github.com/TheRedDeveloper/ply-engine / build

Method build

src/shader_build.rs:116–262  ·  view source on GitHub ↗

Runs the shader build pipeline. This will: 1. Scan the source directory for shader files 2. Check content hashes for incremental builds 3. Compile changed shaders using the appropriate pipeline 4. Write compiled GLSL ES output to the output directory 5. Update the hash file

(self)

Source from the content-addressed store, hash-verified

114 /// 4. Write compiled GLSL ES output to the output directory
115 /// 5. Update the hash file
116 pub fn build(self) {
117 // Tell Cargo to rerun if the source directory changes
118 println!("cargo:rerun-if-changed={}", self.source_dir.display());
119
120 // Create output directories
121 std::fs::create_dir_all(&self.output_dir)
122 .unwrap_or_else(|e| panic!("Failed to create output dir '{}': {}", self.output_dir.display(), e));
123 std::fs::create_dir_all(&self.spirv_dir)
124 .unwrap_or_else(|e| panic!("Failed to create SPIR-V dir '{}': {}", self.spirv_dir.display(), e));
125 if let Some(parent) = self.hash_file.parent() {
126 std::fs::create_dir_all(parent)
127 .unwrap_or_else(|e| panic!("Failed to create hash dir '{}': {}", parent.display(), e));
128 }
129
130 // Load existing hashes
131 let hashes = load_hashes(&self.hash_file);
132 let mut new_hashes = HashMap::default();
133
134 // Scan source directory
135 if !self.source_dir.exists() {
136 println!(
137 "cargo:warning=Shader source directory '{}' does not exist, skipping shader build",
138 self.source_dir.display()
139 );
140 return;
141 }
142
143 let shader_files = collect_shader_files(&self.source_dir);
144 if shader_files.is_empty() {
145 println!(
146 "cargo:warning=No shader files found in '{}'",
147 self.source_dir.display()
148 );
149 return;
150 }
151
152 for file_path in &shader_files {
153 let ext = file_path
154 .extension()
155 .and_then(|e| e.to_str())
156 .map(|e| format!(".{}", e))
157 .unwrap_or_default();
158
159 let rel_path = file_path
160 .strip_prefix(&self.source_dir)
161 .unwrap_or(file_path);
162
163 // Compute content hash of source file
164 let source_hash = content_hash(file_path);
165
166 // Check dependency hashes for custom handlers
167 let dep_key = format!("{}:deps", rel_path.display());
168 let dep_hashes_changed = if let Some(_handler) = self.custom_handlers.get(&ext) {
169 let dep_globs = handler_dep_globs_cached(&hashes, &dep_key);
170 check_dep_hashes_changed(&dep_globs, &hashes)
171 } else {
172 false
173 };

Callers 2

render_tinyvg_imageFunction · 0.80
ws_connectFunction · 0.80

Calls 13

load_hashesFunction · 0.85
collect_shader_filesFunction · 0.85
content_hashFunction · 0.85
handler_dep_globs_cachedFunction · 0.85
check_dep_hashes_changedFunction · 0.85
expand_globFunction · 0.85
compile_slangFunction · 0.85
copy_glslFunction · 0.85
save_hashesFunction · 0.85
is_emptyMethod · 0.80
getMethod · 0.80
cloneMethod · 0.80

Tested by

no test coverage detected