From 234639281a169b09c982d20bc4b5d8fd8ed40212 Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Sun, 23 Feb 2025 11:38:20 +0100 Subject: [PATCH 1/2] Switching from glob to wax to fix symlink follow issue --- Cargo.lock | 46 +++++++++++++++++++++++++++- Cargo.toml | 2 +- wasm-rpc-stubgen/Cargo.toml | 2 +- wasm-rpc-stubgen/src/commands/app.rs | 36 +++++++++++++--------- 4 files changed, 68 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f98ab8e3c..3d7070c73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1822,6 +1822,26 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "const_format" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126f97965c8ad46d6d9163268ff28432e8f6a1196a55578867832e3049df63dd" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d57c2eccfb16dbac1f4e61e206105db5820c9d26c3c472bc17c774259ef7744" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + [[package]] name = "constant_time_eq" version = "0.3.1" @@ -4280,7 +4300,6 @@ dependencies = [ "colored 3.0.0", "dir-diff", "fs_extra", - "glob", "golem-wasm-ast 1.1.20", "golem-wasm-rpc 1.1.20", "golem-wit 0.0.0", @@ -4307,6 +4326,7 @@ dependencies = [ "toml", "wac-graph", "walkdir", + "wax", "wit-bindgen-rust 0.26.0", "wit-encoder", "wit-parser 0.221.3", @@ -7276,6 +7296,15 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "pori" +version = "0.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a63d338dec139f56dacc692ca63ad35a6be6a797442479b55acd611d79e906" +dependencies = [ + "nom 7.1.3", +] + [[package]] name = "portable-atomic" version = "1.10.0" @@ -11428,6 +11457,21 @@ dependencies = [ "wast 225.0.0", ] +[[package]] +name = "wax" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d12a78aa0bab22d2f26ed1a96df7ab58e8a93506a3e20adb47c51a93b4e1357" +dependencies = [ + "const_format", + "itertools 0.11.0", + "nom 7.1.3", + "pori", + "regex", + "thiserror 1.0.69", + "walkdir", +] + [[package]] name = "web-sys" version = "0.3.77" diff --git a/Cargo.toml b/Cargo.toml index c61e3d5b9..663c4e78c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,6 @@ dirs = "6.0.0" fs_extra = "1.3.0" futures = "0.3.31" futures-util = "0.3.31" -glob = "0.3.2" heck = "0.5.0" http = "1.2.0" http-body-util = "0.1.2" @@ -107,6 +106,7 @@ uuid = "1.13.2" version-compare = "0.2.0" wac-graph = "=0.6.1" walkdir = "2.5.0" +wax = "0.6.0" wit-bindgen-rust = "=0.26.0" wit-encoder = "=0.221.2" wit-parser = "=0.221.3" diff --git a/wasm-rpc-stubgen/Cargo.toml b/wasm-rpc-stubgen/Cargo.toml index 5296fd024..c8f243692 100644 --- a/wasm-rpc-stubgen/Cargo.toml +++ b/wasm-rpc-stubgen/Cargo.toml @@ -38,7 +38,6 @@ clap = { workspace = true } colored = { workspace = true } dir-diff = { workspace = true } fs_extra = { workspace = true } -glob = { workspace = true } heck = { workspace = true } id-arena = { workspace = true } indexmap = { workspace = true } @@ -61,6 +60,7 @@ tokio = { workspace = true } toml = { workspace = true } wac-graph = { workspace = true } walkdir = { workspace = true } +wax = { workspace = true } wit-bindgen-rust = { workspace = true } wit-encoder = { workspace = true } wit-parser = { workspace = true } diff --git a/wasm-rpc-stubgen/src/commands/app.rs b/wasm-rpc-stubgen/src/commands/app.rs index 92898c54e..fc5c8f183 100644 --- a/wasm-rpc-stubgen/src/commands/app.rs +++ b/wasm-rpc-stubgen/src/commands/app.rs @@ -22,7 +22,6 @@ use crate::{commands, naming, WasmRpcOverride}; use anyhow::{anyhow, bail, Context, Error}; use colored::control::SHOULD_COLORIZE; use colored::Colorize; -use glob::{glob_with, MatchOptions}; use golem_wasm_rpc::WASM_RPC_VERSION; use itertools::Itertools; use serde::Serialize; @@ -35,6 +34,7 @@ use std::path::{Path, PathBuf}; use std::process::Command; use std::time::SystemTime; use walkdir::WalkDir; +use wax::{Glob, LinkBehavior, WalkBehavior}; pub struct Config { pub app_source_mode: ApplicationSourceMode, @@ -1289,25 +1289,31 @@ fn compile_and_collect_globs(root_dir: &Path, globs: &[String]) -> Result, _>>() + .map_err(|err| anyhow!(err))? + .iter() + .map(|glob| { + glob.walk_with_behavior( + root_dir, + WalkBehavior { + link: LinkBehavior::ReadFile, + ..WalkBehavior::default() }, ) - .with_context(|| format!("Failed to compile glob expression: {}", pattern)) + .into_iter() + .collect::>() + }) + .flatten() + .map(|walk_item| { + walk_item + .map(|entry| entry.path().to_path_buf()) + .with_context(|| "Failed to get path from item when evaluating glob expressions") }) .collect::, _>>() .map_err(|err| anyhow!(err)) - .and_then(|paths| { - paths - .into_iter() - .flatten() - .collect::, _>>() - .map_err(|err| anyhow!(err)) - }) } fn create_generated_base_wit( From a33f0db7617f8c70f139ae720a04e99c0b3dc5a9 Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Sun, 23 Feb 2025 11:49:44 +0100 Subject: [PATCH 2/2] Clippy --- wasm-rpc-stubgen/src/commands/app.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/wasm-rpc-stubgen/src/commands/app.rs b/wasm-rpc-stubgen/src/commands/app.rs index fc5c8f183..d1baeda5b 100644 --- a/wasm-rpc-stubgen/src/commands/app.rs +++ b/wasm-rpc-stubgen/src/commands/app.rs @@ -1295,7 +1295,7 @@ fn compile_and_collect_globs(root_dir: &Path, globs: &[String]) -> Result, _>>() .map_err(|err| anyhow!(err))? .iter() - .map(|glob| { + .flat_map(|glob| { glob.walk_with_behavior( root_dir, WalkBehavior { @@ -1303,10 +1303,8 @@ fn compile_and_collect_globs(root_dir: &Path, globs: &[String]) -> Result>() }) - .flatten() .map(|walk_item| { walk_item .map(|entry| entry.path().to_path_buf())