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