#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT"
PROFILE="--release"
FEATURES="--features tree-sitter-cangjie"
while [[ $# -gt 0 ]]; do
case "$1" in
--debug)
PROFILE=""
shift
;;
--no-cangjie)
FEATURES=""
shift
;;
--help|-h)
echo "用法: $0 [--debug] [--no-cangjie]"
echo ""
echo "选项:"
echo " --debug 构建 debug 版本(默认 release)"
echo " --no-cangjie 不包含 Cangjie 语言支持(默认包含)"
echo ""
echo "输出二进制位置: target/release/codelattice"
exit 0
;;
*)
echo "未知选项: $1(使用 --help 查看帮助)"
exit 1
;;
esac
done
if ! command -v cargo &> /dev/null; then
echo "错误: 未找到 cargo。请先安装 Rust 工具链:"
echo " curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
exit 1
fi
echo "==> CodeLattice 本地构建"
echo " 项目根目录: $PROJECT_ROOT"
echo " 构建模式: ${PROFILE:-debug}"
echo " 特性: ${FEATURES:-(无)}"
echo ""
echo "==> 开始构建..."
cargo build $PROFILE $FEATURES -p gitnexus-rust-core-cli --bins
if [[ -n "$PROFILE" ]]; then
BIN_DIR="$PROJECT_ROOT/target/release"
else
BIN_DIR="$PROJECT_ROOT/target/debug"
fi
BIN_PATH="$BIN_DIR/codelattice"
COMPAT_BIN_PATH="$BIN_DIR/gitnexus-rust-core-cli"
echo ""
echo "==> 构建完成"
echo " 二进制: $BIN_PATH"
echo " 兼容名: $COMPAT_BIN_PATH"
echo ""
echo "==> 快速试用"
echo ""
echo " # Rust 项目分析(Unified JSON)"
echo " $BIN_PATH analyze --root fixtures/rust/portable-smoke --format json"
echo ""
echo " # Rust 下游消费格式(bridge format)"
echo " $BIN_PATH analyze --root fixtures/rust/portable-smoke --language rust --format gitnexus-rc --strict"
echo ""
if [[ -n "$FEATURES" ]]; then
echo " # Cangjie 项目分析"
echo " $BIN_PATH analyze --root fixtures/cangjie/portable-smoke --format json"
echo ""
echo " # Cangjie Bridge 格式"
echo " $BIN_PATH analyze --root fixtures/cangjie/portable-smoke --language cangjie --format gitnexus-rc --strict"
echo ""
fi
echo " # 自身分析"
echo " $BIN_PATH analyze --root . --language auto --format json"
echo ""
echo " # 质量门检查"
echo " $BIN_PATH quality --root fixtures/rust/portable-smoke --language rust"
echo ""
echo " # Bridge 格式验证(端点完整性 + 结构)"
echo " ./scripts/verify-bridge.sh"
echo ""
echo " # 更多用法见 README.md"