From a532eacf7b30676b156c99ba43f9dbb5c194cd5f Mon Sep 17 00:00:00 2001 From: Chad Brokaw Date: Wed, 25 Jan 2023 16:02:57 -0500 Subject: [PATCH] Replace HashMap with sorted Vec so builds are deterministic --- vello_shaders/build.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vello_shaders/build.rs b/vello_shaders/build.rs index 39efbfa..4c0c20e 100644 --- a/vello_shaders/build.rs +++ b/vello_shaders/build.rs @@ -13,7 +13,10 @@ use compile::ShaderInfo; fn main() { let out_dir = env::var_os("OUT_DIR").unwrap(); let dest_path = Path::new(&out_dir).join("shaders.rs"); - let shaders = compile::ShaderInfo::from_dir("../shader"); + let mut shaders = compile::ShaderInfo::from_dir("../shader"); + // Drop the HashMap and sort by name so that we get deterministic order. + let mut shaders = shaders.drain().collect::>(); + shaders.sort_by(|x, y| x.0.cmp(&y.0)); let mut buf = String::default(); write_types(&mut buf, &shaders).unwrap(); if cfg!(feature = "wgsl") { @@ -34,7 +37,7 @@ fn main() { fn write_types( buf: &mut String, - shaders: &HashMap, + shaders: &[(String, ShaderInfo)], ) -> Result<(), std::fmt::Error> { writeln!(buf, "pub struct Shaders<'a> {{")?; for (name, _) in shaders { @@ -64,7 +67,7 @@ fn write_types( fn write_shaders( buf: &mut String, mod_name: &str, - shaders: &HashMap, + shaders: &[(String, ShaderInfo)], translate: impl Fn(&ShaderInfo) -> Vec, ) -> Result<(), std::fmt::Error> { writeln!(buf, "pub mod {mod_name} {{")?;