try new hashing strategy

This commit is contained in:
Jonathan Kelley committed 2024-03-06 17:05:03 -08:00
1 parent 08d054f5c8
commit 1f6195b2ec
2 files changed
+13 -24

No files matched your search

+12 -23
View File
@@ -1,19 +1,15 @@
use std::{ use std::{collections::hash_map::DefaultHasher, hash::Hasher, process::Command};
collections::hash_map::DefaultHasher, fs::read_to_string, hash::Hasher, process::Command,
};
fn main() { fn main() {
// If any TS changes, re-run the build script // If any TS changes, re-run the build script
println!("cargo:rerun-if-changed=src/ts/*.ts"); println!("cargo:rerun-if-changed=src/ts/*.ts");
// Compute the hash of the ts files // Compute the hash of the ts files
let hash = hash_dir("./src/ts"); let hash = hash_ts_files();
// If the hash matches the one on disk, we're good and don't need to update bindings // If the hash matches the one on disk, we're good and don't need to update bindings
if let Ok(contents) = read_to_string("./src/js/hash.txt") { if include_str!("src/js/hash.txt").trim() == hash.to_string() {
if contents.trim() == hash.to_string() { return;
return;
}
} }
// Otherwise, generate the bindings and write the new hash to disk // Otherwise, generate the bindings and write the new hash to disk
@@ -26,25 +22,18 @@ fn main() {
} }
/// Hashes the contents of a directory /// Hashes the contents of a directory
fn hash_dir(dir: &str) -> u128 { fn hash_ts_files() -> u128 {
let mut out = 0; let mut out = 0;
for entry in std::fs::read_dir(dir).unwrap() { let files = [
let entry = entry.unwrap(); include_str!("src/ts/common.ts"),
let path = entry.path(); include_str!("src/ts/native.ts"),
include_str!("src/ts/core.ts"),
];
let Some(ext) = path.extension() else { for file in files.iter() {
continue;
};
if ext != "ts" {
continue;
}
// Hash the contents of the file and then add it to the overall hash
// This makes us order invariant
let mut hasher = DefaultHasher::new(); let mut hasher = DefaultHasher::new();
hasher.write(&std::fs::read(&path).unwrap()); hasher.write(file.as_bytes());
out += hasher.finish() as u128; out += hasher.finish() as u128;
} }
+1 -1
View File
@@ -1 +1 @@
66508259673533768445 36839850333612604813