NAC_Blockchain/scripts/build_all.sh

115 lines
2.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# NAC区块链统一编译脚本
# 作者NAC公链开发小组
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
# 默认为debug模式
BUILD_MODE="debug"
CARGO_FLAGS=""
# 解析参数
while [[ $# -gt 0 ]]; do
case $1 in
--release|-r)
BUILD_MODE="release"
CARGO_FLAGS="--release"
shift
;;
*)
echo "未知参数: $1"
exit 1
;;
esac
done
echo "========================================="
echo " NAC区块链统一编译脚本"
echo " 模式: ${BUILD_MODE}"
echo "========================================="
echo ""
SUCCESS=0
FAILED=0
# 编译模块函数
build_module() {
local module=$1
local name=$2
if [ -d "$module" ]; then
echo -e "${YELLOW}正在编译 ${name}...${NC}"
cd "$module"
if cargo build $CARGO_FLAGS 2>&1 | tee /tmp/build_${name}.log; then
echo -e "${GREEN}${name} 编译成功${NC}"
((SUCCESS++))
else
echo -e "${RED}${name} 编译失败${NC}"
echo "错误日志: /tmp/build_${name}.log"
((FAILED++))
fi
cd ..
echo ""
else
echo -e "${YELLOW}跳过 ${name}(目录不存在)${NC}"
echo ""
fi
}
# 开始编译
START_TIME=$(date +%s)
# 1. 编译nac-udm核心模块
build_module "nac-udm" "NAC统一数据模型"
# 2. 编译charter-compiler
build_module "charter-compiler" "Charter编译器"
# 3. 编译nvm_v2
build_module "nvm_v2" "NAC虚拟机v2"
# 4. 编译其他模块(如果存在)
build_module "nac-nvm" "NAC虚拟机"
build_module "nac-cbpp" "CBPP共识协议"
build_module "nac-gnacs" "GNACS资产分类"
build_module "nac-acc" "ACC协议"
build_module "nac-acc20c" "ACC-20C合规协议"
build_module "nac-rpc" "NAC RPC接口"
build_module "nac-storage" "NAC存储层"
# 计算耗时
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
# 输出统计
echo "========================================="
echo "编译完成"
echo "========================================="
echo -e "成功: ${GREEN}${SUCCESS}${NC}"
echo -e "失败: ${RED}${FAILED}${NC}"
echo "耗时: ${DURATION}"
echo ""
if [ $FAILED -eq 0 ]; then
echo -e "${GREEN}✓ 所有模块编译成功!${NC}"
echo ""
echo "编译产物位置:"
if [ "$BUILD_MODE" == "release" ]; then
echo " target/release/"
else
echo " target/debug/"
fi
exit 0
else
echo -e "${RED}✗ 部分模块编译失败,请检查错误日志${NC}"
exit 1
fi