build.rs: don't build compile-shaders if shaders are unchanged
This commit is contained in:
parent
d1910063d8
commit
ee84b309ba
6 changed files with 43 additions and 40 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -637,6 +637,7 @@ dependencies = [
|
||||||
"tiny-skia",
|
"tiny-skia",
|
||||||
"tracy-client-sys",
|
"tracy-client-sys",
|
||||||
"uapi",
|
"uapi",
|
||||||
|
"walkdir",
|
||||||
"with_builtin_macros",
|
"with_builtin_macros",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,8 @@ repc = "0.1.1"
|
||||||
anyhow = "1.0.79"
|
anyhow = "1.0.79"
|
||||||
bstr = { version = "1.9.0", default-features = false, features = ["std"] }
|
bstr = { version = "1.9.0", default-features = false, features = ["std"] }
|
||||||
cc = "1.0.86"
|
cc = "1.0.86"
|
||||||
|
blake3 = "1.8.2"
|
||||||
|
walkdir = "2.5.0"
|
||||||
|
|
||||||
#[profile.dev.build-override]
|
#[profile.dev.build-override]
|
||||||
#opt-level = 3
|
#opt-level = 3
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
use {anyhow::bail, std::process::Command};
|
mod hash;
|
||||||
|
|
||||||
|
use {crate::vulkan::hash::unchanged, anyhow::bail, std::process::Command};
|
||||||
|
|
||||||
pub fn main() -> anyhow::Result<()> {
|
pub fn main() -> anyhow::Result<()> {
|
||||||
if !std::fs::exists("compile-shaders")? {
|
if !std::fs::exists("compile-shaders")? {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
if unchanged() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
let code = Command::new("cargo")
|
let code = Command::new("cargo")
|
||||||
.args([
|
.args([
|
||||||
"run",
|
"run",
|
||||||
|
|
|
||||||
32
build/vulkan/hash.rs
Normal file
32
build/vulkan/hash.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
use {std::fmt::Write, walkdir::WalkDir};
|
||||||
|
|
||||||
|
pub const ROOT: &str = "src/gfx_apis/vulkan/shaders";
|
||||||
|
pub const HASH: &str = "src/gfx_apis/vulkan/shaders_hash.txt";
|
||||||
|
|
||||||
|
fn calculate_hash() -> anyhow::Result<String> {
|
||||||
|
let dir = WalkDir::new(ROOT);
|
||||||
|
let mut files = vec![];
|
||||||
|
for file in dir {
|
||||||
|
let file = file?;
|
||||||
|
if file.file_type().is_file() {
|
||||||
|
files.push(file.path().to_path_buf());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
files.sort();
|
||||||
|
let mut out = String::new();
|
||||||
|
for file in files {
|
||||||
|
let data = std::fs::read(&file)?;
|
||||||
|
writeln!(out, "{} {}", blake3::hash(&data).to_hex(), file.display())?;
|
||||||
|
}
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unchanged() -> bool {
|
||||||
|
let Ok(actual) = std::fs::read_to_string(HASH) else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
let Ok(expected) = calculate_hash() else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
actual == expected
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,7 @@
|
||||||
use {
|
use {anyhow::bail, compile_shaders_core::ROOT, std::process::Command};
|
||||||
anyhow::bail,
|
|
||||||
compile_shaders_core::{ROOT, unchanged},
|
|
||||||
std::process::Command,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
println!("cargo:rerun-if-changed={}", ROOT);
|
println!("cargo:rerun-if-changed={}", ROOT);
|
||||||
if unchanged() {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
let code = Command::new("cargo")
|
let code = Command::new("cargo")
|
||||||
.args([
|
.args([
|
||||||
"run",
|
"run",
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,6 @@
|
||||||
use {std::fmt::Write, walkdir::WalkDir};
|
include!("../../../build/vulkan/hash.rs");
|
||||||
|
|
||||||
pub const ROOT: &str = "src/gfx_apis/vulkan/shaders";
|
|
||||||
pub const BIN: &str = "src/gfx_apis/vulkan/shaders_bin";
|
pub const BIN: &str = "src/gfx_apis/vulkan/shaders_bin";
|
||||||
pub const HASH: &str = "src/gfx_apis/vulkan/shaders_hash.txt";
|
|
||||||
|
|
||||||
fn calculate_hash() -> anyhow::Result<String> {
|
|
||||||
let dir = WalkDir::new(ROOT);
|
|
||||||
let mut files = vec![];
|
|
||||||
for file in dir {
|
|
||||||
let file = file?;
|
|
||||||
if file.file_type().is_file() {
|
|
||||||
files.push(file.path().to_path_buf());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
files.sort();
|
|
||||||
let mut out = String::new();
|
|
||||||
for file in files {
|
|
||||||
let data = std::fs::read(&file)?;
|
|
||||||
writeln!(out, "{} {}", blake3::hash(&data).to_hex(), file.display())?;
|
|
||||||
}
|
|
||||||
Ok(out)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unchanged() -> bool {
|
|
||||||
let Ok(actual) = std::fs::read_to_string(HASH) else {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
let Ok(expected) = calculate_hash() else {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
actual == expected
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_hash() -> anyhow::Result<()> {
|
pub fn update_hash() -> anyhow::Result<()> {
|
||||||
std::fs::write(HASH, calculate_hash()?)?;
|
std::fs::write(HASH, calculate_hash()?)?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue