Skip to content

Commit 719da09

Browse files
committed
Prevent rebuilds due to different order of tokens in ct_token_map
1 parent fe3c354 commit 719da09

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lrlex/src/lib/ctbuilder.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,9 +1205,12 @@ pub fn ct_token_map<StorageT: Display + ToTokens>(
12051205
let timestamp = env!("VERGEN_BUILD_TIMESTAMP");
12061206
let mod_ident = format_ident!("{}", mod_name);
12071207
write!(outs, "// lrlex build time: {}\n\n", quote!(#timestamp),).ok();
1208-
let tokens = &token_map
1209-
.borrow()
1210-
.iter()
1208+
// Sort the tokens so that they're always in the same order.
1209+
// This will prevent unneeded rebuilds.
1210+
let mut token_map_sorted = Vec::from_iter(token_map.borrow().iter());
1211+
token_map_sorted.sort_by_key(|(k, _)| *k);
1212+
let tokens = &token_map_sorted
1213+
.into_iter()
12111214
.map(|(k, id)| {
12121215
let name = match rename_map {
12131216
Some(rmap) => *rmap.get(k.as_str()).unwrap_or(&k.as_str()),

0 commit comments

Comments
 (0)