fix: install.sh respects CARGO_TARGET_DIR via cargo metadata
The installer hardcoded target/ as the build output directory, but CARGO_TARGET_DIR (or [build] target-dir in cargo config) can redirect output anywhere (e.g., /tmp/cargo-target). Now uses cargo metadata --format-version 1 to get the actual target_directory, falling back to $SCRIPT_DIR/target if metadata fails. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
17
install.sh
17
install.sh
@@ -40,16 +40,21 @@ if ! (cd "$SCRIPT_DIR" && cargo build --release); then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Find the binary — handles custom target triples (e.g., CARGO_BUILD_TARGET
|
# Find the binary — respects CARGO_TARGET_DIR, custom target triples, etc.
|
||||||
# puts it in target/<triple>/release/ instead of target/release/)
|
# Use cargo metadata as the source of truth for the target directory.
|
||||||
BINARY="$SCRIPT_DIR/target/release/$BINARY_NAME"
|
TARGET_DIR=$(cd "$SCRIPT_DIR" && cargo metadata --format-version 1 --no-deps 2>/dev/null | jq -r '.target_directory' 2>/dev/null) || true
|
||||||
|
TARGET_DIR="${TARGET_DIR:-$SCRIPT_DIR/target}"
|
||||||
|
|
||||||
|
BINARY="$TARGET_DIR/release/$BINARY_NAME"
|
||||||
if [[ ! -f "$BINARY" ]]; then
|
if [[ ! -f "$BINARY" ]]; then
|
||||||
BINARY=$(find "$SCRIPT_DIR/target" -name "$BINARY_NAME" -type f -path "*/release/*" ! -name "*.d" 2>/dev/null | head -1)
|
# Fall back to searching (handles custom target triples like target/<triple>/release/)
|
||||||
|
BINARY=$(find "$TARGET_DIR" -name "$BINARY_NAME" -type f -path "*/release/*" ! -name "*.d" 2>/dev/null | head -1)
|
||||||
fi
|
fi
|
||||||
if [[ -z "${BINARY:-}" || ! -f "$BINARY" ]]; then
|
if [[ -z "${BINARY:-}" || ! -f "$BINARY" ]]; then
|
||||||
echo "ERROR: Build succeeded but binary not found."
|
echo "ERROR: Build succeeded but binary not found."
|
||||||
echo " Searched: $SCRIPT_DIR/target/*/release/$BINARY_NAME"
|
echo " Target dir: $TARGET_DIR"
|
||||||
echo " Contents: $(ls "$SCRIPT_DIR/target/release/" 2>/dev/null || echo '(no target/release/)')"
|
echo " Searched: $TARGET_DIR/*/release/$BINARY_NAME"
|
||||||
|
echo " Contents: $(ls "$TARGET_DIR/release/" 2>/dev/null || echo '(empty or missing)')"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "[ok] Built: $(ls -lh "$BINARY" | awk '{print $5}')"
|
echo "[ok] Built: $(ls -lh "$BINARY" | awk '{print $5}')"
|
||||||
|
|||||||
Reference in New Issue
Block a user