A rust project template for general purpose.

Overview

Rust 项目的初始化模版

开发项目时,会有不少关于项目的ci, lint, typo等配置,通过该模板创建项目,帮助快速构建这些配置:

  • github action 配置,用于在CI对代码进行完整的检查和构建
  • pre-commit 配置,用于在commit时进行代码规范检查,如: cargo fmt -- --check, cargo deny check -d, cargo clippy, typos,等
  • cargo deny 配置,用于检查rust依赖的安全性
  • cliff 配置,用于自动生成CHANGELOG
  • typo 配置,用于检查代码中的拼写错误

安装相关工具

安装 cargo generate

用于根据模板生成代码

cargo install cargo-generate

更多参考:https://github.com/cargo-generate/cargo-generate

安装 pre-commit

pre-commit 是一个代码检查工具,可以在提交代码前进行代码检查。

pip install pre-commit

更多参考: https://pre-commit.com/

安装 Cargo deny

用于检查依赖的安全性

cargo install --locked cargo-deny

更多参考: https://github.com/EmbarkStudios/cargo-deny

也可以根据自己的需要自定义配置: https://embarkstudios.github.io/cargo-deny/

如果在执行 cargo deny check 时提示如下错误:

2024-08-06 03:31:18 [ERROR] failed to open advisory database: "/Users/xxx/.cargo/advisory-dbs/github.com-2f857891b7f43c59" does not appear to be a git repository: Could not retrieve metadata of "/Users/xxx/.cargo/advisory-dbs/github.com-2f857891b7f43c59": No such file or directory (os error 2)

可以尝试执行 cargo deny fetch 解决

安装 typos

typos 是一个拼写检查工具

cargo install typos-cli

更多参考: https://github.com/crate-ci/typos

安装 git cliff

git cliff 是一个生成 changelog 的工具。

cargo install git-cliff

更多参考: https://git-cliff.org/docs/

使用

cargo generate 创建项目

cargo generate fan-tastic-z/rust-project-template

github action

github action 中这部分替换 是为了保证github action在当前template下可以正常运行,如果生成项目之后这部分可以根据需要进行删除

- name: Get repository name
    run: |
        echo "repo_name=$(basename $GITHUB_REPOSITORY)" >> "$GITHUB_ENV"
- name: Replace package name in Cargo.toml
    run: |
    sed -i "s/{{project-name}}/$repo_name/g" Cargo.toml

替换 cliff 配置

替换 cliff.toml 配置文件中 下面配置中 replace 的值为自己的仓库地址

postprocessors = [
  { pattern = '\$REPO', replace = "https://github.com/fan-tastic-z/rust-project-template" }, # replace repository URL
]

安装 git hook scripts

在项目目录下执行

pre-commit install
You might also like...
🖨 Template for Rust applications & smart contracts @okp4.

Rust Template Template for Rust projects @okp4. Purpose & Philosophy This repository holds the template for building Rust projects with a consistent s

Minimal compile-time Rust template engine

boilerplate boilerplate is a minimal compile-time Rust text template engine. Quick Start Add boilerplate to your project's Cargo.toml: [dependencies]

Cloup is a template manager that provides the files you desire when you need them, written in Rust.
Cloup is a template manager that provides the files you desire when you need them, written in Rust.

cloup cloup is a template manager that delivers the files you desire when you need them, written in rust you no longer need to locate your previous pr

A template for command-line Rust programs

This is a template for command-line Rust programs. Clone and run the rename script with both a lowercase and UpperCase name. In the dev profile, depen

Rust-Rocket framework template Demo

rocketapp Rust-Rocket framework template Demo dependencies are defined in Cargo.toml Clone as: git clone https://github.com/srikantgdev/rocketapp [op

Rust Cannon Template 🦀 💣 💥

A build system and a minimal Rust program for building MIPS binaries that are executable in the context of [Optimism Cannon]

A template for writing CMSIS-Pack flash algorithms in Rust

Flash Algorithm Template This is a flash algorithm template for writing CMSIS-Pack flash algorithms in Rust. It can be used to generate new flash algo

A template for developing Rust projects, with sensible defaults

Rust Template A template for developing Rust projects, with sensible defaults. Getting Started Click the Use this template button at the top of the pa

LLM-chain Rust Template Repository

Jumpstart your llm-chain projects with the llm-chain-template repository! This template provides a foundation for using the llm-chain library, complete with example code and instructions to get you started effortlessly.

Owner
fan-tastic-z
fan-tastic-z
A template for your next Rust project.

Opinionated Rust Template A template for your next Rust project. To start coding run: cargo generate tomkarw/opinionated-rust-template Only requires j

Tom Karwowski 8 Dec 1, 2022
Template to maintain a rust project running CI/CD with Github Workflows.

Rust CI/CD template Template to maintain a rust project running CI/CD with Github Workflows. CI Workflow ci.yaml This workflow will run every time you

Ame 106 Aug 5, 2024
A template for starting a flipperzero-rs project for the Flipper Zero🐬

flipperzero-template ?? A template for kick-starting a Rust + FlipperZero project using flipperzero-rs ?? ❤️ ?? . Currently supports SDK 14.0 (flipper

Rust for Flipper Zero 5 Apr 4, 2023
A general solution for commonly used crypt in rust, collection of cryptography-related traits and algorithms.

Crypto-rs A general solution for commonly used crypt in rust, collection of cryptography-related traits and algorithms. This is a Rust implementation

houseme 4 Nov 28, 2022
RISC Zero is a zero-knowledge verifiable general computing platform based on zk-STARKs and the RISC-V microarchitecture.

RISC Zero WARNING: This software is still experimental, we do not recommend it for production use (see Security section). RISC Zero is a zero-knowledg

RISC Zero 653 Jan 3, 2023
MevWallet is a smart contract wallet that allows the user to capture MEV from Searchers, or create MEV on purpose.

MevWallet MevWallet is a smart contract wallet that allows the user to capture MEV from Searchers, or create MEV on purpose. This repo contains the so

Blunt Instruments 94 Jan 26, 2023
Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana (WIP) ⛏👷🚧⚠️

Solana BPF Boilerplate Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana This boilerplate provides the following. Si

ono 6 Jan 30, 2022
A blazing fast, type-safe template engine for Rust.

markup.rs A blazing fast, type-safe template engine for Rust. markup.rs is a template engine for Rust powered by procedural macros which parses the te

Utkarsh Kukreti 209 Dec 24, 2022
This is a template to build secret contracts in Rust to run in Secret Network

Secret Contracts Starter Pack This is a template to build secret contracts in Rust to run in Secret Network. To understand the framework better, pleas

Ethan Gallucci 1 Jan 8, 2022
A template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it.

CosmWasm Starter Pack This is a template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it. To understan

null 1 Mar 7, 2022