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)
| 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 | }; |
no test coverage detected