准备发布 v0.1.0

- 添加 Apache-2.0 许可证
- 添加 CHANGELOG.md 变更日志
- 添加 SECURITY.md 安全策略
- 添加 README.zh-CN.md 中文文档
- 添加 rustfmt.toml 代码格式配置
- 添加 scripts/pre_publish_check.sh 发布检查脚本
- 更新 Cargo.toml 元数据(分类、关键词、文档链接)
- 完善 README.md 示例代码
- 优化 SM2/SM9 性能和测试覆盖率
This commit is contained in:
huangxt
2026-03-07 19:27:41 +08:00
parent bec7f277ce
commit 8ad52ecac0
23 changed files with 1275 additions and 361 deletions
+86
View File
@@ -0,0 +1,86 @@
#!/usr/bin/env bash
# Pre-publish checks for libsmx
# Run this before `cargo publish` to catch common issues.
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
pass() { echo -e "${GREEN}[PASS]${NC} $1"; }
fail() { echo -e "${RED}[FAIL]${NC} $1"; exit 1; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
echo "=========================================="
echo " libsmx Pre-Publish Checks"
echo "=========================================="
echo ""
# 1. Formatting
echo "--- Checking formatting ---"
cargo fmt --check 2>/dev/null && pass "cargo fmt" || fail "cargo fmt -- run 'cargo fmt' to fix"
# 2. Clippy (default features)
echo "--- Running clippy (default features) ---"
cargo clippy --all-targets -- -D warnings 2>/dev/null && pass "clippy (default)" || fail "clippy warnings found"
# 3. Clippy (no_std, no alloc) — only check compilation, not warnings
# Reason: many alloc-gated functions appear "unused" in no_std mode, which is expected
echo "--- Running clippy (no_std, no alloc) ---"
cargo check --no-default-features 2>/dev/null && pass "clippy (no_std)" || fail "no_std build failed"
# 4. Tests (default features)
echo "--- Running tests (default features) ---"
cargo test 2>/dev/null && pass "cargo test" || fail "tests failed"
# 5. Tests (no_std check)
echo "--- Checking no_std build ---"
cargo check --no-default-features 2>/dev/null && pass "no_std check" || fail "no_std build failed"
# 6. Doc build
echo "--- Building documentation ---"
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps 2>/dev/null && pass "cargo doc" || fail "doc build failed"
# 7. Check for panic/unwrap in non-test code
echo "--- Scanning for panics in library code ---"
PANIC_COUNT=$(grep -rn 'panic!\|\.unwrap()\|\.expect(' src/ --include='*.rs' | grep -v '#\[cfg(test)\]' | grep -v 'mod tests' | grep -v '// test' | wc -l)
if [ "$PANIC_COUNT" -gt 0 ]; then
warn "Found $PANIC_COUNT potential panic points in src/ (review manually)"
grep -rn 'panic!\|\.unwrap()\|\.expect(' src/ --include='*.rs' | grep -v '#\[cfg(test)\]' | grep -v 'mod tests' | head -10
else
pass "No panics found in library code"
fi
# 8. Check Cargo.toml metadata
echo "--- Checking Cargo.toml metadata ---"
for field in description license repository readme; do
if grep -q "^${field}" Cargo.toml; then
pass "Cargo.toml has '$field'"
else
fail "Cargo.toml missing '$field'"
fi
done
# 9. Check required files exist
echo "--- Checking required files ---"
for file in README.md LICENSE CHANGELOG.md SECURITY.md; do
if [ -f "$file" ]; then
pass "$file exists"
else
warn "$file not found"
fi
done
# 10. Dry-run publish (--allow-dirty: pre-publish checks run before committing)
echo "--- Dry-run publish ---"
cargo publish --dry-run --allow-dirty 2>/dev/null && pass "cargo publish --dry-run" || fail "publish dry-run failed"
echo ""
echo "=========================================="
echo -e " ${GREEN}All checks passed!${NC}"
echo "=========================================="
echo ""
echo "Ready to publish. Run:"
echo " cargo publish"