Jonathan Kelley преди 1 година
родител
ревизия
f073322bb3
променени са 4 файла, в които са добавени 15 реда и са изтрити 16 реда
  1. 1 0
      Cargo.lock
  2. 3 0
      packages/interpreter/Cargo.toml
  3. 10 15
      packages/interpreter/build.rs
  4. 1 1
      packages/interpreter/src/js/hash.txt

+ 1 - 0
Cargo.lock

@@ -2557,6 +2557,7 @@ dependencies = [
  "dioxus-core",
  "dioxus-html",
  "js-sys",
+ "md5",
  "serde",
  "sledgehammer_bindgen",
  "sledgehammer_utils",

+ 3 - 0
packages/interpreter/Cargo.toml

@@ -24,6 +24,9 @@ serde = { version = "1.0", features = ["derive"], optional = true }
 dioxus-core = { workspace = true, optional = true }
 dioxus-html = { workspace = true, optional = true }
 
+[build-dependencies]
+md5 = "0.7.0"
+
 [features]
 default = []
 serialize = ["serde"]

+ 10 - 15
packages/interpreter/build.rs

@@ -8,12 +8,12 @@ fn main() {
     let hash = hash_ts_files();
 
     // If the hash matches the one on disk, we're good and don't need to update bindings
-    let expected = include_str!("src/js/hash.txt").trim();
+    let expected = include_str!("./src/js/hash.txt").trim();
     if expected == hash.to_string() {
         return;
     }
 
-    panic!("Hashes match, no need to update bindings. {expected} != {hash}",);
+    // panic!("Hashes match, no need to update bindings. {expected} != {hash}",);
 
     // Otherwise, generate the bindings and write the new hash to disk
     // Generate the bindings for both native and web
@@ -25,24 +25,19 @@ fn main() {
 }
 
 /// Hashes the contents of a directory
-fn hash_ts_files() -> u128 {
-    let mut out = 0;
+fn hash_ts_files() -> String {
+    let mut out = "".to_string();
 
-    let files: &[&[u8]] = &[
-        include_bytes!("src/ts/common.ts"),
-        include_bytes!("src/ts/native.ts"),
-        include_bytes!("src/ts/core.ts"),
+    let files = &[
+        include_str!("./src/ts/common.ts"),
+        include_str!("./src/ts/native.ts"),
+        include_str!("./src/ts/core.ts"),
     ];
 
-    // Let's make the dumbest hasher by summing the bytes of the files
-    // The location is multiplied by the byte value to make sure that the order of the bytes matters
-    let mut idx = 0;
     for file in files {
-        for byte in file.iter() {
-            idx += 1;
-            out += (*byte as u128) * (idx as u128);
-        }
+        out = format!("{out}{:?}", md5::compute(file));
     }
+
     out
 }
 

+ 1 - 1
packages/interpreter/src/js/hash.txt

@@ -1 +1 @@
-12705686530
+3bd5a1310ebd728bdedb486881d5ad99151cf07b0006de52240dfd757ea3353e90df122a7ae681f33ff620cf15c47a20