Skip to content

Commit

Permalink
chore(stageleft): use same hashing library everywhere (#1590)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadaj authored Dec 2, 2024
1 parent 78f6a32 commit 0dc709e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 29 deletions.
23 changes: 2 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions hydroflow_plus/src/deploy/trybuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ pub fn create_graph_trybuild(
}
});

let mut hasher = Sha256::new();
hasher.update(&source);
let hash = format!("{:X}", hasher.finalize())
let hash = format!("{:X}", Sha256::digest(&source))
.chars()
.take(8)
.collect::<String>();
Expand Down
2 changes: 1 addition & 1 deletion stageleft_macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ quote = "1.0.35"
syn = { version = "2.0.46", features = [ "parsing", "extra-traits", "visit" ] }
proc-macro2 = "1.0.74"
proc-macro-crate = "1.0.0"
sha256 = "1.0.0"
sha2 = "0.10.0"

[dev-dependencies]
insta = "1.39"
Expand Down
4 changes: 3 additions & 1 deletion stageleft_macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use proc_macro2::{Punct, Spacing, Span, TokenStream};
use quote::{quote, quote_spanned, ToTokens};
use sha2::{Digest, Sha256};
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::{AngleBracketedGenericArguments, Token, Type};
Expand Down Expand Up @@ -339,7 +340,7 @@ pub fn entry(
.chars()
.filter(|c| c.is_alphanumeric())
.collect::<String>();
let input_hash = "macro_".to_string() + &sha256::digest(input_contents);
let input_hash = "macro_".to_string() + &format!("{:X}", Sha256::digest(input_contents));
let input_hash_ident = syn::Ident::new(&input_hash, Span::call_site());
let input_hash_impl_ident = syn::Ident::new(&(input_hash + "_impl"), Span::call_site());

Expand All @@ -353,6 +354,7 @@ pub fn entry(

#[cfg_attr(not(stageleft_macro), allow(unused))]
#[cfg_attr(not(stageleft_macro), doc(hidden))]
#[allow(non_snake_case)]
pub(crate) fn #input_hash_impl_ident(input: #root::internal::TokenStream) -> #root::internal::TokenStream {
let input_parsed = #root::internal::syn::parse::Parser::parse(
#root::internal::syn::punctuated::Punctuated::<#root::internal::syn::Expr, #root::internal::syn::Token![,]>::parse_terminated,
Expand Down
2 changes: 1 addition & 1 deletion stageleft_tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ syn-inline-mod = "0.6.0"
quote = "1.0.35"
syn = { version = "2.0.46", features = [ "parsing", "extra-traits", "visit" ] }
proc-macro2 = "1.0.74"
sha256 = "1.0.0"
sha2 = "0.10.0"
5 changes: 3 additions & 2 deletions stageleft_tool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{env, fs};

use proc_macro2::Span;
use quote::ToTokens;
use sha2::{Digest, Sha256};
use syn::visit::Visit;
use syn::visit_mut::VisitMut;
use syn::{parse_quote, UsePath};
Expand Down Expand Up @@ -41,7 +42,7 @@ impl<'a> Visit<'a> for GenMacroVistor {
.chars()
.filter(|c| c.is_alphanumeric())
.collect::<String>();
let contents_hash = sha256::digest(contents);
let contents_hash = format!("{:X}", Sha256::digest(contents));
self.exported_macros
.insert((contents_hash, cur_path.to_token_stream().to_string()));
}
Expand Down Expand Up @@ -72,7 +73,7 @@ pub fn gen_macro(staged_path: &Path, crate_name: &str) {

let proc_macro_wrapper: syn::ItemFn = parse_quote!(
#[proc_macro]
#[expect(unused_qualifications, reason = "generated code")]
#[expect(unused_qualifications, non_snake_case, reason = "generated code")]
pub fn #underscored_path(input: ::proc_macro::TokenStream) -> ::proc_macro::TokenStream {
let input = ::stageleft::internal::TokenStream::from(input);
let out = #exported_from_parsed::#underscored_path_impl(input);
Expand Down

0 comments on commit 0dc709e

Please sign in to comment.