From ef993b39931450b0d77c54909f4e018cbf390122 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 15 Feb 2024 07:56:20 -0800 Subject: [PATCH] Sort directory contents when loading WIT The order that binary wasms are added to `Resolve` can change how some items are numbered, so to keep everything deterministic be sure to sort by filename and don't rely on underlying filesystem ordering. --- crates/wit-parser/src/resolve.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/wit-parser/src/resolve.rs b/crates/wit-parser/src/resolve.rs index 273c183626..504c56f744 100644 --- a/crates/wit-parser/src/resolve.rs +++ b/crates/wit-parser/src/resolve.rs @@ -228,8 +228,12 @@ impl Resolve { if !path.exists() { return Ok(ret); } - for dep in path.read_dir().context("failed to read directory")? { - let dep = dep.context("failed to read directory iterator")?; + let mut entries = path + .read_dir() + .and_then(|i| i.collect::>>()) + .context("failed to read directory")?; + entries.sort_by_key(|e| e.file_name()); + for dep in entries { let path = dep.path(); let pkg = if dep.file_type()?.is_dir() {