Vapora/justfiles/distro.just
2026-02-17 23:15:12 +00:00

231 lines
7.7 KiB
Plaintext

# ╔══════════════════════════════════════════════════════════════════════╗
# ║ DISTRIBUTION & PACKAGING RECIPES ║
# ║ Targets, cross-compilation, and distribution ║
# ╚══════════════════════════════════════════════════════════════════════╝
distro-help:
@echo "DISTRIBUTION & TARGET MODULE"
@echo ""
@echo "Targets:"
@echo " just distro::list-targets List installed Rust targets"
@echo " just distro::install-targets Install common cross-compile targets"
@echo " just distro::install-target TGT Install specific target"
@echo ""
@echo "Build:"
@echo " just distro::build-target TGT Build for specific target"
@echo " just distro::build-all-targets Build for all installed targets"
@echo ""
@echo "Installation:"
@echo " just distro::install Install server binaries to ~/.local/bin"
@echo " just distro::install DIR=/path Install to custom directory"
@echo " just distro::install UI=true Also build frontend (trunk --release)"
@echo ""
@echo " Binaries installed: vapora-backend, vapora-agents, vapora-mcp-server,"
@echo " vapora-a2a, vapora (CLI)"
@echo ""
@echo "Utilities:"
@echo " just distro::clean-targets Clean target build artifacts"
WORKSPACE_ROOT := justfile_directory()
# === TARGETS ===
[doc("List installed Rust targets")]
list-targets:
@echo "=== Installed Rust Targets ==="
rustup target list | grep installed
@echo ""
@echo "Common VAPORA targets:"
@echo " x86_64-unknown-linux-gnu Linux x86_64 (default)"
@echo " x86_64-apple-darwin macOS Intel"
@echo " aarch64-apple-darwin macOS ARM64 (Apple Silicon)"
@echo " aarch64-unknown-linux-gnu Linux ARM64"
@echo " x86_64-pc-windows-gnu Windows x86_64"
@echo " wasm32-unknown-unknown WebAssembly (frontend)"
[doc("Install common cross-compile targets including wasm32")]
install-targets:
#!/usr/bin/env bash
set -e
echo "=== Installing Rust targets ==="
TARGETS=(
"x86_64-unknown-linux-gnu"
"x86_64-apple-darwin"
"aarch64-apple-darwin"
"aarch64-unknown-linux-gnu"
"x86_64-pc-windows-gnu"
"wasm32-unknown-unknown"
)
for target in "${TARGETS[@]}"; do
if rustup target list --installed | grep -q "$target"; then
echo " ✓ $target (already installed)"
else
echo " Installing $target..."
rustup target add "$target"
fi
done
echo "✓ Targets installed"
[doc("Install specific Rust target")]
install-target TARGET:
#!/usr/bin/env bash
set -e
echo "=== Installing target: {{TARGET}} ==="
rustup target add "{{TARGET}}"
echo "✓ {{TARGET}} installed"
# === BUILD ===
[doc("Build for specific target")]
build-target TARGET:
#!/usr/bin/env bash
set -e
echo "=== Building for {{TARGET}} (release) ==="
cd "{{ WORKSPACE_ROOT }}"
cargo build --release --target "{{TARGET}}" --workspace
echo "✓ Build complete for {{TARGET}}"
[doc("Build for all installed targets (excludes wasm32 — use frontend-build-release for that)")]
build-all-targets:
#!/usr/bin/env bash
set -e
echo "=== Building for all native targets ==="
cd "{{ WORKSPACE_ROOT }}"
TARGETS=$(rustup target list --installed | grep -v wasm32)
for target in $TARGETS; do
echo ""
echo "Building for $target..."
cargo build --release --target "$target" --workspace || {
echo "✗ Build failed for $target"
continue
}
echo "✓ $target complete"
done
echo ""
echo "✓ All native target builds complete"
# === INSTALLATION ===
# Build and install all release binaries.
#
# Usage:
# just distro::install → ~/.local/bin, native only
# just distro::install DIR=/usr/local/bin → custom dir, native only
# just distro::install UI=true → ~/.local/bin + trunk --release
# just distro::install DIR=/opt UI=true → custom dir + trunk --release
#
# Binaries: vapora-backend, vapora-agents, vapora-mcp-server, vapora-a2a, vapora (CLI)
[doc("Build and install server binaries (DIR=path, UI=true for frontend)")]
install DIR="" UI="false":
#!/bin/bash
set -e
WORKSPACE="{{ WORKSPACE_ROOT }}"
WORKSPACE="$(cd "$WORKSPACE" && pwd)" || { echo "✗ Failed to access workspace"; exit 1; }
if [ -z "{{ DIR }}" ]; then
INSTALL_DIR="$HOME/.local/bin"
else
INSTALL_DIR="{{ DIR }}"
fi
echo "=== Building and Installing VAPORA binaries ==="
echo "Workspace: $WORKSPACE"
echo "Install directory: $INSTALL_DIR"
echo "Frontend (UI): {{ UI }}"
echo ""
# Build all server binaries in one pass (Cargo deduplicates shared deps)
echo "Building release binaries..."
cd "$WORKSPACE"
cargo build --release \
-p vapora-backend \
-p vapora-agents \
-p vapora-mcp-server \
-p vapora-a2a \
-p vapora-cli \
--quiet
echo "✓ Native binaries built"
echo ""
# Optionally build the Leptos frontend via trunk
if [ "{{ UI }}" = "true" ]; then
if ! command -v trunk &>/dev/null; then
echo "✗ trunk not found. Install with: cargo install trunk"
exit 1
fi
echo "Building frontend (trunk --release)..."
cd "$WORKSPACE/crates/vapora-frontend"
trunk build --release
echo "✓ Frontend built → $WORKSPACE/crates/vapora-frontend/dist"
cd "$WORKSPACE"
echo ""
fi
# Copy binaries to install dir
mkdir -p "$INSTALL_DIR" || { echo "✗ Failed to create $INSTALL_DIR"; exit 1; }
echo "Installing to $INSTALL_DIR..."
declare -a BINARIES=(
"vapora-backend"
"vapora-agents"
"vapora-mcp-server"
"vapora-a2a"
"vapora"
)
INSTALLED=0
MISSING=0
for BIN_NAME in "${BINARIES[@]}"; do
BIN_PATH="$WORKSPACE/target/release/$BIN_NAME"
if [ -f "$BIN_PATH" ]; then
cp "$BIN_PATH" "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/$BIN_NAME"
echo " ✓ $BIN_NAME"
INSTALLED=$((INSTALLED + 1))
else
echo " ✗ $BIN_NAME (not found in target/release — build may have failed)"
MISSING=$((MISSING + 1))
fi
done
echo ""
if [ "$INSTALLED" -eq 0 ]; then
echo "✗ No binaries were installed"
exit 1
fi
if [ "$MISSING" -gt 0 ]; then
echo "⚠ $MISSING binaries missing — check build output above"
fi
echo "✓ Installation complete ($INSTALLED/$((INSTALLED + MISSING)) binaries)"
echo ""
echo "Install dir: $INSTALL_DIR"
if echo "$INSTALL_DIR" | grep -q "\.local/bin"; then
echo ""
echo "Ensure PATH includes $INSTALL_DIR:"
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
fi
echo ""
echo "Verify:"
echo " $INSTALL_DIR/vapora-backend --help"
echo " $INSTALL_DIR/vapora-agents --help"
echo " $INSTALL_DIR/vapora-a2a --help"
if [ "{{ UI }}" = "true" ]; then
echo ""
echo "Frontend dist: $WORKSPACE/crates/vapora-frontend/dist"
fi
echo ""
# === UTILITIES ===
[doc("Clean all target build artifacts")]
clean-targets:
@echo "=== Cleaning target artifacts ==="
cd "{{ WORKSPACE_ROOT }}" && cargo clean
@echo "✓ Cleaned all targets"