From: 志宇 Date: Thu, 17 Sep 2026 04:24:09 +0000 (+0000) Subject: chore(just): Add `verify-standalone` recipe X-Git-Url: http://internal-gitweb-vhost/-script/src/example_cli/database/enum.AnyDatabase.html?a=commitdiff_plain;h=37411ea4713a8706c3af9beda24494f99649fed7;p=bdk chore(just): Add `verify-standalone` recipe Packages a crate and builds the packaged copy outside the workspace, so sibling workspace crates resolve from crates.io instead of local paths. This catches crates that accidentally depend on unreleased changes in other crates of the same workspace. Extra args are passed to `cargo build`. Added alias `vs` for quick access. Co-Authored-By: Claude Opus 5 --- diff --git a/justfile b/justfile index 7d96010c..17043f25 100644 --- a/justfile +++ b/justfile @@ -4,6 +4,7 @@ alias f := fmt alias t := test alias p := pre-push alias d := doc +alias vs := verify-standalone _default: @just --list @@ -62,3 +63,58 @@ pre-push: fmt check test # Check documentation for all workspace packages doc: RUSTDOCFLAGS='-D warnings' cargo doc --workspace --no-deps + +# A failure usually means the crate uses something from a sibling workspace +# crate that isn't released on crates.io yet +[doc("Verify a crate builds as published, against released workspace crates")] +[positional-arguments] +verify-standalone crate *args: + #!/usr/bin/env bash + set -euo pipefail + + command -v jq >/dev/null 2>&1 || { echo "Error: jq is required but not installed" >&2; exit 1; } + + # Positional args avoid word-splitting/quoting issues with `{{{{args}}` + CRATE="$1" + shift + + echo "Verifying $CRATE can build standalone..." + + # Package the crate; extra args are passed to `cargo build` only + cargo package -p "$CRATE" --no-verify --allow-dirty + + # Find the packaged tarball (respects CARGO_TARGET_DIR / build.target-dir) + METADATA=$(cargo metadata --format-version 1 --no-deps) + TARGET_DIR=$(jq -r '.target_directory' <<< "$METADATA") + CRATE_VERSION=$(jq -r --arg c "$CRATE" '.packages[] | select(.name == $c) | .version' <<< "$METADATA") + TARBALL="$TARGET_DIR/package/${CRATE}-${CRATE_VERSION}.crate" + + if [ ! -f "$TARBALL" ]; then + echo "Error: Could not find packaged tarball at $TARBALL" + exit 1 + fi + + # Reuse a persistent cache across runs/crates instead of re-downloading + # the registry index and every dependency from scratch each invocation + CACHE_DIR="$TARGET_DIR/verify-standalone-cache" + mkdir -p "$CACHE_DIR/cargo-home" "$CACHE_DIR/target" + + # Create a temporary directory for unpacking + TEMP_DIR=$(mktemp -d) + trap "rm -rf $TEMP_DIR" EXIT + + # Unpack the tarball + tar -xzf "$TARBALL" -C "$TEMP_DIR" + + # Build outside the workspace so sibling crates resolve from crates.io + cd "$TEMP_DIR/${CRATE}-${CRATE_VERSION}" + + # Reuse the registry cache and build artifacts across invocations for speed + export CARGO_HOME="$CACHE_DIR/cargo-home" + export CARGO_TARGET_DIR="$CACHE_DIR/target" + + echo "Building $CRATE in isolation..." + # --locked: use the packaged Cargo.lock as-is + cargo build --locked "$@" + + echo "✅ $CRATE builds successfully in isolation!"