From 5d04ddc593731d0e671eaf7cac1dc1d12d122dff Mon Sep 17 00:00:00 2001 From: vasilito Date: Fri, 24 Jul 2026 08:14:48 +0900 Subject: [PATCH] base recipe: make EXISTING_BINS filtering fast (one scan, not N full-tree greps) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The driver-list filter ran `grep -R "^name = \"$bin\"$" $COOKBOOK_SOURCE` once PER bin (~40 bins). $COOKBOOK_SOURCE is local/sources/base, whose target/ build tree is ~8.7 GB, so each grep re-scanned gigabytes and the whole loop scanned hundreds of GB — a very slow build phase. Collect the workspace's crate names ONCE from Cargo.toml files (skipping target/ via --exclude-dir), into a bash associative array, then do an O(1) membership check per bin. Verified equivalent (same bins selected) and near-instant: the single scan of local/sources/base completes in ~0.02s vs minutes for the per-bin recursive greps. --- recipes/core/base/recipe.toml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/recipes/core/base/recipe.toml b/recipes/core/base/recipe.toml index a612115326..60f970a73b 100644 --- a/recipes/core/base/recipe.toml +++ b/recipes/core/base/recipe.toml @@ -160,11 +160,21 @@ esac mkdir -pv "${COOKBOOK_STAGE}/usr/bin" "${COOKBOOK_STAGE}/usr/lib/drivers" export CARGO_PROFILE_RELEASE_OPT_LEVEL=s export CARGO_PROFILE_RELEASE_PANIC=abort -# Only build drivers that actually have source Cargo.toml entries +# Only build drivers that actually have source Cargo.toml entries. +# Collect the workspace's crate names ONCE from Cargo.toml files, skipping the +# multi-GB target/ build trees. The previous code ran a full recursive grep of +# the entire source (including target/, ~8.7 GB) for EVERY bin (~40 of them), +# re-scanning gigabytes per entry — extremely slow. One scan + O(1) membership +# lookup is equivalent and near-instant. +declare -A HAVE_CRATE=() +while IFS= read -r crate_name +do + HAVE_CRATE["${crate_name}"]=1 +done < <(grep -Rhs --include=Cargo.toml --exclude-dir=target '^name = ' "${COOKBOOK_SOURCE}" | sed -E 's/^name = "([^"]+)".*/\\1/') EXISTING_BINS=() for bin in "${BINS[@]}" do - if grep -Rqs "^name = \\\"${bin}\\\"$" "${COOKBOOK_SOURCE}"; then + if [[ -n "${HAVE_CRATE[${bin}]:-}" ]]; then EXISTING_BINS+=("${bin}") fi done