shader copy to output
All checks were successful
CI / build-test-release (push) Successful in 15m1s

This commit is contained in:
Jorijn van der Graaf 2026-05-01 19:16:13 +02:00
commit de9865b583
8 changed files with 163 additions and 1 deletions

View file

@ -572,6 +572,36 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
return {buildError, false, {}};
}
// Ship .spv files from transitive deps' bin dirs alongside the executable
// so consumers find shaders next to the binary at runtime. Only an exe is
// a deployment unit; intermediate libs don't need to forward shaders since
// the exe walks all transitive deps. Runs outside the repack gate because
// the relink mtime check above only watches .so/.dll/.a, so a shader-only
// change in a dep wouldn't trigger repack but still needs the new .spv
// copied across.
if (config.type == ConfigurationType::Executable) {
try {
std::unordered_set<Configuration*> shaderSeen;
std::function<void(Configuration*)> copyDepShaders = [&](Configuration* dep) {
if (!shaderSeen.insert(dep).second) return;
fs::path depDir = dep->BinDir();
for (const Shader& shader : dep->shaders) {
fs::path src = depDir / shader.path.filename().replace_extension("spv");
if (!fs::exists(src)) continue;
fs::path dest = outputDir / src.filename();
if (!fs::exists(dest) || fs::last_write_time(src) > fs::last_write_time(dest)) {
fs::copy_file(src, dest, fs::copy_options::overwrite_existing);
}
}
for (Configuration* sub : dep->dependencies) copyDepShaders(sub);
};
for (Configuration* dep : config.dependencies) copyDepShaders(dep);
} catch (const fs::filesystem_error& e) {
for(std::thread& thread : threads) thread.join();
return {e.what(), false, {}};
}
}
if(repack.load()) {
buildResult.repack = true;
}

View file

@ -54,7 +54,8 @@ namespace Crafter {
}
bool Shader::Check(const fs::path& outputDir) const {
return fs::exists((outputDir/path.filename()).generic_string()+".spv") && fs::last_write_time(path.generic_string()+".glsl") < fs::last_write_time((outputDir/path.filename()).generic_string()+".spv");
fs::path spv = outputDir / path.filename().replace_extension("spv");
return fs::exists(spv) && fs::last_write_time(path) < fs::last_write_time(spv);
}
std::string Shader::Compile(const fs::path& outputDir) const {
EShLanguage glslangType = ToEShLanguage(type);