]> Untitled Git - bdk/commitdiff
chore(just): Add `verify-standalone` recipe
author志宇 <hello@evanlinjin.me>
Thu, 17 Sep 2026 04:24:09 +0000 (04:24 +0000)
committer志宇 <hello@evanlinjin.me>
Mon, 19 Oct 2026 03:51:18 +0000 (14:51 +1100)
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 <noreply@anthropic.com>
justfile

index 7d96010c8d863986fa9ab9743cd90f058e791f3f..17043f254d75d93b0b9e2cd9a638a25a4ab7200f 100644 (file)
--- 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!"